339
339
from bzrlib.testament import Testament
340
340
# monkey patch gpg signing mechanism
341
341
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
342
commit.Commit(config=MustSignConfig(branch)).commit(message="base",
343
allow_pointless=True,
342
commit.Commit(config=MustSignConfig(branch)).commit(
343
message_callback=lambda: "base", allow_pointless=True,
344
rev_id='B', working_tree=wt)
346
345
self.assertEqual(Testament.from_revision(branch.repository,
347
346
'B').as_short_text(),
348
347
branch.repository.get_signature_text('B'))
386
385
config = BranchWithHooks(branch)
387
386
commit.Commit(config=config).commit(
387
message_callback=lambda: "base",
389
388
allow_pointless=True,
390
389
rev_id='A', working_tree = wt)
391
390
self.assertEqual(['called', 'called'], calls)
396
395
# using the Commit object directly does not set the branch nick.
397
396
wt = self.make_branch_and_tree('.')
399
c.commit(working_tree=wt, message='empty tree', allow_pointless=True)
398
c.commit(working_tree=wt, message_callback=lambda:'empty tree',
399
allow_pointless=True)
400
400
self.assertEquals(wt.branch.revno(), 1)
401
401
self.assertEqual({},
402
402
wt.branch.repository.get_revision(
557
557
tree = self.make_branch_and_tree('.')
558
558
self.assertRaises(errors.PathsNotVersionedError, tree.commit,
559
559
'message', specific_files=['bogus'])
561
class Callback(object):
563
def __init__(self, message):
565
self.message = message
571
def test_commit_callback(self):
572
"""Commit should invoke a callback to get the message"""
574
tree = self.make_branch_and_tree('.')
578
self.assertTrue(isinstance(e, BzrError))
579
self.assertEqual('The message_callback keyword parameter is'
580
' required for commit().', str(e))
582
self.fail('exception not raised')
583
cb = self.Callback('commit 1')
584
tree.commit(message_callback=cb)
585
self.assertTrue(cb.called)
586
repository = tree.branch.repository
587
message = repository.get_revision(tree.last_revision()).message
588
self.assertEqual('commit 1', message)
590
def test_no_callback_pointless(self):
591
"""Callback should not be invoked for pointless commit"""
592
tree = self.make_branch_and_tree('.')
593
cb = self.Callback('commit 2')
594
self.assertRaises(PointlessCommit, tree.commit, message_callback=cb,
595
allow_pointless=False)
596
self.assertFalse(cb.called)
598
def test_no_callback_netfailure(self):
599
"""Callback should not be invoked if connectivity fails"""
600
# simulate network failure
601
tree = self.make_branch_and_tree('.')
602
def raise_(self, arg, arg2):
603
raise errors.NoSuchFile('foo')
604
cb = self.Callback('commit 2')
605
repository = tree.branch.repository
606
repository.add_inventory = raise_
607
self.assertRaises(errors.NoSuchFile, tree.commit, message_callback=cb)
608
self.assertFalse(cb.called)