49
52
from bzrlib.workingtree import WorkingTree
55
class TestTestCaseWithBranch(TestCaseWithBranch):
57
def test_branch_format_matches_bzrdir_branch_format(self):
58
bzrdir_branch_format = self.bzrdir_format.get_branch_format()
59
self.assertIs(self.branch_format.__class__,
60
bzrdir_branch_format.__class__)
62
def test_make_branch_gets_expected_format(self):
63
branch = self.make_branch('.')
64
self.assertIs(self.branch_format.__class__,
65
branch._format.__class__)
52
68
class TestBranch(TestCaseWithBranch):
54
def test_append_revisions(self):
55
"""Test appending more than one revision"""
56
wt = self.make_branch_and_tree('tree')
57
wt.commit('f', rev_id='rev1')
58
wt.commit('f', rev_id='rev2')
59
wt.commit('f', rev_id='rev3')
61
br = self.get_branch()
63
br.append_revision("rev1")
64
self.assertEquals(br.revision_history(), ["rev1",])
65
br.append_revision("rev2", "rev3")
66
self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
67
self.assertRaises(errors.ReservedId, br.append_revision, 'current:')
69
70
def test_create_tree_with_merge(self):
70
71
tree = self.create_tree_with_merge()
71
ancestry_graph = tree.branch.repository.get_revision_graph('rev-3')
72
self.assertEqual({'rev-1':(),
73
self.addCleanup(tree.unlock)
74
graph = tree.branch.repository.get_graph()
75
ancestry_graph = graph.get_parent_map(
76
tree.branch.repository.all_revision_ids())
77
self.assertEqual({'rev-1':('null:',),
73
78
'rev-2':('rev-1', ),
74
79
'rev-1.1.1':('rev-1', ),
75
80
'rev-3':('rev-2', 'rev-1.1.1', ),
292
321
self.assertEqual(repo.get_signature_text('A'),
293
322
d2.open_repository().get_signature_text('A'))
324
def test_missing_revisions(self):
325
t1 = self.make_branch_and_tree('b1')
326
rev1 = t1.commit('one')
327
t2 = t1.bzrdir.sprout('b2').open_workingtree()
328
rev2 = t1.commit('two')
329
rev3 = t1.commit('three')
331
self.assertEqual([rev2, rev3],
332
self.applyDeprecated(deprecated_in((1, 6, 0)),
333
t2.branch.missing_revisions, t1.branch))
336
self.applyDeprecated(deprecated_in((1, 6, 0)),
337
t2.branch.missing_revisions, t1.branch, stop_revision=1))
338
self.assertEqual([rev2],
339
self.applyDeprecated(deprecated_in((1, 6, 0)),
340
t2.branch.missing_revisions, t1.branch, stop_revision=2))
341
self.assertEqual([rev2, rev3],
342
self.applyDeprecated(deprecated_in((1, 6, 0)),
343
t2.branch.missing_revisions, t1.branch, stop_revision=3))
345
self.assertRaises(errors.NoSuchRevision,
346
self.applyDeprecated, deprecated_in((1, 6, 0)),
347
t2.branch.missing_revisions, t1.branch, stop_revision=4)
349
rev4 = t2.commit('four')
350
self.assertRaises(errors.DivergedBranches,
351
self.applyDeprecated, deprecated_in((1, 6, 0)),
352
t2.branch.missing_revisions, t1.branch)
295
354
def test_nicks(self):
296
355
"""Test explicit and implicit branch nicknames.
298
357
Nicknames are implicitly the name of the branch's directory, unless an
299
358
explicit nickname is set. That is, an explicit nickname always
300
359
overrides the implicit one.
652
753
tree3.merge_from_branch(tree2.branch)
653
754
tree3.commit('empty commit 6')
654
755
tree2.pull(tree3.branch)
758
class TestIgnoreFallbacksParameter(TestCaseWithBranch):
760
def make_branch_with_fallback(self):
761
fallback = self.make_branch('fallback')
762
if not fallback._format.supports_stacking():
763
raise tests.TestNotApplicable("format does not support stacking")
764
stacked = self.make_branch('stacked')
765
stacked.set_stacked_on_url(fallback.base)
768
def test_fallbacks_not_opened(self):
769
stacked = self.make_branch_with_fallback()
770
self.get_transport('').rename('fallback', 'moved')
771
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
772
self.assertEqual([], reopened.repository._fallback_repositories)
774
def test_fallbacks_are_opened(self):
775
stacked = self.make_branch_with_fallback()
776
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
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])