56
53
class TestDefaultFormat(TestCase):
58
def test_default_format(self):
59
# update this if you change the default branch format
60
self.assertIsInstance(BranchFormat.get_default_format(),
63
def test_default_format_is_same_as_bzrdir_default(self):
64
# XXX: it might be nice if there was only one place the default was
65
# set, but at the moment that's not true -- mbp 20070814 --
66
# https://bugs.launchpad.net/bzr/+bug/132376
67
self.assertEqual(BranchFormat.get_default_format(),
68
BzrDirFormat.get_default_format().get_branch_format())
70
55
def test_get_set_default_format(self):
71
# set the format and then set it back again
72
56
old_format = BranchFormat.get_default_format()
58
self.assertTrue(isinstance(old_format, BzrBranchFormat5))
73
59
BranchFormat.set_default_format(SampleBranchFormat())
75
61
# the default branch format is used by the meta dir format
107
93
ensure_config_dir_exists)
108
94
ensure_config_dir_exists()
109
95
fn = locations_config_filename()
110
# write correct newlines to locations.conf
111
# by default ConfigObj uses native line-endings for new files
112
# but uses already existing line-endings if file is not empty
115
f.write('# comment\n')
119
96
branch = self.make_branch('.', format='knit')
120
97
branch.set_push_location('foo')
121
98
local_path = urlutils.local_path_from_url(branch.base[:-1])
122
self.assertFileEqual("# comment\n"
99
self.assertFileEqual("[%s]\n"
124
100
"push_location = foo\n"
125
101
"push_location:policy = norecurse" % local_path,
225
def test_append_revision(self):
226
tree = self.make_branch_and_tree('branch1',
227
format='dirstate-tags')
230
tree.commit('foo', rev_id='foo')
231
tree.commit('bar', rev_id='bar')
232
tree.commit('baz', rev_id='baz')
233
tree.set_last_revision('bar')
234
tree.branch.set_last_revision_info(2, 'bar')
235
tree.commit('qux', rev_id='qux')
236
tree.add_parent_tree_id('baz')
237
tree.commit('qux', rev_id='quxx')
238
tree.branch.set_last_revision_info(0, 'null:')
239
self.assertRaises(errors.NotLeftParentDescendant,
240
tree.branch.append_revision, 'bar')
241
tree.branch.append_revision('foo')
242
self.assertRaises(errors.NotLeftParentDescendant,
243
tree.branch.append_revision, 'baz')
244
tree.branch.append_revision('bar')
245
tree.branch.append_revision('baz')
246
self.assertRaises(errors.NotLeftParentDescendant,
247
tree.branch.append_revision, 'quxx')
249
251
def do_checkout_test(self, lightweight=False):
250
252
tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
251
253
subtree = self.make_branch_and_tree('source/subtree',
273
275
self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
275
278
def test_checkout_with_references(self):
276
279
self.do_checkout_test()
278
281
def test_light_checkout_with_references(self):
279
282
self.do_checkout_test(lightweight=True)
281
def test_set_push(self):
282
branch = self.make_branch('source', format='dirstate-tags')
283
branch.get_config().set_user_option('push_location', 'old',
284
store=config.STORE_LOCATION)
287
warnings.append(args[0] % args[1:])
288
_warning = trace.warning
289
trace.warning = warning
291
branch.set_push_location('new')
293
trace.warning = _warning
294
self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
297
284
class TestBranchReference(TestCaseWithTransport):
298
285
"""Tests for the branch reference facility."""
331
318
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
332
319
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
333
320
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
334
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
335
321
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
336
322
self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
340
326
# the installed hooks are saved in self._preserved_hooks.
341
327
self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
329
def test_install_hook_raises_unknown_hook(self):
330
"""install_hook should raise UnknownHook if a hook is unknown."""
331
hooks = BranchHooks()
332
self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
334
def test_install_hook_appends_known_hook(self):
335
"""install_hook should append the callable for known hooks."""
336
hooks = BranchHooks()
337
hooks.install_hook('set_rh', None)
338
self.assertEqual(hooks['set_rh'], [None])
344
341
class TestPullResult(TestCase):