/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:04:39 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4405.
  • Revision ID: jelmer@samba.org-20090528160439-4z0xlrk5nejobm7q
Merge bzr.dev.

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,
624
625
        self.assertEqual('foo', branch.get_push_location())
625
626
 
626
627
 
 
628
class TestChildSubmitFormats(TestCaseWithBranch):
 
629
 
 
630
    def test_get_child_submit_format_default(self):
 
631
        self.assertEqual(None, self.get_branch().get_child_submit_format())
 
632
 
 
633
    def test_get_child_submit_format(self):
 
634
        branch = self.get_branch()
 
635
        branch.get_config().set_user_option('child_submit_format', '10')
 
636
        branch = self.get_branch()
 
637
        self.assertEqual('10', branch.get_child_submit_format())
 
638
 
 
639
 
627
640
class TestFormat(TestCaseWithBranch):
628
641
    """Tests for the format itself."""
629
642
 
769
782
        self.get_transport('').rename('fallback', 'moved')
770
783
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
771
784
        self.assertEqual([], reopened.repository._fallback_repositories)
772
 
        
 
785
 
773
786
    def test_fallbacks_are_opened(self):
774
787
        stacked = self.make_branch_with_fallback()
775
788
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
776
789
        self.assertLength(1, reopened.repository._fallback_repositories)
 
790
 
 
791
 
 
792
class TestReferenceLocation(TestCaseWithBranch):
 
