223
221
wt.move(['hello'], 'a')
224
222
r2 = 'test@rev-2'
225
223
wt.commit('two', rev_id=r2, allow_pointless=False)
228
self.check_inventory_shape(wt.read_working_inventory(),
229
['a/', 'a/hello', 'b/'])
224
self.check_inventory_shape(wt.read_working_inventory(),
225
['a', 'a/hello', 'b'])
233
227
wt.move(['b'], 'a')
234
228
r3 = 'test@rev-3'
235
229
wt.commit('three', rev_id=r3, allow_pointless=False)
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/'])
230
self.check_inventory_shape(wt.read_working_inventory(),
231
['a', 'a/hello', 'a/b'])
232
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
233
['a', 'a/hello', 'a/b'])
245
235
wt.move(['a/hello'], 'a/b')
246
236
r4 = 'test@rev-4'
247
237
wt.commit('four', rev_id=r4, allow_pointless=False)
250
self.check_inventory_shape(wt.read_working_inventory(),
251
['a/', 'a/b/hello', 'a/b/'])
238
self.check_inventory_shape(wt.read_working_inventory(),
239
['a', 'a/b/hello', 'a/b'])
255
241
inv = b.repository.get_revision_inventory(r4)
256
242
eq(inv['hello-id'].revision, r4)
257
243
eq(inv['a-id'].revision, r1)
258
244
eq(inv['b-id'].revision, r3)
260
246
def test_removed_commit(self):
261
247
"""Commit with a removed file"""
262
248
wt = self.make_branch_and_tree('.')
525
509
('change', 'added', 'newdir'),
526
510
('change', 'added', 'newfile'),
527
511
('renamed', 'renamed', 'dirtorename', 'renameddir'),
528
('renamed', 'renamed', 'filetorename', 'renamedfile'),
529
512
('renamed', 'renamed', 'dirtoreparent', 'renameddir/reparenteddir'),
530
513
('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
514
('renamed', 'renamed', 'filetorename', 'renamedfile'),
531
515
('deleted', 'dirtoremove'),
532
516
('deleted', 'filetoremove'),
572
552
timestamp_1ms = round(timestamp, 3)
573
553
self.assertEqual(timestamp_1ms, timestamp)
575
def assertBasisTreeKind(self, kind, tree, file_id):
576
basis = tree.basis_tree()
579
self.assertEqual(kind, basis.kind(file_id))
583
def test_commit_kind_changes(self):
584
if not osutils.has_symlinks():
585
raise tests.TestSkipped('Test requires symlink support')
586
tree = self.make_branch_and_tree('.')
587
os.symlink('target', 'name')
588
tree.add('name', 'a-file-id')
589
tree.commit('Added a symlink')
590
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
593
self.build_tree(['name'])
594
tree.commit('Changed symlink to file')
595
self.assertBasisTreeKind('file', tree, 'a-file-id')
598
os.symlink('target', 'name')
599
tree.commit('file to symlink')
600
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
604
tree.commit('symlink to directory')
605
self.assertBasisTreeKind('directory', tree, 'a-file-id')
608
os.symlink('target', 'name')
609
tree.commit('directory to symlink')
610
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
612
# prepare for directory <-> file tests
615
tree.commit('symlink to directory')
616
self.assertBasisTreeKind('directory', tree, 'a-file-id')
619
self.build_tree(['name'])
620
tree.commit('Changed directory to file')
621
self.assertBasisTreeKind('file', tree, 'a-file-id')
625
tree.commit('file to directory')
626
self.assertBasisTreeKind('directory', tree, 'a-file-id')
628
555
def test_commit_unversioned_specified(self):
629
556
"""Commit should raise if specified files isn't in basis or worktree"""
630
557
tree = self.make_branch_and_tree('.')
631
558
self.assertRaises(errors.PathsNotVersionedError, tree.commit,
632
559
'message', specific_files=['bogus'])
634
class Callback(object):
636
def __init__(self, message, testcase):
638
self.message = message
639
self.testcase = testcase
641
def __call__(self, commit_obj):
643
self.testcase.assertTrue(isinstance(commit_obj, Commit))
646
def test_commit_callback(self):
647
"""Commit should invoke a callback to get the message"""
649
tree = self.make_branch_and_tree('.')
653
self.assertTrue(isinstance(e, BzrError))
654
self.assertEqual('The message or message_callback keyword'
655
' parameter is required for commit().', str(e))
657
self.fail('exception not raised')
658
cb = self.Callback(u'commit 1', self)
659
tree.commit(message_callback=cb)
660
self.assertTrue(cb.called)
661
repository = tree.branch.repository
662
message = repository.get_revision(tree.last_revision()).message
663
self.assertEqual('commit 1', message)
665
def test_no_callback_pointless(self):
666
"""Callback should not be invoked for pointless commit"""
667
tree = self.make_branch_and_tree('.')
668
cb = self.Callback(u'commit 2', self)
669
self.assertRaises(PointlessCommit, tree.commit, message_callback=cb,
670
allow_pointless=False)
671
self.assertFalse(cb.called)
673
def test_no_callback_netfailure(self):
674
"""Callback should not be invoked if connectivity fails"""
675
tree = self.make_branch_and_tree('.')
676
cb = self.Callback(u'commit 2', self)
677
repository = tree.branch.repository
678
# simulate network failure
679
def raise_(self, arg, arg2):
680
raise errors.NoSuchFile('foo')
681
repository.add_inventory = raise_
682
self.assertRaises(errors.NoSuchFile, tree.commit, message_callback=cb)
683
self.assertFalse(cb.called)
685
def test_selected_file_merge_commit(self):
686
"""Ensure the correct error is raised"""
687
tree = self.make_branch_and_tree('foo')
688
# pending merge would turn into a left parent
689
tree.commit('commit 1')
690
tree.add_parent_tree_id('example')
691
self.build_tree(['foo/bar', 'foo/baz'])
692
tree.add(['bar', 'baz'])
693
err = self.assertRaises(errors.CannotCommitSelectedFileMerge,
694
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
695
self.assertEqual(['bar', 'baz'], err.files)
696
self.assertEqual('Selected-file commit of merges is not supported'
697
' yet: files bar, baz', str(err))
699
def test_commit_ordering(self):
700
"""Test of corner-case commit ordering error"""
701
tree = self.make_branch_and_tree('.')
702
self.build_tree(['a/', 'a/z/', 'a/c/', 'a/z/x', 'a/z/y'])
703
tree.add(['a/', 'a/z/', 'a/c/', 'a/z/x', 'a/z/y'])
705
self.build_tree(['a/c/d/'])
707
tree.rename_one('a/z/x', 'a/c/d/x')
708
tree.commit('test', specific_files=['a/z/y'])