321
318
repo = self.make_repository('.', shared=True)
322
319
except errors.IncompatibleFormat:
324
if repo.bzrdir._format.colocated_branches:
325
raise tests.TestNotApplicable(
326
"control dir does not support colocated branches")
327
self.assertEqual(0, len(repo.bzrdir.list_branches()))
328
if not self.bzrdir_format.colocated_branches:
329
raise tests.TestNotApplicable("control dir format does not support "
330
"colocated branches")
321
self.assertEquals(0, len(repo.bzrdir.list_branches()))
332
323
child_branch1 = self.branch_format.initialize(repo.bzrdir,
334
except errors.UninitializableFormat:
325
except (errors.UninitializableFormat, errors.NoColocatedBranchSupport):
335
326
# branch references are not default init'able and
336
327
# not all bzrdirs support colocated branches.
338
self.assertEqual(1, len(repo.bzrdir.list_branches()))
329
self.assertEquals(1, len(repo.bzrdir.list_branches()))
339
330
self.branch_format.initialize(repo.bzrdir, name='branch2')
340
self.assertEqual(2, len(repo.bzrdir.list_branches()))
331
self.assertEquals(2, len(repo.bzrdir.list_branches()))
342
333
def test_create_append_revisions_only(self):
479
470
checkout = source_branch.create_checkout('c')
480
471
self.assertEqual(rev_id, checkout.last_revision())
473
def test_set_revision_history(self):
474
tree = self.make_branch_and_tree('a')
475
tree.commit('a commit', rev_id='rev1')
477
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
478
br.set_revision_history, ["rev1"])
479
self.assertEquals(br.last_revision(), "rev1")
480
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
481
br.set_revision_history, [])
482
self.assertEquals(br.last_revision(), 'null:')
482
484
def test_heads_to_fetch(self):
483
485
# heads_to_fetch is a method that returns a collection of revids that
484
486
# need to be fetched to copy this branch into another repo. At a
773
775
self.assertEqual(None, branch.get_master_branch())
777
def test_unlocked_does_not_cache_master_branch(self):
778
"""Unlocked branches do not cache the result of get_master_branch."""
779
master = self.make_branch('master')
780
branch1 = self.make_branch('branch')
783
except errors.UpgradeRequired:
784
raise tests.TestNotApplicable('Format does not support binding')
786
branch2 = branch1.bzrdir.open_branch()
787
self.assertNotEqual(None, branch1.get_master_branch())
788
# Unbind the branch via branch2. branch1 isn't locked so will
789
# immediately return the new value for get_master_branch.
791
self.assertEqual(None, branch1.get_master_branch())
775
793
def test_bind_clears_cached_master_branch(self):
776
794
"""b.bind clears any cached value of b.get_master_branch."""
777
795
master1 = self.make_branch('master1')
842
860
def test_fallbacks_not_opened(self):
843
861
stacked = self.make_branch_with_fallback()
844
862
self.get_transport('').rename('fallback', 'moved')
845
reopened_dir = controldir.ControlDir.open(stacked.base)
863
reopened_dir = bzrdir.BzrDir.open(stacked.base)
846
864
reopened = reopened_dir.open_branch(ignore_fallbacks=True)
847
865
self.assertEqual([], reopened.repository._fallback_repositories)
849
867
def test_fallbacks_are_opened(self):
850
868
stacked = self.make_branch_with_fallback()
851
reopened_dir = controldir.ControlDir.open(stacked.base)
869
reopened_dir = bzrdir.BzrDir.open(stacked.base)
852
870
reopened = reopened_dir.open_branch(ignore_fallbacks=False)
853
871
self.assertLength(1, reopened.repository._fallback_repositories)
1061
1079
# above the control dir but we might need to relax that?
1062
1080
self.assertEqual(br.control_url.find(br.user_url), 0)
1063
1081
self.assertEqual(br.control_url, br.control_transport.base)
1066
class FakeShelfCreator(object):
1068
def __init__(self, branch):
1069
self.branch = branch
1071
def write_shelf(self, shelf_file, message=None):
1072
tree = self.branch.repository.revision_tree(revision.NULL_REVISION)
1073
with transform.TransformPreview(tree) as tt:
1074
shelf.ShelfCreator._write_shelf(
1075
shelf_file, tt, revision.NULL_REVISION)
1078
@contextlib.contextmanager
1079
def skip_if_storing_uncommitted_unsupported():
1082
except errors.StoringUncommittedNotSupported:
1083
raise tests.TestNotApplicable('Cannot store uncommitted changes.')
1086
class TestUncommittedChanges(per_branch.TestCaseWithBranch):
1088
def bind(self, branch, master):
1091
except errors.UpgradeRequired:
1092
raise tests.TestNotApplicable('Branch cannot be bound.')
1094
def test_store_uncommitted(self):
1095
tree = self.make_branch_and_tree('b')
1096
branch = tree.branch
1097
creator = FakeShelfCreator(branch)
1098
with skip_if_storing_uncommitted_unsupported():
1099
self.assertIs(None, branch.get_unshelver(tree))
1100
branch.store_uncommitted(creator)
1101
self.assertIsNot(None, branch.get_unshelver(tree))
1103
def test_store_uncommitted_bound(self):
1104
tree = self.make_branch_and_tree('b')
1105
branch = tree.branch
1106
master = self.make_branch('master')
1107
self.bind(branch, master)
1108
creator = FakeShelfCreator(tree.branch)
1109
self.assertIs(None, tree.branch.get_unshelver(tree))
1110
self.assertIs(None, master.get_unshelver(tree))
1111
tree.branch.store_uncommitted(creator)
1112
self.assertIsNot(None, master.get_unshelver(tree))
1114
def test_store_uncommitted_already_stored(self):
1115
branch = self.make_branch('b')
1116
with skip_if_storing_uncommitted_unsupported():
1117
branch.store_uncommitted(FakeShelfCreator(branch))
1118
self.assertRaises(errors.ChangesAlreadyStored,
1119
branch.store_uncommitted, FakeShelfCreator(branch))
1121
def test_store_uncommitted_none(self):
1122
branch = self.make_branch('b')
1123
with skip_if_storing_uncommitted_unsupported():
1124
branch.store_uncommitted(FakeShelfCreator(branch))
1125
branch.store_uncommitted(None)
1126
self.assertIs(None, branch.get_unshelver(None))
1128
def test_get_unshelver(self):
1129
tree = self.make_branch_and_tree('tree')
1131
self.build_tree_contents([('tree/file', 'contents1')])
1133
with skip_if_storing_uncommitted_unsupported():
1134
tree.store_uncommitted()
1135
unshelver = tree.branch.get_unshelver(tree)
1136
self.assertIsNot(None, unshelver)
1138
def test_get_unshelver_bound(self):
1139
tree = self.make_branch_and_tree('tree')
1141
self.build_tree_contents([('tree/file', 'contents1')])
1143
with skip_if_storing_uncommitted_unsupported():
1144
tree.store_uncommitted()
1145
branch = self.make_branch('branch')
1146
self.bind(branch, tree.branch)
1147
unshelver = branch.get_unshelver(tree)
1148
self.assertIsNot(None, unshelver)