~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-31 06:06:38 UTC
  • mfrom: (1966.1.2 build-resolver)
  • Revision ID: pqm@pqm.ubuntu.com-20060831060638-bfc0303de36a40a8
Behave reasonably when creating a checkout in a directory with files

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')
 
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', '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')],
 
745
                         target.conflicts())
 
746
        target2 = self.make_branch_and_tree('target2')
 
747
        target_file = file('target2/file', 'wb')
 
748
        try:
 
749
            source_file = file('source/file', 'rb')
 
750
            try:
 
751
                target_file.write(source_file.read())
 
752
            finally:
 
753
                source_file.close()
 
754
        finally:
 
755
            target_file.close()
 
756
        build_tree(source.basis_tree(), target2)
 
757
        self.assertEqual([], target2.conflicts())
 
758
 
 
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')],
 
772
            target.conflicts())
 
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())
732
777
        
 
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')
 
788
 
 
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')
 
796
 
 
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)],
 
807
            target.conflicts())
 
808
 
 
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)],
 
818
            target.conflicts())
 
819
 
 
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())
 
830
 
 
831
    def test_raises_in_populated(self):
 
832
        source = self.make_branch_and_tree('source')
 
833
        self.build_tree(['source/name'])
 
834
        source.add('name')
 
835
        source.commit('added name')
 
836
        target = self.make_branch_and_tree('target')
 
837
        self.build_tree(['target/name'])
 
838
        target.add('name')
 
839
        self.assertRaises(AssertionError, build_tree, source.basis_tree(),
 
840
                          target)
 
841
 
 
842
 
733
843
class MockTransform(object):
734
844
 
735
845
    def has_named_child(self, by_parent, parent_id, name):