729
731
self.assertIs(os.path.isdir('b/foo'), True)
730
732
self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
731
733
self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
735
def test_file_conflict_handling(self):
736
"""Ensure that when building trees, conflict handling is done"""
737
source = self.make_branch_and_tree('source')
738
target = self.make_branch_and_tree('target')
739
self.build_tree(['source/file', 'target/file'])
740
source.add('file', 'new-file')
741
source.commit('added file')
742
build_tree(source.basis_tree(), target)
743
self.assertEqual([DuplicateEntry('Moved existing file to',
744
'file.moved', 'file', None, 'new-file')],
746
target2 = self.make_branch_and_tree('target2')
747
target_file = file('target2/file', 'wb')
749
source_file = file('source/file', 'rb')
751
target_file.write(source_file.read())
756
build_tree(source.basis_tree(), target2)
757
self.assertEqual([], target2.conflicts())
759
def test_symlink_conflict_handling(self):
760
"""Ensure that when building trees, conflict handling is done"""
761
if not has_symlinks():
762
raise TestSkipped('Test requires symlink support')
763
source = self.make_branch_and_tree('source')
764
os.symlink('foo', 'source/symlink')
765
source.add('symlink', 'new-symlink')
766
source.commit('added file')
767
target = self.make_branch_and_tree('target')
768
os.symlink('bar', 'target/symlink')
769
build_tree(source.basis_tree(), target)
770
self.assertEqual([DuplicateEntry('Moved existing file to',
771
'symlink.moved', 'symlink', None, 'new-symlink')],
773
target = self.make_branch_and_tree('target2')
774
os.symlink('foo', 'target2/symlink')
775
build_tree(source.basis_tree(), target)
776
self.assertEqual([], target.conflicts())
778
def test_directory_conflict_handling(self):
779
"""Ensure that when building trees, conflict handling is done"""
780
source = self.make_branch_and_tree('source')
781
target = self.make_branch_and_tree('target')
782
self.build_tree(['source/dir1/', 'source/dir1/file', 'target/dir1/'])
783
source.add(['dir1', 'dir1/file'], ['new-dir1', 'new-file'])
784
source.commit('added file')
785
build_tree(source.basis_tree(), target)
786
self.assertEqual([], target.conflicts())
787
self.failUnlessExists('target/dir1/file')
789
# Ensure contents are merged
790
target = self.make_branch_and_tree('target2')
791
self.build_tree(['target2/dir1/', 'target2/dir1/file2'])
792
build_tree(source.basis_tree(), target)
793
self.assertEqual([], target.conflicts())
794
self.failUnlessExists('target2/dir1/file2')
795
self.failUnlessExists('target2/dir1/file')
797
# Ensure new contents are suppressed for existing branches
798
target = self.make_branch_and_tree('target3')
799
self.make_branch('target3/dir1')
800
self.build_tree(['target3/dir1/file2'])
801
build_tree(source.basis_tree(), target)
802
self.failIfExists('target3/dir1/file')
803
self.failUnlessExists('target3/dir1/file2')
804
self.failUnlessExists('target3/dir1.diverted/file')
805
self.assertEqual([DuplicateEntry('Diverted to',
806
'dir1.diverted', 'dir1', 'new-dir1', None)],
809
target = self.make_branch_and_tree('target4')
810
self.build_tree(['target4/dir1/'])
811
self.make_branch('target4/dir1/file')
812
build_tree(source.basis_tree(), target)
813
self.failUnlessExists('target4/dir1/file')
814
self.assertEqual('directory', file_kind('target4/dir1/file'))
815
self.failUnlessExists('target4/dir1/file.diverted')
816
self.assertEqual([DuplicateEntry('Diverted to',
817
'dir1/file.diverted', 'dir1/file', 'new-file', None)],
820
def test_mixed_conflict_handling(self):
821
"""Ensure that when building trees, conflict handling is done"""
822
source = self.make_branch_and_tree('source')
823
target = self.make_branch_and_tree('target')
824
self.build_tree(['source/name', 'target/name/'])
825
source.add('name', 'new-name')
826
source.commit('added file')
827
build_tree(source.basis_tree(), target)
828
self.assertEqual([DuplicateEntry('Moved existing file to',
829
'name.moved', 'name', None, 'new-name')], target.conflicts())
831
def test_raises_in_populated(self):
832
source = self.make_branch_and_tree('source')
833
self.build_tree(['source/name'])
835
source.commit('added name')
836
target = self.make_branch_and_tree('target')
837
self.build_tree(['target/name'])
839
self.assertRaises(AssertionError, build_tree, source.basis_tree(),
733
843
class MockTransform(object):
735
845
def has_named_child(self, by_parent, parent_id, name):