~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Aaron Bentley
  • Date: 2006-08-29 18:17:41 UTC
  • mto: This revision was merged to the branch mainline in revision 1977.
  • Revision ID: abentley@panoramicfeedback.com-20060829181741-4360542e119ff839
Implement disk-content merge and conflict resolution for build_tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
 
 
19
from bzrlib import tests
19
20
from bzrlib.bzrdir import BzrDir
20
21
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
21
22
                              UnversionedParent, ParentLoop)
713
714
        self.assertIs(os.path.lexists(this.wt.abspath('b/h1.OTHER')), False)
714
715
        self.assertEqual(this.wt.id2path('i'), pathjoin('b/i1.OTHER'))
715
716
 
716
 
class TestBuildTree(TestCaseInTempDir):
 
717
class TestBuildTree(tests.TestCaseWithTransport):
 
718
 
717
719
    def test_build_tree(self):
718
720
        if not has_symlinks():
719
721
            raise TestSkipped('Test requires symlink support')
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')
732
 
        
 
734
 
 
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')
 
741
        source.commit('added file')
 
742
        build_tree(source.basis_tree(), target)
 
743
        self.assertEqual(1, len(target.conflicts()))
 
744
        target2 = self.make_branch_and_tree('target2')
 
745
        target_file = file('target2/file', 'wb')
 
746
        try:
 
747
            target_file.write('contents of source/file\n')
 
748
        finally:
 
749
            target_file.close()
 
750
        build_tree(source.basis_tree(), target2)
 
751
        self.assertEqual(len(target2.conflicts()), 0)
 
752
 
 
753
    def test_symlink_conflict_handling(self):
 
754
        """Ensure that when building trees, conflict handling is done"""
 
755
        if not has_symlinks():
 
756
            raise TestSkipped('Test requires symlink support')
 
757
        source = self.make_branch_and_tree('source')
 
758
        os.symlink('foo', 'source/symlink')
 
759
        source.add('symlink')
 
760
        source.commit('added file')
 
761
        target = self.make_branch_and_tree('target')
 
762
        os.symlink('bar', 'target/symlink')
 
763
        build_tree(source.basis_tree(), target)
 
764
        self.assertEqual(1, len(target.conflicts()))
 
765
        
 
766
        target = self.make_branch_and_tree('target2')
 
767
        os.symlink('foo', 'target2/symlink')
 
768
        build_tree(source.basis_tree(), target)
 
769
        self.assertEqual(0, len(target.conflicts()))
 
770
        
 
771
    def test_directory_conflict_handling(self):
 
772
        """Ensure that when building trees, conflict handling is done"""
 
773
        source = self.make_branch_and_tree('source')
 
774
        target = self.make_branch_and_tree('target')
 
775
        self.build_tree(['source/dir1/', 'source/dir1/file', 'target/dir1/'])
 
776
        source.add(['dir1', 'dir1/file'])
 
777
        source.commit('added file')
 
778
        build_tree(source.basis_tree(), target)
 
779
        self.assertEqual(0, len(target.conflicts()))
 
780
        self.failUnlessExists('target/dir1/file')
 
781
 
 
782
        # Ensure contents are merged
 
783
        target = self.make_branch_and_tree('target2')
 
784
        self.build_tree(['target2/dir1/', 'target2/dir1/file2'])
 
785
        build_tree(source.basis_tree(), target)
 
786
        self.assertEqual(0, len(target.conflicts()))
 
787
        self.failUnlessExists('target2/dir1/file2')
 
788
        self.failUnlessExists('target2/dir1/file')
 
789
 
 
790
        # Ensure new contents are suppressed for existing branches
 
791
        target = self.make_branch('target3')
 
792
        target = self.make_branch_and_tree('target3/dir1')
 
793
        self.build_tree(['target3/dir1/file2'])
 
794
        build_tree(source.basis_tree(), target)
 
795
        self.assertEqual(0, len(target.conflicts()))
 
796
        self.failIfExists('target3/dir1/file1')
 
797
        self.failUnlessExists('target3/dir1/file2')
 
798
 
 
799
    def test_mixed_conflict_handling(self):
 
800
        """Ensure that when building trees, conflict handling is done"""
 
801
        source = self.make_branch_and_tree('source')
 
802
        target = self.make_branch_and_tree('target')
 
803
        self.build_tree(['source/name', 'target/name/'])
 
804
        source.add('name')
 
805
        source.commit('added file')
 
806
        build_tree(source.basis_tree(), target)
 
807
        self.assertEqual(1, len(target.conflicts()))
 
808
 
 
809
 
733
810
class MockTransform(object):
734
811
 
735
812
    def has_named_child(self, by_parent, parent_id, name):