~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    bzrdir,
25
25
    errors,
26
26
    gpg,
 
27
    merge,
27
28
    urlutils,
28
29
    transactions,
29
30
    remote,
769
770
        self.get_transport('').rename('fallback', 'moved')
770
771
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
771
772
        self.assertEqual([], reopened.repository._fallback_repositories)
772
 
        
 
773
 
773
774
    def test_fallbacks_are_opened(self):
774
775
        stacked = self.make_branch_with_fallback()
775
776
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
776
777
        self.assertLength(1, reopened.repository._fallback_repositories)
 
778
 
 
779
 
 
780
class TestReferenceLocation(TestCaseWithBranch):
 
781
 
 
782
    def test_reference_parent(self):
 
783
        tree = self.make_branch_and_tree('tree')
 
784
        subtree = self.make_branch_and_tree('tree/subtree')
 
785
        subtree.set_root_id('subtree-id')
 
786
        try:
 
787
            tree.add_reference(subtree)
 
788
        except bzrlib.errors.UnsupportedOperation:
 
789
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
790
        reference_parent = tree.branch.reference_parent('subtree-id',
 
791
                                                        'subtree')
 
792
        self.assertEqual(subtree.branch.base, reference_parent.base)
 
793
 
 
794
    def test_reference_parent_accepts_possible_transports(self):
 
795
        tree = self.make_branch_and_tree('tree')
 
796
        subtree = self.make_branch_and_tree('tree/subtree')
 
797
        subtree.set_root_id('subtree-id')
 
798
        try:
 
799
            tree.add_reference(subtree)
 
800
        except bzrlib.errors.UnsupportedOperation:
 
801
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
802
        reference_parent = tree.branch.reference_parent('subtree-id',
 
803
            'subtree', possible_transports=[subtree.bzrdir.root_transport])
 
804
 
 
805
    def test_get_reference_info(self):
 
806
        branch = self.make_branch('branch')
 
807
        try:
 
808
            path, loc = branch.get_reference_info('file-id')
 
809
        except bzrlib.errors.UnsupportedOperation:
 
810
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
811
        self.assertIs(None, path)
 
812
        self.assertIs(None, loc)
 
813
 
 
814
    def test_set_reference_info(self):
 
815
        branch = self.make_branch('branch')
 
816
        try:
 
817
            branch.set_reference_info('file-id', 'path/to/location',
 
818
                                      'path/to/file')
 
819
        except bzrlib.errors.UnsupportedOperation:
 
820
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
821
 
 
822
    def test_set_get_reference_info(self):
 
823
        branch = self.make_branch('branch')
 
824
        try:
 
825
            branch.set_reference_info('file-id', 'path/to/file',
 
826
                                      'path/to/location')
 
827
        except bzrlib.errors.UnsupportedOperation:
 
828
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
829
        # Create a new instance to ensure storage is permanent
 
830
        branch = Branch.open('branch')
 
831
        tree_path, branch_location = branch.get_reference_info('file-id')
 
832
        self.assertEqual('path/to/location', branch_location)
 
833
 
 
834
    def test_set_null_reference_info(self):
 
835
        branch = self.make_branch('branch')
 
836
        try:
 
837
            branch.set_reference_info('file-id', 'path/to/file',
 
838
                                      'path/to/location')
 
839
        except bzrlib.errors.UnsupportedOperation:
 
840
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
841
        branch.set_reference_info('file-id', None, None)
 
842
        tree_path, branch_location = branch.get_reference_info('file-id')
 
843
        self.assertIs(None, tree_path)
 
844
        self.assertIs(None, branch_location)
 
845
 
 
846
    def test_set_null_reference_info_when_null(self):
 
847
        branch = self.make_branch('branch')
 
848
        try:
 
849
            tree_path, branch_location = branch.get_reference_info('file-id')
 
850
        except bzrlib.errors.UnsupportedOperation:
 
851
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
852
        self.assertIs(None, tree_path)
 
853
        self.assertIs(None, branch_location)
 
854
        branch.set_reference_info('file-id', None, None)
 
855
 
 
856
    def test_set_null_requires_two_nones(self):
 
857
        branch = self.make_branch('branch')
 
858
        try:
 
859
            e = self.assertRaises(ValueError, branch.set_reference_info,
 
860
                                  'file-id', 'path', None)
 
861
        except bzrlib.errors.UnsupportedOperation:
 
862
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
863
        self.assertEqual('tree_path must be None when branch_location is'
 
864
                         ' None.', str(e))
 
865
        e = self.assertRaises(ValueError, branch.set_reference_info,
 
866
                              'file-id', None, 'location')
 
867
        self.assertEqual('branch_location must be None when tree_path is'
 
868
                         ' None.', str(e))
 
869
 
 
870
    def make_branch_with_reference(self, location, reference_location,
 
871
                                   file_id='file-id'):
 
