~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/intertree_implementations/test_compare.py

merge dirstate

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#       (it should not follow the link)
39
39
# TODO: test specific_files when the target tree has a file and the source a
40
40
#       dir with children, same id and same path. 
41
 
# TODO: test specific_files with a new unversioned path.
42
 
#
43
41
# TODO: test comparisons between trees with different root ids. mbp 20070301
44
42
 
45
43
class TestCompare(TestCaseWithTwoTrees):
298
296
            specific_files=['d'],
299
297
            require_versioned=True)
300
298
 
 
299
    def test_default_ignores_unversioned_files(self):
 
300
        tree1 = self.make_branch_and_tree('tree1')
 
301
        tree2 = self.make_to_branch_and_tree('tree2')
 
302
        self.build_tree(['tree1/a', 'tree1/c',
 
303
                         'tree2/a', 'tree2/b', 'tree2/c'])
 
304
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
 
305
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
 
306
 
 
307
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
308
        d = self.intertree_class(tree1, tree2).compare()
 
309
        self.assertEqual([], d.added)
 
310
        self.assertEqual([(u'a', 'a-id', 'file', True, False),
 
311
            (u'c', 'c-id', 'file', True, False)], d.modified)
 
312
        self.assertEqual([], d.removed)
 
313
        self.assertEqual([], d.renamed)
 
314
        self.assertEqual([], d.unchanged)
 
315
        self.assertEqual([], d.unversioned)
 
316
 
 
317
    def test_unversioned_paths_in_tree(self):
 
318
        tree1 = self.make_branch_and_tree('tree1')
 
319
        tree2 = self.make_to_branch_and_tree('tree2')
 
320
        self.build_tree(['tree2/file', 'tree2/dir/'])
 
321
        # try:
 
322
        os.symlink('target', 'tree2/link')
 
323
        links_supported = True
 
324
        # except ???:
 
325
        #   links_supported = False
 
326
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
327
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
 
328
        self.assertEqual([], d.added)
 
329
        self.assertEqual([], d.modified)
 
330
        self.assertEqual([], d.removed)
 
331
        self.assertEqual([], d.renamed)
 
332
        self.assertEqual([], d.unchanged)
 
333
        self.assertEqual([(u'dir', None, 'directory'), (u'file', None, 'file'),
 
334
            (u'link', None, 'symlink')], d.unversioned)
 
335
 
301
336
 
302
337
class TestIterChanges(TestCaseWithTwoTrees):
303
338
    """Test the comparison iterator"""
412
447
                (entry.name, None), (entry.kind, None),
413
448
                (entry.executable, None))
414
449
 
 
450
    def renamed(self, from_tree, to_tree, file_id, content_changed):
 
451
        from_entry = from_tree.inventory[file_id]
 
452
        to_entry = to_tree.inventory[file_id]
 
453
        from_path = from_tree.id2path(file_id)
 
454
        to_path = to_tree.id2path(file_id)
 
455
        return (file_id, to_path, content_changed, (True, True),
 
456
            (from_entry.parent_id, to_entry.parent_id),
 
457
            (from_entry.name, to_entry.name),
 
458
            (from_entry.kind, to_entry.kind),
 
459
            (from_entry.executable, to_entry.executable))
 
460
 
415
461
    def unchanged(self, tree, file_id):
416
462
        entry = tree.inventory[file_id]
417
463
        parent = entry.parent_id
654
700
                           (False, False))], 
655
701
                         list(tree2._iter_changes(tree1)))
656
702
 
657
 
    def _todo_test_unversioned_paths_in_tree(self):
 
703
    def test_default_ignores_unversioned_files(self):
658
704
        tree1 = self.make_branch_and_tree('tree1')
659
705
        tree2 = self.make_to_branch_and_tree('tree2')
660
 
        self.build_tree(['tree2/file', 'tree2/dir/'])
661
 
        # try:
662
 
        os.symlink('target', 'tree2/link')
663
 
        links_supported = True
664
 
        # except ???:
665
 
        #   links_supported = False
 
706
        self.build_tree(['tree1/a', 'tree1/c',
 
707
                         'tree2/a', 'tree2/b', 'tree2/c'])
 
708
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
 
709
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
 
710
 
666
711
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
667
 
        root_id = tree1.path2id('')
668
712
        tree1.lock_read()
669
713
        self.addCleanup(tree1.unlock)
