725
765
tree3.merge_from_branch(tree2.branch)
726
766
tree3.commit('empty commit 6')
727
767
tree2.pull(tree3.branch)
770
class TestIgnoreFallbacksParameter(TestCaseWithBranch):
772
def make_branch_with_fallback(self):
773
fallback = self.make_branch('fallback')
774
if not fallback._format.supports_stacking():
775
raise tests.TestNotApplicable("format does not support stacking")
776
stacked = self.make_branch('stacked')
777
stacked.set_stacked_on_url(fallback.base)
780
def test_fallbacks_not_opened(self):
781
stacked = self.make_branch_with_fallback()
782
self.get_transport('').rename('fallback', 'moved')
783
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
784
self.assertEqual([], reopened.repository._fallback_repositories)
786
def test_fallbacks_are_opened(self):
787
stacked = self.make_branch_with_fallback()
788
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
789
self.assertLength(1, reopened.repository._fallback_repositories)
792
class TestReferenceLocation(TestCaseWithBranch):
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')
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',
804
self.assertEqual(subtree.branch.base, reference_parent.base)
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')
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])
817
def test_get_reference_info(self):
818
branch = self.make_branch('branch')
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)
826
def test_set_reference_info(self):
827
branch = self.make_branch('branch')
829
branch.set_reference_info('file-id', 'path/to/location',
831
except bzrlib.errors.UnsupportedOperation:
832
raise tests.TestNotApplicable('Branch cannot hold references.')
834
def test_set_get_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
# 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)
846
def test_set_null_reference_info(self):
847
branch = self.make_branch('branch')
849
branch.set_reference_info('file-id', 'path/to/file',
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)
858
def test_set_null_reference_info_when_null(self):
859
branch = self.make_branch('branch')
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)
868
def test_set_null_requires_two_nones(self):
869
branch = self.make_branch('branch')
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'
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'
882
def make_branch_with_reference(self, location, reference_location,
884
branch = self.make_branch(location)
886
branch.set_reference_info(file_id, 'path/to/file',
888
except bzrlib.errors.UnsupportedOperation:
889
raise tests.TestNotApplicable('Branch cannot hold references.')
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)
899
def test_branch_relative_reference_location(self):
900
branch = self.make_branch('branch')
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)
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])
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])
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])
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])
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])
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])
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])
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])
968
def test_merge_updates_references(self):
969
branch = self.make_branch_with_reference('branch', 'reference')
970
tree = self.make_branch_and_tree('tree')
972
branch.pull(tree.branch)
973
checkout = branch.create_checkout('checkout', lightweight=True)
974
checkout.commit('bar')
976
self.addCleanup(tree.unlock)
977
merger = merge.Merger.from_revision_ids(None, tree,
978
branch.last_revision(),
980
merger.merge_type = merge.Merge3Merger
982
self.assertEqual('../branch/reference',
983
tree.branch.get_reference_info('file-id')[1])