479
476
checkout = source_branch.create_checkout('c')
480
477
self.assertEqual(rev_id, checkout.last_revision())
479
def test_set_revision_history(self):
480
tree = self.make_branch_and_tree('a')
481
tree.commit('a commit', rev_id='rev1')
483
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
484
br.set_revision_history, ["rev1"])
485
self.assertEquals(br.last_revision(), "rev1")
486
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
487
br.set_revision_history, [])
488
self.assertEquals(br.last_revision(), 'null:')
482
490
def test_heads_to_fetch(self):
483
491
# heads_to_fetch is a method that returns a collection of revids that
484
492
# need to be fetched to copy this branch into another repo. At a
773
781
self.assertEqual(None, branch.get_master_branch())
783
def test_unlocked_does_not_cache_master_branch(self):
784
"""Unlocked branches do not cache the result of get_master_branch."""
785
master = self.make_branch('master')
786
branch1 = self.make_branch('branch')
789
except errors.UpgradeRequired:
790
raise tests.TestNotApplicable('Format does not support binding')
792
branch2 = branch1.bzrdir.open_branch()
793
self.assertNotEqual(None, branch1.get_master_branch())
794
# Unbind the branch via branch2. branch1 isn't locked so will
795
# immediately return the new value for get_master_branch.
797
self.assertEqual(None, branch1.get_master_branch())
775
799
def test_bind_clears_cached_master_branch(self):
776
800
"""b.bind clears any cached value of b.get_master_branch."""
777
801
master1 = self.make_branch('master1')
842
866
def test_fallbacks_not_opened(self):
843
867
stacked = self.make_branch_with_fallback()
844
868
self.get_transport('').rename('fallback', 'moved')
845
reopened_dir = controldir.ControlDir.open(stacked.base)
869
reopened_dir = bzrdir.BzrDir.open(stacked.base)
846
870
reopened = reopened_dir.open_branch(ignore_fallbacks=True)
847
871
self.assertEqual([], reopened.repository._fallback_repositories)
849
873
def test_fallbacks_are_opened(self):
850
874
stacked = self.make_branch_with_fallback()
851
reopened_dir = controldir.ControlDir.open(stacked.base)
875
reopened_dir = bzrdir.BzrDir.open(stacked.base)
852
876
reopened = reopened_dir.open_branch(ignore_fallbacks=False)
853
877
self.assertLength(1, reopened.repository._fallback_repositories)
1061
1085
# above the control dir but we might need to relax that?
1062
1086
self.assertEqual(br.control_url.find(br.user_url), 0)
1063
1087
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)