670
714
        tree2.lock_read()
671
715
        self.addCleanup(tree2.unlock)
672
 
        expected = [
673
 
            self.unversioned(tree2, 'file'),
674
 
            self.unversioned(tree2, 'dir'),
675
 
            ]
676
 
        if links_supported:
677
 
            expected.append(self.unversioned(tree2, 'link'))
678
 
        expected = sorted(expected)
 
716
 
 
717
        # We should ignore the fact that 'b' exists in tree-2
 
718
        # because the want_unversioned parameter was not given.
 
719
        expected = sorted([
 
720
            self.content_changed(tree2, 'a-id'),
 
721
            self.content_changed(tree2, 'c-id'),
 
722
            ])
679
723
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
680
724
 
681
 
    def _todo_test_unversioned_paths_in_tree_specific_files(self):
682
 
        tree1 = self.make_branch_and_tree('tree1')
683
 
        tree2 = self.make_to_branch_and_tree('tree2')
684
 
        self.build_tree(['tree2/file', 'tree2/dir/'])
685
 
        # try:
686
 
        os.symlink('target', 'tree2/link')
687
 
        links_supported = True
688
 
        # except ???:
689
 
        #   links_supported = False
 
725
    def test_unversioned_paths_in_tree(self):
 
726
        tree1 = self.make_branch_and_tree('tree1')
 
727
        tree2 = self.make_to_branch_and_tree('tree2')
 
728
        self.build_tree(['tree2/file', 'tree2/dir/'])
 
729
        # try:
 
730
        os.symlink('target', 'tree2/link')
 
731
        links_supported = True
 
732
        # except ???:
 
733
        #   links_supported = False
 
734
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
735
        tree1.lock_read()
 
736
        self.addCleanup(tree1.unlock)
 
737
        tree2.lock_read()
 
738
        self.addCleanup(tree2.unlock)
 
739
        expected = [
 
740
            self.unversioned(tree2, 'file'),
 
741
            self.unversioned(tree2, 'dir'),
 
742
            ]
 
743
        if links_supported:
 
744
            expected.append(self.unversioned(tree2, 'link'))
 
745
        expected = sorted(expected)
 
746
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
747
            want_unversioned=True))
 
748
 
 
749
    def test_unversioned_paths_in_tree_specific_files(self):
 
750
        tree1 = self.make_branch_and_tree('tree1')
 
751
        tree2 = self.make_to_branch_and_tree('tree2')
 
752
        self.build_tree(['tree2/file', 'tree2/dir/'])
 
753
        # try:
 
754
        os.symlink('target', 'tree2/link')
 
755
        links_supported = True
 
756
        # except ???:
 
757
        #   links_supported = False
 
758
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
759
        tree1.lock_read()
 
760
        self.addCleanup(tree1.unlock)
 
761
        tree2.lock_read()
 
762
        self.addCleanup(tree2.unlock)
 
763
        expected = [
 
764
            self.unversioned(tree2, 'file'),
 
765
            self.unversioned(tree2, 'dir'),
 
766
            ]
 
767
        specific_files=['file', 'dir']
 
768
        if links_supported:
 
769
            expected.append(self.unversioned(tree2, 'link'))
 
770
            specific_files.append('link')
 
771
        expected = sorted(expected)
 
772
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
773
            specific_files=specific_files, require_versioned=False,
 
774
            want_unversioned=True))
 
775
 
 
776
    def test_unversioned_paths_in_target_matching_source_old_names(self):
 
777
        # its likely that naive implementations of unversioned file support
 
778
        # will fail if the path was versioned, but is not any more, 
 
779
        # due to a rename, not due to unversioning it.
 
780
        # That is, if the old tree has a versioned file 'foo', and
 
781
        # the new tree has the same file but versioned as 'bar', and also
 
782
        # has an unknown file 'foo', we should get back output for
 
783
        # both foo and bar.
 
784
        tree1 = self.make_branch_and_tree('tree1')
 
785
        tree2 = self.make_to_branch_and_tree('tree2')
 
786
        self.build_tree(['tree2/file', 'tree2/dir/',
 
787
            'tree1/file', 'tree2/movedfile',
 
788
            'tree1/dir/', 'tree2/moveddir/'])
 
789
        # try:
 
790
        os.symlink('target', 'tree1/link')
 
791
        os.symlink('target', 'tree2/link')
 
