14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Command that signs unsigned commits by the current user. """
17
"""Command which looks for unsigned commits by the current user, and signs them.
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
23
repository as _mod_repository,
24
26
revision as _mod_revision,
26
from .commands import Command
27
from .option import Option
28
from .i18n import gettext, ngettext
29
from bzrlib.commands import Command
30
from bzrlib.option import Option
31
from bzrlib.i18n import gettext, ngettext
31
33
class cmd_sign_my_commits(Command):
32
34
__doc__ = """Sign all commits by a given committer.
45
help='Don\'t actually sign anything, just print'
46
' the revisions that would be signed.'),
47
help='Don\'t actually sign anything, just print'
48
' the revisions that would be signed.'),
48
50
takes_args = ['location?', 'committer?']
50
52
def run(self, location=None, committer=None, dry_run=False):
55
57
bzrdir = controldir.ControlDir.open(location)
56
58
branch = bzrdir.open_branch()
57
59
repo = branch.repository
58
branch_config = branch.get_config_stack()
60
branch_config = branch.get_config()
60
62
if committer is None:
61
committer = branch_config.get('email')
63
committer = branch_config.username()
62
64
gpg_strategy = gpg.GPGStrategy(branch_config)
65
with repo.lock_write():
66
69
graph = repo.get_graph()
67
with _mod_repository.WriteGroup(repo):
70
repo.start_write_group()
68
72
for rev_id, parents in graph.iter_ancestry(
69
73
[branch.last_revision()]):
70
74
if _mod_revision.is_null(rev_id):
80
84
# We have a revision without a signature who has a
81
85
# matching committer, start signing
82
self.outf.write("%s\n" % rev_id)
85
89
repo.sign_revision(rev_id, gpg_strategy)
87
ngettext('Signed %d revision.\n', 'Signed %d revisions.\n',
91
repo.abort_write_group()
94
repo.commit_write_group()
97
print 'Signed %d revisions' % (count,)
91
100
class cmd_verify_signatures(Command):
98
Option('acceptable-keys',
99
help='Comma separated list of GPG key patterns which are'
100
' acceptable for verification.',
107
Option('acceptable-keys',
108
help='Comma separated list of GPG key patterns which are'
109
' acceptable for verification.',
106
115
takes_args = ['location?']
108
117
def run(self, acceptable_keys=None, revision=None, verbose=None,
110
119
bzrdir = controldir.ControlDir.open_containing(location)[0]
111
120
branch = bzrdir.open_branch()
112
121
repo = branch.repository
113
branch_config = branch.get_config_stack()
122
branch_config = branch.get_config()
114
123
gpg_strategy = gpg.GPGStrategy(branch_config)
116
125
gpg_strategy.set_acceptable_keys(acceptable_keys)
118
127
def write(string):
119
128
self.outf.write(string + "\n")
121
129
def write_verbose(string):
122
130
self.outf.write(" " + string + "\n")
124
self.add_cleanup(repo.lock_read().unlock)
125
# get our list of revisions
132
#get our list of revisions
127
134
if revision is not None:
128
135
if len(revision) == 1:
134
141
if to_revid is None:
135
142
to_revno = branch.revno()
136
143
if from_revno is None or to_revno is None:
137
raise errors.CommandError(
138
gettext('Cannot verify a range of non-revision-history'
144
raise errors.BzrCommandError(gettext(
145
'Cannot verify a range of non-revision-history revisions'))
140
146
for revno in range(from_revno, to_revno + 1):
141
147
revisions.append(branch.get_rev_id(revno))
143
# all revisions by default including merges
149
#all revisions by default including merges
144
150
graph = repo.get_graph()
146
153
for rev_id, parents in graph.iter_ancestry(
147
154
[branch.last_revision()]):
148
155
if _mod_revision.is_null(rev_id):
153
160
revisions.append(rev_id)
154
count, result, all_verifiable = gpg.bulk_verify_signatures(
155
repo, revisions, gpg_strategy)
162
count, result, all_verifiable =\
163
gpg_strategy.do_verifications(revisions, repo)
156
164
if all_verifiable:
157
write(gettext("All commits signed with verifiable keys"))
159
for message in gpg.verbose_valid_message(result):
160
write_verbose(message)
166
"All commits signed with verifiable keys"))
168
write(gpg_strategy.verbose_valid_message(result))
163
write(gpg.valid_commits_message(count))
165
for message in gpg.verbose_valid_message(result):
166
write_verbose(message)
167
write(gpg.expired_commit_message(count))
169
for message in gpg.verbose_expired_key_message(result, repo):
170
write_verbose(message)
171
write(gpg.unknown_key_message(count))
173
for message in gpg.verbose_missing_key_message(result):
174
write_verbose(message)
175
write(gpg.commit_not_valid_message(count))
177
for message in gpg.verbose_not_valid_message(result, repo):
178
write_verbose(message)
179
write(gpg.commit_not_signed_message(count))
181
for message in gpg.verbose_not_signed_message(result, repo):
171
write(gpg_strategy.valid_commits_message(count))
173
for message in gpg_strategy.verbose_valid_message(result):
174
write_verbose(message)
175
write(gpg_strategy.expired_commit_message(count))
177
for message in gpg_strategy.verbose_expired_key_message(result,
179
write_verbose(message)
180
write(gpg_strategy.unknown_key_message(count))
182
for message in gpg_strategy.verbose_missing_key_message(result):
183
write_verbose(message)
184
write(gpg_strategy.commit_not_valid_message(count))
186
for message in gpg_strategy.verbose_not_valid_message(result,
188
write_verbose(message)
189
write(gpg_strategy.commit_not_signed_message(count))
191
for message in gpg_strategy.verbose_not_signed_message(result,
182
193
write_verbose(message)