def test_commit_failed_signature(self): import breezy.gpg import breezy.commit as commit oldstrategy = breezy.gpg.GPGStrategy wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id=b'A') self.assertFalse(branch.repository.has_signature_for_revision_id(b'A')) try: # monkey patch gpg signing mechanism breezy.gpg.GPGStrategy = breezy.gpg.DisabledGPGStrategy conf = config.MemoryStack(b''' create_signatures=always ''') self.assertRaises(breezy.gpg.SigningFailed, commit.Commit(config_stack=conf).commit, message="base", allow_pointless=True, rev_id=b'B', working_tree=wt) branch = Branch.open(self.get_url('.')) self.assertEqual(branch.last_revision(), b'A') self.assertFalse(branch.repository.has_revision(b'B')) finally: breezy.gpg.GPGStrategy = oldstrategy
def test_signed_commit(self): import breezy.gpg import breezy.commit as commit oldstrategy = breezy.gpg.GPGStrategy wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id=b'A') self.assertFalse(branch.repository.has_signature_for_revision_id(b'A')) try: from ..bzr.testament import Testament # monkey patch gpg signing mechanism breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy conf = config.MemoryStack(b''' create_signatures=always ''') commit.Commit(config_stack=conf).commit(message="base", allow_pointless=True, rev_id=b'B', working_tree=wt) def sign(text): return breezy.gpg.LoopbackGPGStrategy(None).sign( text, breezy.gpg.MODE_CLEAR) self.assertEqual( sign( Testament.from_revision(branch.repository, b'B').as_short_text()), branch.repository.get_signature_text(b'B')) finally: breezy.gpg.GPGStrategy = oldstrategy
def test_commit_invokes_hooks(self): import breezy.commit as commit wt = self.make_branch_and_tree('.') branch = wt.branch calls = [] def called(branch, rev_id): calls.append('called') breezy.ahook = called try: conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook') commit.Commit(config_stack=conf).commit( message="base", allow_pointless=True, rev_id=b'A', working_tree=wt) self.assertEqual(['called', 'called'], calls) finally: del breezy.ahook
def commit(self, message=None, revprops=None, *args, **kwargs): # avoid circular imports from breezy import commit possible_master_transports = [] with self.lock_write(): revprops = commit.Commit.update_revprops( revprops, self.branch, kwargs.pop('authors', None), kwargs.get('local', False), possible_master_transports) # args for wt.commit start at message from the Commit.commit method, args = (message, ) + args for hook in MutableTree.hooks['start_commit']: hook(self) committed_id = commit.Commit().commit( working_tree=self, revprops=revprops, possible_master_transports=possible_master_transports, *args, **kwargs) post_hook_params = PostCommitHookParams(self) for hook in MutableTree.hooks['post_commit']: hook(post_hook_params) return committed_id