def test_set_commit_message_hook(self):
     msgeditor.hooks.install_named_hook(
         "set_commit_message",
         lambda commit_obj, existing_message: "save me some typing\n", None)
     commit_obj = commit.Commit()
     self.assertEqual("save me some typing\n",
                      msgeditor.set_commit_message(commit_obj))
    def test_commit_failed_signature(self):
        import bzrlib.gpg
        import bzrlib.commit as commit
        oldstrategy = bzrlib.gpg.GPGStrategy
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        wt.commit("base", allow_pointless=True, rev_id='A')
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
        try:
            # monkey patch gpg signing mechanism
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
            conf = config.MemoryStack('''
gpg_signing_command=cat -
create_signatures=always
''')
            self.assertRaises(SigningFailed,
                              commit.Commit(config_stack=conf).commit,
                              message="base",
                              allow_pointless=True,
                              rev_id='B',
                              working_tree=wt)
            branch = Branch.open(self.get_url('.'))
            self.assertEqual(branch.last_revision(), 'A')
            self.assertFalse(branch.repository.has_revision('B'))
        finally:
            bzrlib.gpg.GPGStrategy = oldstrategy
    def test_signed_commit(self):
        import bzrlib.gpg
        import bzrlib.commit as commit
        oldstrategy = bzrlib.gpg.GPGStrategy
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        wt.commit("base", allow_pointless=True, rev_id='A')
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
        try:
            from bzrlib.testament import Testament
            # monkey patch gpg signing mechanism
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
            conf = config.MemoryStack('''
gpg_signing_command=cat -
create_signatures=always
''')
            commit.Commit(config_stack=conf).commit(message="base",
                                                    allow_pointless=True,
                                                    rev_id='B',
                                                    working_tree=wt)

            def sign(text):
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)

            self.assertEqual(
                sign(
                    Testament.from_revision(branch.repository,
                                            'B').as_short_text()),
                branch.repository.get_signature_text('B'))
        finally:
            bzrlib.gpg.GPGStrategy = oldstrategy
 def test_generate_commit_message_template_hook(self):
     msgeditor.hooks.install_named_hook(
         "commit_message_template",
         lambda commit_obj, msg: "save me some typing\n", None)
     commit_obj = commit.Commit()
     self.assertEqual(
         "save me some typing\n",
         msgeditor.generate_commit_message_template(commit_obj))
    def test_commit_invokes_hooks(self):
        import bzrlib.commit as commit
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        calls = []

        def called(branch, rev_id):
            calls.append('called')

        bzrlib.ahook = called
        try:
            conf = config.MemoryStack('post_commit=bzrlib.ahook bzrlib.ahook')
            commit.Commit(config_stack=conf).commit(message="base",
                                                    allow_pointless=True,
                                                    rev_id='A',
                                                    working_tree=wt)
            self.assertEqual(['called', 'called'], calls)
        finally:
            del bzrlib.ahook
Beispiel #6
0
 def commit(self, message=None, revprops=None, *args, **kwargs):
     # avoid circular imports
     from bzrlib import commit
     if revprops is None:
         revprops = {}
     if not 'branch-nick' in revprops:
         revprops['branch-nick'] = self.branch.nick
     author = kwargs.pop('author', None)
     if author is not None:
         if 'author' in revprops:
             # XXX: maybe we should just accept one of them?
             raise AssertionError('author property given twice')
         revprops['author'] = author
     # 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,
                                           *args,
                                           **kwargs)
     return committed_id
Beispiel #7
0
 def commit(self, message=None, revprops=None, *args, **kwargs):
     # avoid circular imports
     from bzrlib import commit
     possible_master_transports = []
     revprops = commit.Commit.update_revprops(revprops, self.branch,
                                              kwargs.pop('authors', None),
                                              kwargs.pop('author', 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
Beispiel #8
0
 def test_commit_failed_signature(self):
     import bzrlib.gpg
     import bzrlib.commit as commit
     oldstrategy = bzrlib.gpg.GPGStrategy
     wt = self.make_branch_and_tree('.')
     branch = wt.branch
     wt.commit("base", allow_pointless=True, rev_id='A')
     self.failIf(branch.repository.has_signature_for_revision_id('A'))
     try:
         from bzrlib.testament import Testament
         # monkey patch gpg signing mechanism
         bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
         config = MustSignConfig(branch)
         self.assertRaises(SigningFailed,
                           commit.Commit(config=config).commit,
                           message="base",
                           allow_pointless=True,
                           rev_id='B',
                           working_tree=wt)
         branch = Branch.open(self.get_url('.'))
         self.assertEqual(branch.revision_history(), ['A'])
         self.failIf(branch.repository.has_revision('B'))
     finally:
         bzrlib.gpg.GPGStrategy = oldstrategy
 def test_generate_commit_message_template_no_hooks(self):
     commit_obj = commit.Commit()
     self.assertIs(None,
                   msgeditor.generate_commit_message_template(commit_obj))
 def test_set_commit_message_no_hooks(self):
     commit_obj = commit.Commit()
     self.assertIs(None, msgeditor.set_commit_message(commit_obj))