872
        branch = self.make_branch(location)
 
873
        try:
 
874
            branch.set_reference_info(file_id, 'path/to/file',
 
875
                                      reference_location)
 
876
        except bzrlib.errors.UnsupportedOperation:
 
877
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
878
        return branch
 
879
 
 
880
    def test_reference_parent_from_reference_info_(self):
 
881
        referenced_branch = self.make_branch('reference_branch')
 
882
        branch = self.make_branch_with_reference('branch',
 
883
                                                 referenced_branch.base)
 
884
        parent = branch.reference_parent('file-id', 'path/to/file')
 
885
        self.assertEqual(parent.base, referenced_branch.base)
 
886
 
 
887
    def test_branch_relative_reference_location(self):
 
888
        branch = self.make_branch('branch')
 
889
        try:
 
890
            branch.set_reference_info('file-id', 'path/to/file',
 
891
            '../reference_branch')
 
892
        except bzrlib.errors.UnsupportedOperation:
 
893
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
894
        referenced_branch = self.make_branch('reference_branch')
 
895
        parent = branch.reference_parent('file-id', 'path/to/file')
 
896
        self.assertEqual(parent.base, referenced_branch.base)
 
897
 
 
898
    def test_sprout_copies_reference_location(self):
 
899
        branch = self.make_branch_with_reference('branch', '../reference')
 
900
        new_branch = branch.bzrdir.sprout('new-branch').open_branch()
 
901
        self.assertEqual('../reference',
 
902
                         new_branch.get_reference_info('file-id')[1])
 
903
 
 
904
    def test_clone_copies_reference_location(self):
 
905
        branch = self.make_branch_with_reference('branch', '../reference')
 
906
        new_branch = branch.bzrdir.clone('new-branch').open_branch()
 
907
        self.assertEqual('../reference',
 
908
                         new_branch.get_reference_info('file-id')[1])
 
909
 
 
910
    def test_copied_locations_are_rebased(self):
 
911
        branch = self.make_branch_with_reference('branch', 'reference')
 
912
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
913
        self.assertEqual('../reference',
 
914
                         new_branch.get_reference_info('file-id')[1])
 
915
 
 
916
    def test_update_references_retains_old_references(self):
 
917
        branch = self.make_branch_with_reference('branch', 'reference')
 
918
        new_branch = self.make_branch_with_reference(
 
919
            'new_branch', 'reference', 'file-id2')
 
920
        new_branch.update_references(branch)
 
921
        self.assertEqual('reference',
 
922
                         branch.get_reference_info('file-id')[1])
 
923
 
 
924
    def test_update_references_retains_known_references(self):
 
925
        branch = self.make_branch_with_reference('branch', 'reference')
 
926
        new_branch = self.make_branch_with_reference(
 
927
            'new_branch', 'reference2')
 
928
        new_branch.update_references(branch)
 
929
        self.assertEqual('reference',
 
930
                         branch.get_reference_info('file-id')[1])
 
931
 
 
932
    def test_update_references_skips_known_references(self):
 
933
        branch = self.make_branch_with_reference('branch', 'reference')
 
934
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
935
        new_branch.set_reference_info('file-id', '../foo', '../foo')
 
936
        new_branch.update_references(branch)
 
937
        self.assertEqual('reference',
 
938
                         branch.get_reference_info('file-id')[1])
 
939
 
 
940
    def test_pull_updates_references(self):
 
941
        branch = self.make_branch_with_reference('branch', 'reference')
 
942
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
943
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
944
        branch.pull(new_branch)
 
945
        self.assertEqual('foo',
 
946
                         branch.get_reference_info('file-id2')[1])
 
947
 
 
948
    def test_push_updates_references(self):
 
949
        branch = self.make_branch_with_reference('branch', 'reference')
 
950
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
951
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
952
        new_branch.push(branch)
 
953
        self.assertEqual('foo',
 
954
                         branch.get_reference_info('file-id2')[1])
 
955
 
 
956
    def test_merge_updates_references(self):
 
957
        branch = self.make_branch_with_reference('branch', 'reference')
 
958
        tree = self.make_branch_and_tree('tree')
 
959
        tree.commit('foo')
 
960
        branch.pull(tree.branch)
 
961
        checkout = branch.create_checkout('checkout', lightweight=True)
 
962
        checkout.commit('bar')
 
963
        tree.lock_write()
 
964
        self.addCleanup(tree.unlock)
 
965
        merger = merge.Merger.from_revision_ids(None, tree,
 
966
                                                branch.last_revision(),
 
967
                                                other_branch=branch)
 
968
        merger.merge_type = merge.Merge3Merger
 
969
        merger.do_merge()
 
970
        self.assertEqual('../branch/reference',
 
971
                         tree.branch.get_reference_info('file-id')[1])