792
        os.symlink('target', 'tree2/movedlink')
 
793
        links_supported = True
 
794
        # except ???:
 
795
        #   links_supported = False
 
796
        tree1.add(['file', 'dir', 'link'], ['file-id', 'dir-id', 'link-id'])
 
797
        tree2.add(['movedfile', 'moveddir', 'movedlink'],
 
798
            ['file-id', 'dir-id', 'link-id'])
690
799
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
691
800
        root_id = tree1.path2id('')
692
801
        tree1.lock_read()
694
803
        tree2.lock_read()
695
804
        self.addCleanup(tree2.unlock)
696
805
        expected = [
 
806
            self.renamed(tree1, tree2, 'dir-id', False),
 
807
            self.renamed(tree1, tree2, 'file-id', True),
697
808
            self.unversioned(tree2, 'file'),
698
809
            self.unversioned(tree2, 'dir'),
699
810
            ]
700
811
        specific_files=['file', 'dir']
701
812
        if links_supported:
 
813
            expected.append(self.renamed(tree1, tree2, 'link-id', False))
702
814
            expected.append(self.unversioned(tree2, 'link'))
703
815
            specific_files.append('link')
704
816
        expected = sorted(expected)
705
 
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
706
 
            specific_files=specific_files))
 
817
        # run once with, and once without specific files, to catch
 
818
        # potentially different code paths.
 
819
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
820
            require_versioned=False,
 
821
            want_unversioned=True))
 
822
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
823
            specific_files=specific_files, require_versioned=False,
 
824
            want_unversioned=True))
 
825
 
 
826
    def test_unversioned_subtree_only_emits_root(self):
 
827
        tree1 = self.make_branch_and_tree('tree1')
 
828
        tree2 = self.make_to_branch_and_tree('tree2')
 
829
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
 
830
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
831
        expected = [
 
832
            self.unversioned(tree2, 'dir'),
 
833
            ]
 
834
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
835
            want_unversioned=True))
707
836
 
708
837
    def make_trees_with_symlinks(self):
709
838
        tree1 = self.make_branch_and_tree('tree1')
749
878
        #   links_supported = False
750
879
        return self.mutable_trees_to_test_trees(tree1, tree2)
751
880
 
752
 
    def _disabled_test_versioned_symlinks(self):
 
881
    def test_versioned_symlinks(self):
753
882
        tree1, tree2 = self.make_trees_with_symlinks()
754
883
        root_id = tree1.path2id('')
755
884
        tree1.lock_read()
769
898
            self.kind_changed(tree1, tree2, 'tofile'),
770
899
            ]
771
900
        expected = sorted(expected)
772
 
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2, include_unchanged=True))
 
901
        self.assertEqual(expected,
 
902
            self.do_iter_changes(tree1, tree2, include_unchanged=True,
 
903
                want_unversioned=True))
773
904
 
774
 
    def _disabled_test_versioned_symlinks_specific_files(self):
 
905
    def test_versioned_symlinks_specific_files(self):
775
906
        tree1, tree2 = self.make_trees_with_symlinks()
776
907
        root_id = tree1.path2id('')
777
908
        tree1.lock_read()
814
945
                          if f_id.endswith('_f-id'))
815
946
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
816
947
 
817
 
    def test_trees_with_unknown(self):
818
 
        tree1 = self.make_branch_and_tree('tree1')
819
 
        tree2 = self.make_to_branch_and_tree('tree2')
820
 
        tree2.set_root_id(tree1.get_root_id())
821
 
        self.build_tree(['tree1/a', 'tree1/c',
822
 
                         'tree2/a', 'tree2/b', 'tree2/c'])
823
 
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
824
 
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
825
 
 
826
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
827
 
        tree1.lock_read()
828
 
        self.addCleanup(tree1.unlock)
829
 
        tree2.lock_read()
830
 
        self.addCleanup(tree2.unlock)
831
 
 
832
 
        # We should ignore the fact that 'b' exists in tree-2
833
 
        expected = sorted([
834
 
            self.content_changed(tree2, 'a-id'),
835
 
            self.content_changed(tree2, 'c-id'),
836
 
            ])
837
 
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
838
 
 
839
948
    def test_trees_with_missing_dir(self):
840
949
        tree1 = self.make_branch_and_tree('tree1')
841
950
        tree2 = self.make_to_branch_and_tree('tree2')