793
 
 
794
    def test_reference_parent(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')
 
804
        self.assertEqual(subtree.branch.base, reference_parent.base)
 
805
 
 
806
    def test_reference_parent_accepts_possible_transports(self):
 
807
        tree = self.make_branch_and_tree('tree')
 
808
        subtree = self.make_branch_and_tree('tree/subtree')
 
809
        subtree.set_root_id('subtree-id')
 
810
        try:
 
811
            tree.add_reference(subtree)
 
812
        except bzrlib.errors.UnsupportedOperation:
 
813
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
814
        reference_parent = tree.branch.reference_parent('subtree-id',
 
815
            'subtree', possible_transports=[subtree.bzrdir.root_transport])
 
816
 
 
817
    def test_get_reference_info(self):
 
818
        branch = self.make_branch('branch')
 
819
        try:
 
820
            path, loc = branch.get_reference_info('file-id')
 
821
        except bzrlib.errors.UnsupportedOperation:
 
822
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
823
        self.assertIs(None, path)
 
824
        self.assertIs(None, loc)
 
825
 
 
826
    def test_set_reference_info(self):
 
827
        branch = self.make_branch('branch')
 
828
        try:
 
829
            branch.set_reference_info('file-id', 'path/to/location',
 
830
                                      'path/to/file')
 
831
        except bzrlib.errors.UnsupportedOperation:
 
832
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
833
 
 
834
    def test_set_get_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
        # Create a new instance to ensure storage is permanent
 
842
        branch = Branch.open('branch')
 
843
        tree_path, branch_location = branch.get_reference_info('file-id')
 
844
        self.assertEqual('path/to/location', branch_location)
 
845
 
 
846
    def test_set_null_reference_info(self):
 
847
        branch = self.make_branch('branch')
 
848
        try:
 
849
            branch.set_reference_info('file-id', 'path/to/file',
 
850
                                      'path/to/location')
 
851
        except bzrlib.errors.UnsupportedOperation:
 
852
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
853
        branch.set_reference_info('file-id', None, None)
 
854
        tree_path, branch_location = branch.get_reference_info('file-id')
 
855
        self.assertIs(None, tree_path)
 
856
        self.assertIs(None, branch_location)
 
857
 
 
858
    def test_set_null_reference_info_when_null(self):
 
859
        branch = self.make_branch('branch')
 
860
        try:
 
861
            tree_path, branch_location = branch.get_reference_info('file-id')
 
862
        except bzrlib.errors.UnsupportedOperation:
 
863
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
864
        self.assertIs(None, tree_path)
 
865
        self.assertIs(None, branch_location)
 
866
        branch.set_reference_info('file-id', None, None)
 
867
 
 
868
    def test_set_null_requires_two_nones(self):
 
869
        branch = self.make_branch('branch')
 
870
        try:
 
871
            e = self.assertRaises(ValueError, branch.set_reference_info,
 
872
                                  'file-id', 'path', None)
 
873
        except bzrlib.errors.UnsupportedOperation:
 
874
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
875
        self.assertEqual('tree_path must be None when branch_location is'
 
876
                         ' None.', str(e))
 
877
        e = self.assertRaises(ValueError, branch.set_reference_info,
 
878
                              'file-id', None, 'location')
 
879
        self.assertEqual('branch_location must be None when tree_path is'
 
880
                         ' None.', str(e))
 
881
 
 
882
    def make_branch_with_reference(self, location, reference_location,
 
883
                                   file_id='file-id'):
 
884
        branch = self.make_branch(location)
 
885
        try:
 
886
            branch.set_reference_info(file_id, 'path/to/file',
 
887
                                      reference_location)
 
888
        except bzrlib.errors.UnsupportedOperation:
 
889
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
890
        return branch
 
891
 
 
892
    def test_reference_parent_from_reference_info_(self):
 
893
        referenced_branch = self.make_branch('reference_branch')
 
894
        branch = self.make_branch_with_reference('branch',
 
895
                                                 referenced_branch.base)
 
896
        parent = branch.reference_parent('file-id', 'path/to/file')
 
897
        self.assertEqual(parent.base, referenced_branch.base)
 
898
 
 
899
    def test_branch_relative_reference_location(self):
 
900
        branch = self.make_branch('branch')
 
901
        try:
 
902
            branch.set_reference_info('file-id', 'path/to/file',
 
903
            '../reference_branch')
 
904
        except bzrlib.errors.UnsupportedOperation:
 
905
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
906
        referenced_branch = self.make_branch('reference_branch')
 
907
        parent = branch.reference_parent('file-id', 'path/to/file')
 
908
        self.assertEqual(parent.base, referenced_branch.base)
 
909
 
 
910
    def test_sprout_copies_reference_location(self):
 
911
        branch = self.make_branch_with_reference('branch', '../reference')
 
912
        new_branch = branch.bzrdir.sprout('new-branch').open_branch()
 
913
        self.assertEqual('../reference',
 
914
                         new_branch.get_reference_info('file-id')[1])
 
915
 
 
916
    def test_clone_copies_reference_location(self):
 
917
        branch = self.make_branch_with_reference('branch', '../reference')
 
918
        new_branch = branch.bzrdir.clone('new-branch').open_branch()
 
919
        self.assertEqual('../reference',
 
920
                         new_branch.get_reference_info('file-id')[1])
 
921
 
 
922
    def test_copied_locations_are_rebased(self):
 
923
        branch = self.make_branch_with_reference('branch', 'reference')
 
924
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
925
        self.assertEqual('../reference',
 
926
                         new_branch.get_reference_info('file-id')[1])
 
927
 
 
928
    def test_update_references_retains_old_references(self):
 
929
        branch = self.make_branch_with_reference('branch', 'reference')
 
930
        new_branch = self.make_branch_with_reference(
 
931
            'new_branch', 'reference', 'file-id2')
 
932
        new_branch.update_references(branch)
 
933
        self.assertEqual('reference',
 
934
                         branch.get_reference_info('file-id')[1])
 
935
 
 
936
    def test_update_references_retains_known_references(self):
 
937
        branch = self.make_branch_with_reference('branch', 'reference')
 
938
        new_branch = self.make_branch_with_reference(
 
939
            'new_branch', 'reference2')
 
940
        new_branch.update_references(branch)
 
941
        self.assertEqual('reference',
 
942
                         branch.get_reference_info('file-id')[1])
 
943
 
 
944
    def test_update_references_skips_known_references(self):
 
945
        branch = self.make_branch_with_reference('branch', 'reference')
 
946
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
947
        new_branch.set_reference_info('file-id', '../foo', '../foo')
 
948
        new_branch.update_references(branch)
 
949
        self.assertEqual('reference',
 
950
                         branch.get_reference_info('file-id')[1])
 
951
 
 
952
    def test_pull_updates_references(self):
 
953
        branch = self.make_branch_with_reference('branch', 'reference')
 
954
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
955
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
956
        branch.pull(new_branch)
 
957
        self.assertEqual('foo',
 
958
                         branch.get_reference_info('file-id2')[1])
 
959
 
 
960
    def test_push_updates_references(self):
 
961
        branch = self.make_branch_with_reference('branch', 'reference')
 
962
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
963
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
964
        new_branch.push(branch)
 
965
        self.assertEqual('foo',
 
966
                         branch.get_reference_info('file-id2')[1])
 
967
 
 
968
    def test_merge_updates_references(self):
 
969
        branch = self.make_branch_with_reference('branch', 'reference')
 
970
        tree = self.make_branch_and_tree('tree')
 
971
        tree.commit('foo')
 
972
        branch.pull(tree.branch)
 
973
        checkout = branch.create_checkout('checkout', lightweight=True)
 
974
        checkout.commit('bar')
 
975
        tree.lock_write()
 
976
        self.addCleanup(tree.unlock)
 
977
        merger = merge.Merger.from_revision_ids(None, tree,
 
978
                                                branch.last_revision(),
 
979
                                                other_branch=branch)
 
980
        merger.merge_type = merge.Merge3Merger
 
981
        merger.do_merge()
 
982
        self.assertEqual('../branch/reference',
 
983
                         tree.branch.get_reference_info('file-id')[1])