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)
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)
780
class TestReferenceLocation(TestCaseWithBranch):
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')
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',
792
self.assertEqual(subtree.branch.base, reference_parent.base)
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')
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])
805
def test_get_reference_info(self):
806
branch = self.make_branch('branch')
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)
814
def test_set_reference_info(self):
815
branch = self.make_branch('branch')
817
branch.set_reference_info('file-id', 'path/to/location',
819
except bzrlib.errors.UnsupportedOperation:
820
raise tests.TestNotApplicable('Branch cannot hold references.')
822
def test_set_get_reference_info(self):
823
branch = self.make_branch('branch')
825
branch.set_reference_info('file-id', 'path/to/file',
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)
834
def test_set_null_reference_info(self):
835
branch = self.make_branch('branch')
837
branch.set_reference_info('file-id', 'path/to/file',
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)
846
def test_set_null_reference_info_when_null(self):
847
branch = self.make_branch('branch')
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)
856
def test_set_null_requires_two_nones(self):
857
branch = self.make_branch('branch')
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'
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'
870
def make_branch_with_reference(self, location, reference_location,
872
branch = self.make_branch(location)
874
branch.set_reference_info(file_id, 'path/to/file',
876
except bzrlib.errors.UnsupportedOperation:
877
raise tests.TestNotApplicable('Branch cannot hold references.')
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)
887
def test_branch_relative_reference_location(self):
888
branch = self.make_branch('branch')
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)
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])
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])
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])
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])
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])
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])
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])
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])
956
def test_merge_updates_references(self):
957
branch = self.make_branch_with_reference('branch', 'reference')
958
tree = self.make_branch_and_tree('tree')
960
branch.pull(tree.branch)
961
checkout = branch.create_checkout('checkout', lightweight=True)
962
checkout.commit('bar')
964
self.addCleanup(tree.unlock)
965
merger = merge.Merger.from_revision_ids(None, tree,
966
branch.last_revision(),
968
merger.merge_type = merge.Merge3Merger
970
self.assertEqual('../branch/reference',
971
tree.branch.get_reference_info('file-id')[1])