53
56
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())
55
70
def test_get_set_default_format(self):
71
# set the format and then set it back again
56
72
old_format = BranchFormat.get_default_format()
58
self.assertTrue(isinstance(old_format, BzrBranchFormat5))
59
73
BranchFormat.set_default_format(SampleBranchFormat())
61
75
# the default branch format is used by the meta dir format
93
107
ensure_config_dir_exists)
94
108
ensure_config_dir_exists()
95
109
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')
96
119
branch = self.make_branch('.', format='knit')
97
120
branch.set_push_location('foo')
98
121
local_path = urlutils.local_path_from_url(branch.base[:-1])
99
self.assertFileEqual("[%s]\n"
122
self.assertFileEqual("# comment\n"
100
124
"push_location = foo\n"
101
125
"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')
251
249
def do_checkout_test(self, lightweight=False):
252
250
tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
253
251
subtree = self.make_branch_and_tree('source/subtree',
275
273
self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
278
275
def test_checkout_with_references(self):
279
276
self.do_checkout_test()
281
278
def test_light_checkout_with_references(self):
282
279
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 '
284
297
class TestBranchReference(TestCaseWithTransport):
285
298
"""Tests for the branch reference facility."""
298
311
opened_branch = branch_dir.open_branch()
299
312
self.assertEqual(opened_branch.base, target_branch.base)
314
def test_get_reference(self):
315
"""For a BranchReference, get_reference should reutrn the location."""
316
branch = self.make_branch('target')
317
checkout = branch.create_checkout('checkout', lightweight=True)
318
reference_url = branch.bzrdir.root_transport.abspath('') + '/'
319
# if the api for create_checkout changes to return different checkout types
320
# then this file read will fail.
321
self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
322
self.assertEqual(reference_url,
323
_mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
302
326
class TestHooks(TestCase):
307
331
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
308
332
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
309
333
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)
310
335
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
311
336
self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
315
340
# the installed hooks are saved in self._preserved_hooks.
316
341
self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
318
def test_install_hook_raises_unknown_hook(self):
319
"""install_hook should raise UnknownHook if a hook is unknown."""
320
hooks = BranchHooks()
321
self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
323
def test_install_hook_appends_known_hook(self):
324
"""install_hook should append the callable for known hooks."""
325
hooks = BranchHooks()
326
hooks.install_hook('set_rh', None)
327
self.assertEqual(hooks['set_rh'], [None])
330
344
class TestPullResult(TestCase):