62
61
def test_default_format(self):
63
62
# update this if you change the default branch format
64
63
self.assertIsInstance(_mod_branch.format_registry.get_default(),
65
_mod_bzrbranch.BzrBranchFormat7)
64
_mod_bzrbranch.BzrBranchFormat7)
67
66
def test_default_format_is_same_as_bzrdir_default(self):
68
67
# XXX: it might be nice if there was only one place the default was
113
112
branch = self.make_branch('.', format='knit')
114
113
branch.set_push_location('foo')
115
114
local_path = urlutils.local_path_from_url(branch.base[:-1])
116
self.assertFileEqual(b"# comment\n"
118
b"push_location = foo\n"
119
b"push_location:policy = norecurse\n" % local_path.encode(
121
bedding.locations_config_path())
115
self.assertFileEqual("# comment\n"
117
"push_location = foo\n"
118
"push_location:policy = norecurse\n" % local_path,
119
config.locations_config_filename())
123
121
# TODO RBC 20051029 test getting a push location from a branch in a
124
122
# recursive section - that is, it appends the branch name.
156
154
SampleSupportedBranchFormatString = b"Sample supported branch format."
158
156
# And the format class can then reference the constant to avoid skew.
161
157
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
162
158
"""A sample supported format."""
203
199
# create a branch with a few known format objects.
204
200
# this is not quite the same as
205
201
self.build_tree(["foo/", "bar/"])
207
202
def check_format(format, url):
208
203
dir = format._matchingcontroldir.initialize(url)
209
204
dir.create_repository()
217
212
SampleBranchFormat.from_string(b"Sample branch format."),
218
213
SampleBranchFormat)
219
214
self.assertRaises(AssertionError,
220
SampleBranchFormat.from_string, b"Different branch format.")
215
SampleBranchFormat.from_string, b"Different branch format.")
222
217
def test_find_format_not_branch(self):
223
218
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
235
230
def test_find_format_with_features(self):
236
231
tree = self.make_branch_and_tree('.', format='2a')
237
232
tree.branch.update_feature_flags({b"name": b"optional"})
238
found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(
233
found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(tree.controldir)
240
234
self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
241
235
self.assertEqual(found_format.features.get(b"name"), b"optional")
242
236
tree.branch.update_feature_flags({b"name": None})
260
254
format = SampleBranchFormat()
261
255
self.registry.register(format)
262
256
self.assertEqual(format,
263
self.registry.get(b"Sample branch format."))
257
self.registry.get(b"Sample branch format."))
264
258
self.registry.remove(format)
265
259
self.assertRaises(KeyError, self.registry.get,
266
b"Sample branch format.")
260
b"Sample branch format.")
268
262
def test_get_all(self):
269
263
format = SampleBranchFormat()
280
274
def test_register_extra_lazy(self):
281
275
self.assertEqual([], self.registry._get_all())
282
276
self.registry.register_extra_lazy("breezy.tests.test_branch",
283
"SampleExtraBranchFormat")
277
"SampleExtraBranchFormat")
284
278
formats = self.registry._get_all()
285
279
self.assertEqual(1, len(formats))
286
280
self.assertIsInstance(formats[0], SampleExtraBranchFormat)
327
321
self.assertPathDoesNotExist('a/.bzr/branch/bound')
328
322
self.assertEqual('ftp://example.com', branch.get_bound_location())
330
def do_checkout_test(self, lightweight):
324
def do_checkout_test(self, lightweight=False):
331
325
tree = self.make_branch_and_tree('source',
332
format=self.get_format_name_subtree())
326
format=self.get_format_name_subtree())
333
327
subtree = self.make_branch_and_tree('source/subtree',
334
format=self.get_format_name_subtree())
328
format=self.get_format_name_subtree())
335
329
subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
336
format=self.get_format_name_subtree())
330
format=self.get_format_name_subtree())
337
331
self.build_tree(['source/subtree/file',
338
332
'source/subtree/subsubtree/file'])
339
333
subsubtree.add('file')
340
334
subtree.add('file')
341
335
subtree.add_reference(subsubtree)
342
subtree.set_reference_info('subsubtree', subsubtree.branch.user_url)
343
336
tree.add_reference(subtree)
344
tree.set_reference_info('subtree', subtree.branch.user_url)
345
337
tree.commit('a revision')
346
338
subtree.commit('a subtree file')
347
339
subsubtree.commit('a subsubtree file')
357
349
self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
359
351
def test_checkout_with_references(self):
360
self.do_checkout_test(lightweight=False)
352
self.do_checkout_test()
362
354
def test_light_checkout_with_references(self):
363
355
self.do_checkout_test(lightweight=True)
377
369
def test_set_stacked_on_url_errors(self):
378
370
branch = self.make_branch('a', format=self.get_format_name())
379
371
self.assertRaises(_mod_branch.UnstackableBranchFormat,
380
branch.set_stacked_on_url, None)
372
branch.set_stacked_on_url, None)
382
374
def test_default_stacked_location(self):
383
375
branch = self.make_branch('a', format=self.get_format_name())
384
self.assertRaises(_mod_branch.UnstackableBranchFormat,
385
branch.get_stacked_on_url)
376
self.assertRaises(_mod_branch.UnstackableBranchFormat, branch.get_stacked_on_url)
388
379
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
402
393
branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
403
394
target = self.make_branch('b')
404
395
self.assertRaises(errors.UnstackableRepositoryFormat,
405
branch.set_stacked_on_url, target.base)
396
branch.set_stacked_on_url, target.base)
407
398
def test_clone_stacked_on_unstackable_repo(self):
408
399
repo = self.make_repository('a', format='dirstate-tags')
447
438
def create_branch_with_reference(self):
448
439
branch = self.make_branch('branch')
449
branch._set_all_reference_info({'path': ('location', b'file-id')})
440
branch._set_all_reference_info({'path': ('location', 'file-id')})
453
444
def instrument_branch(branch, gets):
454
445
old_get = branch._transport.get
456
446
def get(*args, **kwargs):
457
447
gets.append((args, kwargs))
458
448
return old_get(*args, **kwargs)
482
472
branch.lock_write()
483
473
self.instrument_branch(branch, gets)
484
474
self.addCleanup(branch.unlock)
485
branch._set_all_reference_info({'path2': ('location2', b'file-id')})
475
branch._set_all_reference_info({'path2': ('location2', 'file-id')})
486
476
location, file_id = branch.get_reference_info('path2')
487
477
self.assertEqual(0, len(gets))
488
self.assertEqual(b'file-id', file_id)
478
self.assertEqual('file-id', file_id)
489
479
self.assertEqual('location2', location)
491
481
def test_reference_info_caches_cleared(self):
492
482
branch = self.make_branch('branch')
493
483
with branch.lock_write():
494
branch.set_reference_info(b'file-id', 'location2', 'path2')
484
branch.set_reference_info('path2', 'location2', b'file-id')
495
485
doppelganger = _mod_branch.Branch.open('branch')
496
doppelganger.set_reference_info(b'file-id', 'location3', 'path3')
497
self.assertEqual(('location3', 'path3'),
498
branch.get_reference_info(b'file-id'))
486
doppelganger.set_reference_info('path3', 'location3', b'file-id')
487
self.assertEqual(('location3', b'file-id'),
488
branch.get_reference_info('path3'))
500
490
def _recordParentMapCalls(self, repo):
501
491
self._parent_map_calls = []
502
492
orig_get_parent_map = repo.revisions.get_parent_map
504
493
def get_parent_map(q):
506
495
self._parent_map_calls.extend([e[0] for e in q])
533
522
reference_url = branch.controldir.root_transport.abspath('') + '/'
534
523
# if the api for create_checkout changes to return different checkout types
535
524
# then this file read will fail.
536
self.assertFileEqual(reference_url.encode('utf-8'),
537
'checkout/.bzr/branch/location')
525
self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
538
526
self.assertEqual(reference_url,
539
_mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
527
_mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
542
530
class TestHooks(tests.TestCaseWithTransport):
545
533
"""Check that creating a BranchHooks instance has the right defaults."""
546
534
hooks = _mod_branch.BranchHooks()
547
535
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
548
self.assertTrue("post_commit" in hooks,
549
"post_commit not in %s" % hooks)
536
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
550
537
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
551
538
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
552
539
self.assertTrue("post_uncommit" in hooks,
567
554
def test_post_branch_init_hook(self):
569
556
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
571
558
self.assertLength(0, calls)
572
559
branch = self.make_branch('a')
573
560
self.assertLength(1, calls)
579
566
def test_post_branch_init_hook_repr(self):
581
568
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
582
lambda params: param_reprs.append(repr(params)), None)
569
lambda params: param_reprs.append(repr(params)), None)
583
570
branch = self.make_branch('a')
584
571
self.assertLength(1, param_reprs)
585
572
param_repr = param_reprs[0]
626
613
def test_valid_append_revisions_only(self):
627
614
self.assertEqual(None,
628
self.config_stack.get('append_revisions_only'))
615
self.config_stack.get('append_revisions_only'))
629
616
self.check_append_revisions_only(None)
630
617
self.check_append_revisions_only(False, 'False')
631
618
self.check_append_revisions_only(True, 'True')
637
624
def test_invalid_append_revisions_only(self):
638
625
"""Ensure warning is noted on invalid settings"""
639
626
self.warnings = []
641
627
def warning(*args):
642
628
self.warnings.append(args[0] % args[1:])
643
629
self.overrideAttr(trace, 'warning', warning)
698
684
def test_report_changed(self):
699
685
r = _mod_branch.PullResult()
700
r.old_revid = b"old-revid"
686
r.old_revid = "old-revid"
702
r.new_revid = b"new-revid"
688
r.new_revid = "new-revid"
706
692
self.assertEqual("Now on revision 20.\n", f.getvalue())
693
self.assertEqual("Now on revision 20.\n", f.getvalue())
708
695
def test_report_unchanged(self):
709
696
r = _mod_branch.PullResult()
710
r.old_revid = b"same-revid"
711
r.new_revid = b"same-revid"
697
r.old_revid = "same-revid"
698
r.new_revid = "same-revid"
714
701
self.assertEqual("No revisions or tags to pull.\n", f.getvalue())