217
223
wt.move(['hello'], 'a')
218
224
r2 = 'test@rev-2'
219
225
wt.commit('two', rev_id=r2, allow_pointless=False)
220
self.check_inventory_shape(wt.read_working_inventory(),
221
['a', 'a/hello', 'b'])
228
self.check_inventory_shape(wt.read_working_inventory(),
229
['a', 'a/hello', 'b'])
223
233
wt.move(['b'], 'a')
224
234
r3 = 'test@rev-3'
225
235
wt.commit('three', rev_id=r3, allow_pointless=False)
226
self.check_inventory_shape(wt.read_working_inventory(),
227
['a', 'a/hello', 'a/b'])
228
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
229
['a', 'a/hello', 'a/b'])
238
self.check_inventory_shape(wt.read_working_inventory(),
239
['a', 'a/hello', 'a/b'])
240
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
241
['a', 'a/hello', 'a/b'])
231
245
wt.move(['a/hello'], 'a/b')
232
246
r4 = 'test@rev-4'
233
247
wt.commit('four', rev_id=r4, allow_pointless=False)
234
self.check_inventory_shape(wt.read_working_inventory(),
235
['a', 'a/b/hello', 'a/b'])
250
self.check_inventory_shape(wt.read_working_inventory(),
251
['a', 'a/b/hello', 'a/b'])
237
255
inv = b.repository.get_revision_inventory(r4)
238
256
eq(inv['hello-id'].revision, r4)
239
257
eq(inv['a-id'].revision, r1)
240
258
eq(inv['b-id'].revision, r3)
242
260
def test_removed_commit(self):
243
261
"""Commit with a removed file"""
244
262
wt = self.make_branch_and_tree('.')
507
530
('deleted', 'filetoremove'),
534
def test_commit_removals_respects_filespec(self):
535
"""Commit respects the specified_files for removals."""
536
tree = self.make_branch_and_tree('.')
537
self.build_tree(['a', 'b'])
539
tree.commit('added a, b')
540
tree.remove(['a', 'b'])
541
tree.commit('removed a', specific_files='a')
542
basis = tree.basis_tree()
545
self.assertIs(None, basis.path2id('a'))
546
self.assertFalse(basis.path2id('b') is None)
550
def test_commit_saves_1ms_timestamp(self):
551
"""Passing in a timestamp is saved with 1ms resolution"""
552
tree = self.make_branch_and_tree('.')
553
self.build_tree(['a'])
555
tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
558
rev = tree.branch.repository.get_revision('a1')
559
self.assertEqual(1153248633.419, rev.timestamp)
561
def test_commit_has_1ms_resolution(self):
562
"""Allowing commit to generate the timestamp also has 1ms resolution"""
563
tree = self.make_branch_and_tree('.')
564
self.build_tree(['a'])
566
tree.commit('added a', rev_id='a1')
568
rev = tree.branch.repository.get_revision('a1')
569
timestamp = rev.timestamp
570
timestamp_1ms = round(timestamp, 3)
571
self.assertEqual(timestamp_1ms, timestamp)
573
def assertBasisTreeKind(self, kind, tree, file_id):
574
basis = tree.basis_tree()
577
self.assertEqual(kind, basis.kind(file_id))
581
def test_commit_kind_changes(self):
582
if not osutils.has_symlinks():
583
raise tests.TestSkipped('Test requires symlink support')
584
tree = self.make_branch_and_tree('.')
585
os.symlink('target', 'name')
586
tree.add('name', 'a-file-id')
587
tree.commit('Added a symlink')
588
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
591
self.build_tree(['name'])
592
tree.commit('Changed symlink to file')
593
self.assertBasisTreeKind('file', tree, 'a-file-id')
596
os.symlink('target', 'name')
597
tree.commit('file to symlink')
598
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
602
tree.commit('symlink to directory')
603
self.assertBasisTreeKind('directory', tree, 'a-file-id')
606
os.symlink('target', 'name')
607
tree.commit('directory to symlink')
608
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
610
# prepare for directory <-> file tests
613
tree.commit('symlink to directory')
614
self.assertBasisTreeKind('directory', tree, 'a-file-id')
617
self.build_tree(['name'])
618
tree.commit('Changed directory to file')
619
self.assertBasisTreeKind('file', tree, 'a-file-id')
623
tree.commit('file to directory')
624
self.assertBasisTreeKind('directory', tree, 'a-file-id')
626
def test_commit_unversioned_specified(self):
627
"""Commit should raise if specified files isn't in basis or worktree"""
628
tree = self.make_branch_and_tree('.')
629
self.assertRaises(errors.PathsNotVersionedError, tree.commit,
630
'message', specific_files=['bogus'])
632
class Callback(object):
634
def __init__(self, message, testcase):
636
self.message = message
637
self.testcase = testcase
639
def __call__(self, commit_obj):
641
self.testcase.assertTrue(isinstance(commit_obj, Commit))
644
def test_commit_callback(self):
645
"""Commit should invoke a callback to get the message"""
647
tree = self.make_branch_and_tree('.')
651
self.assertTrue(isinstance(e, BzrError))
652
self.assertEqual('The message or message_callback keyword'
653
' parameter is required for commit().', str(e))
655
self.fail('exception not raised')
656
cb = self.Callback(u'commit 1', self)
657
tree.commit(message_callback=cb)
658
self.assertTrue(cb.called)
659
repository = tree.branch.repository
660
message = repository.get_revision(tree.last_revision()).message
661
self.assertEqual('commit 1', message)
663
def test_no_callback_pointless(self):
664
"""Callback should not be invoked for pointless commit"""
665
tree = self.make_branch_and_tree('.')
666
cb = self.Callback(u'commit 2', self)
667
self.assertRaises(PointlessCommit, tree.commit, message_callback=cb,
668
allow_pointless=False)
669
self.assertFalse(cb.called)
671
def test_no_callback_netfailure(self):
672
"""Callback should not be invoked if connectivity fails"""
673
tree = self.make_branch_and_tree('.')
674
cb = self.Callback(u'commit 2', self)
675
repository = tree.branch.repository
676
# simulate network failure
677
def raise_(self, arg, arg2):
678
raise errors.NoSuchFile('foo')
679
repository.add_inventory = raise_
680
self.assertRaises(errors.NoSuchFile, tree.commit, message_callback=cb)
681
self.assertFalse(cb.called)