61
61
def test_default_format(self):
62
62
# update this if you change the default branch format
63
63
self.assertIsInstance(_mod_branch.format_registry.get_default(),
64
_mod_bzrbranch.BzrBranchFormat7)
64
_mod_bzrbranch.BzrBranchFormat7)
66
66
def test_default_format_is_same_as_bzrdir_default(self):
67
67
# XXX: it might be nice if there was only one place the default was
112
112
branch = self.make_branch('.', format='knit')
113
113
branch.set_push_location('foo')
114
114
local_path = urlutils.local_path_from_url(branch.base[:-1])
115
self.assertFileEqual(b"# comment\n"
117
b"push_location = foo\n"
118
b"push_location:policy = norecurse\n" % local_path.encode(
120
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())
122
121
# TODO RBC 20051029 test getting a push location from a branch in a
123
122
# recursive section - that is, it appends the branch name.
134
133
def get_format_string(cls):
135
134
"""See BzrBranchFormat.get_format_string()."""
136
return b"Sample branch format."
135
return "Sample branch format."
138
137
def initialize(self, a_controldir, name=None, repository=None,
139
138
append_revisions_only=None):
153
152
# Demonstrating how lazy loading is often implemented:
154
153
# A constant string is created.
155
SampleSupportedBranchFormatString = b"Sample supported branch format."
154
SampleSupportedBranchFormatString = "Sample supported branch format."
157
156
# And the format class can then reference the constant to avoid skew.
160
157
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
161
158
"""A sample supported format."""
202
199
# create a branch with a few known format objects.
203
200
# this is not quite the same as
204
201
self.build_tree(["foo/", "bar/"])
206
202
def check_format(format, url):
207
203
dir = format._matchingcontroldir.initialize(url)
208
204
dir.create_repository()
214
210
def test_from_string(self):
215
211
self.assertIsInstance(
216
SampleBranchFormat.from_string(b"Sample branch format."),
212
SampleBranchFormat.from_string("Sample branch format."),
217
213
SampleBranchFormat)
218
214
self.assertRaises(AssertionError,
219
SampleBranchFormat.from_string, b"Different branch format.")
215
SampleBranchFormat.from_string, "Different branch format.")
221
217
def test_find_format_not_branch(self):
222
218
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
234
230
def test_find_format_with_features(self):
235
231
tree = self.make_branch_and_tree('.', format='2a')
236
tree.branch.update_feature_flags({b"name": b"optional"})
237
found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(
232
tree.branch.update_feature_flags({"name": "optional"})
233
found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(tree.controldir)
239
234
self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
240
self.assertEqual(found_format.features.get(b"name"), b"optional")
241
tree.branch.update_feature_flags({b"name": None})
235
self.assertEqual(found_format.features.get("name"), "optional")
236
tree.branch.update_feature_flags({"name": None})
242
237
branch = _mod_branch.Branch.open('.')
243
238
self.assertEqual(branch._format.features, {})
259
254
format = SampleBranchFormat()
260
255
self.registry.register(format)
261
256
self.assertEqual(format,
262
self.registry.get(b"Sample branch format."))
257
self.registry.get("Sample branch format."))
263
258
self.registry.remove(format)
264
259
self.assertRaises(KeyError, self.registry.get,
265
b"Sample branch format.")
260
"Sample branch format.")
267
262
def test_get_all(self):
268
263
format = SampleBranchFormat()
279
274
def test_register_extra_lazy(self):
280
275
self.assertEqual([], self.registry._get_all())
281
276
self.registry.register_extra_lazy("breezy.tests.test_branch",
282
"SampleExtraBranchFormat")
277
"SampleExtraBranchFormat")
283
278
formats = self.registry._get_all()
284
279
self.assertEqual(1, len(formats))
285
280
self.assertIsInstance(formats[0], SampleExtraBranchFormat)
326
321
self.assertPathDoesNotExist('a/.bzr/branch/bound')
327
322
self.assertEqual('ftp://example.com', branch.get_bound_location())
329
def do_checkout_test(self, lightweight):
324
def do_checkout_test(self, lightweight=False):
330
325
tree = self.make_branch_and_tree('source',
331
format=self.get_format_name_subtree())
326
format=self.get_format_name_subtree())
332
327
subtree = self.make_branch_and_tree('source/subtree',
333
format=self.get_format_name_subtree())
328
format=self.get_format_name_subtree())
334
329
subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
335
format=self.get_format_name_subtree())
330
format=self.get_format_name_subtree())
336
331
self.build_tree(['source/subtree/file',
337
332
'source/subtree/subsubtree/file'])
338
333
subsubtree.add('file')
339
334
subtree.add('file')
340
335
subtree.add_reference(subsubtree)
341
subtree.set_reference_info('subsubtree', subsubtree.branch.user_url)
342
336
tree.add_reference(subtree)
343
tree.set_reference_info('subtree', subtree.branch.user_url)
344
337
tree.commit('a revision')
345
338
subtree.commit('a subtree file')
346
339
subsubtree.commit('a subsubtree file')
356
349
self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
358
351
def test_checkout_with_references(self):
359
self.do_checkout_test(lightweight=False)
352
self.do_checkout_test()
361
354
def test_light_checkout_with_references(self):
362
355
self.do_checkout_test(lightweight=True)
376
369
def test_set_stacked_on_url_errors(self):
377
370
branch = self.make_branch('a', format=self.get_format_name())
378
371
self.assertRaises(_mod_branch.UnstackableBranchFormat,
379
branch.set_stacked_on_url, None)
372
branch.set_stacked_on_url, None)
381
374
def test_default_stacked_location(self):
382
375
branch = self.make_branch('a', format=self.get_format_name())
383
self.assertRaises(_mod_branch.UnstackableBranchFormat,
384
branch.get_stacked_on_url)
376
self.assertRaises(_mod_branch.UnstackableBranchFormat, branch.get_stacked_on_url)
387
379
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
401
393
branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
402
394
target = self.make_branch('b')
403
395
self.assertRaises(errors.UnstackableRepositoryFormat,
404
branch.set_stacked_on_url, target.base)
396
branch.set_stacked_on_url, target.base)
406
398
def test_clone_stacked_on_unstackable_repo(self):
407
399
repo = self.make_repository('a', format='dirstate-tags')
446
438
def create_branch_with_reference(self):
447
439
branch = self.make_branch('branch')
448
branch._set_all_reference_info({'path': ('location', b'file-id')})
440
branch._set_all_reference_info({'file-id': ('path', 'location')})
452
444
def instrument_branch(branch, gets):
453
445
old_get = branch._transport.get
455
446
def get(*args, **kwargs):
456
447
gets.append((args, kwargs))
457
448
return old_get(*args, **kwargs)
463
454
branch.lock_read()
464
455
self.addCleanup(branch.unlock)
465
456
self.instrument_branch(branch, gets)
466
branch.get_reference_info('path')
467
branch.get_reference_info('path')
457
branch.get_reference_info('file-id')
458
branch.get_reference_info('file-id')
468
459
self.assertEqual(1, len(gets))
470
461
def test_reference_info_caching_read_unlocked(self):
472
463
branch = self.create_branch_with_reference()
473
464
self.instrument_branch(branch, gets)
474
branch.get_reference_info('path')
475
branch.get_reference_info('path')
465
branch.get_reference_info('file-id')
466
branch.get_reference_info('file-id')
476
467
self.assertEqual(2, len(gets))
478
469
def test_reference_info_caching_write_locked(self):
481
472
branch.lock_write()
482
473
self.instrument_branch(branch, gets)
483
474
self.addCleanup(branch.unlock)
484
branch._set_all_reference_info({'path2': ('location2', b'file-id')})
485
location, file_id = branch.get_reference_info('path2')
475
branch._set_all_reference_info({'file-id': ('path2', 'location2')})
476
path, location = branch.get_reference_info('file-id')
486
477
self.assertEqual(0, len(gets))
487
self.assertEqual(b'file-id', file_id)
478
self.assertEqual('path2', path)
488
479
self.assertEqual('location2', location)
490
481
def test_reference_info_caches_cleared(self):
491
482
branch = self.make_branch('branch')
492
with branch.lock_write():
493
branch.set_reference_info(b'file-id', 'location2', 'path2')
484
branch.set_reference_info('file-id', 'path2', 'location2')
494
486
doppelganger = _mod_branch.Branch.open('branch')
495
doppelganger.set_reference_info(b'file-id', 'location3', 'path3')
496
self.assertEqual(('location3', 'path3'),
497
branch.get_reference_info(b'file-id'))
487
doppelganger.set_reference_info('file-id', 'path3', 'location3')
488
self.assertEqual(('path3', 'location3'),
489
branch.get_reference_info('file-id'))
499
491
def _recordParentMapCalls(self, repo):
500
492
self._parent_map_calls = []
501
493
orig_get_parent_map = repo.revisions.get_parent_map
503
494
def get_parent_map(q):
505
496
self._parent_map_calls.extend([e[0] for e in q])
532
523
reference_url = branch.controldir.root_transport.abspath('') + '/'
533
524
# if the api for create_checkout changes to return different checkout types
534
525
# then this file read will fail.
535
self.assertFileEqual(reference_url.encode('utf-8'),
536
'checkout/.bzr/branch/location')
526
self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
537
527
self.assertEqual(reference_url,
538
_mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
528
_mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
541
531
class TestHooks(tests.TestCaseWithTransport):
544
534
"""Check that creating a BranchHooks instance has the right defaults."""
545
535
hooks = _mod_branch.BranchHooks()
546
536
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
547
self.assertTrue("post_commit" in hooks,
548
"post_commit not in %s" % hooks)
537
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
549
538
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
550
539
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
551
540
self.assertTrue("post_uncommit" in hooks,
566
555
def test_post_branch_init_hook(self):
568
557
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
570
559
self.assertLength(0, calls)
571
560
branch = self.make_branch('a')
572
561
self.assertLength(1, calls)
578
567
def test_post_branch_init_hook_repr(self):
580
569
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
581
lambda params: param_reprs.append(repr(params)), None)
570
lambda params: param_reprs.append(repr(params)), None)
582
571
branch = self.make_branch('a')
583
572
self.assertLength(1, param_reprs)
584
573
param_repr = param_reprs[0]
625
614
def test_valid_append_revisions_only(self):
626
615
self.assertEqual(None,
627
self.config_stack.get('append_revisions_only'))
616
self.config_stack.get('append_revisions_only'))
628
617
self.check_append_revisions_only(None)
629
618
self.check_append_revisions_only(False, 'False')
630
619
self.check_append_revisions_only(True, 'True')
636
625
def test_invalid_append_revisions_only(self):
637
626
"""Ensure warning is noted on invalid settings"""
638
627
self.warnings = []
640
628
def warning(*args):
641
629
self.warnings.append(args[0] % args[1:])
642
630
self.overrideAttr(trace, 'warning', warning)
697
685
def test_report_changed(self):
698
686
r = _mod_branch.PullResult()
699
r.old_revid = b"old-revid"
687
r.old_revid = "old-revid"
701
r.new_revid = b"new-revid"
689
r.new_revid = "new-revid"
705
693
self.assertEqual("Now on revision 20.\n", f.getvalue())
694
self.assertEqual("Now on revision 20.\n", f.getvalue())
707
696
def test_report_unchanged(self):
708
697
r = _mod_branch.PullResult()
709
r.old_revid = b"same-revid"
710
r.new_revid = b"same-revid"
698
r.old_revid = "same-revid"
699
r.new_revid = "same-revid"
713
702
self.assertEqual("No revisions or tags to pull.\n", f.getvalue())