78
74
url = self.get_url()
79
75
bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
80
76
bdir.create_repository()
81
branch = BzrBranchFormat5().initialize(bdir)
77
branch = _mod_branch.BzrBranchFormat5().initialize(bdir)
82
78
t = self.get_transport()
83
79
self.log("branch instance is %r" % branch)
84
self.assert_(isinstance(branch, BzrBranch5))
80
self.assert_(isinstance(branch, _mod_branch.BzrBranch5))
85
81
self.assertIsDirectory('.', t)
86
82
self.assertIsDirectory('.bzr/branch', t)
87
83
self.assertIsDirectory('.bzr/branch/lock', t)
188
184
format.initialize(dir)
189
185
found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
190
186
self.assertIsInstance(found_format, format.__class__)
191
check_format(BzrBranchFormat5(), "bar")
187
check_format(_mod_branch.BzrBranchFormat5(), "bar")
193
189
def test_find_format_factory(self):
194
190
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
231
227
branch = _mod_branch.Branch.open('.')
232
228
self.assertEquals(branch._format.features, {})
230
def test_register_unregister_format(self):
231
# Test the deprecated format registration functions
232
format = SampleBranchFormat()
234
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
236
format.initialize(dir)
237
# register a format for it.
238
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
239
_mod_branch.BranchFormat.register_format, format)
240
# which branch.Open will refuse (not supported)
241
self.assertRaises(errors.UnsupportedFormatError,
242
_mod_branch.Branch.open, self.get_url())
243
self.make_branch_and_tree('foo')
244
# but open_downlevel will work
247
bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
248
# unregister the format
249
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
250
_mod_branch.BranchFormat.unregister_format, format)
251
self.make_branch_and_tree('bar')
235
254
class TestBranchFormatRegistry(tests.TestCase):
337
356
self.assertPathDoesNotExist('a/.bzr/branch/parent')
338
357
self.assertEqual('http://example.com', branch.get_parent())
339
358
branch.set_push_location('sftp://example.com')
340
conf = branch.get_config_stack()
341
self.assertEqual('sftp://example.com', conf.get('push_location'))
359
config = branch.get_config_stack()
360
self.assertEqual('sftp://example.com', config.get('push_location'))
342
361
branch.set_bound_location('ftp://example.com')
343
362
self.assertPathDoesNotExist('a/.bzr/branch/bound')
344
363
self.assertEqual('ftp://example.com', branch.get_bound_location())
365
def test_set_revision_history(self):
366
builder = self.make_branch_builder('.', format=self.get_format_name())
367
builder.build_snapshot('foo', None,
368
[('add', ('', None, 'directory', None))],
370
builder.build_snapshot('bar', None, [], message='bar')
371
branch = builder.get_branch()
373
self.addCleanup(branch.unlock)
374
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
375
branch.set_revision_history, ['foo', 'bar'])
376
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
377
branch.set_revision_history, ['foo'])
378
self.assertRaises(errors.NotLefthandHistory,
379
self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)),
380
branch.set_revision_history, ['bar'])
346
382
def do_checkout_test(self, lightweight=False):
347
383
tree = self.make_branch_and_tree('source',
348
384
format=self.get_format_name_subtree())
453
489
def make_branch(self, location, format=None):
454
490
if format is None:
455
format = controldir.format_registry.make_bzrdir('1.9')
491
format = bzrdir.format_registry.make_bzrdir('1.9')
456
492
format.set_branch_format(_mod_branch.BzrBranchFormat8())
457
493
return tests.TestCaseWithTransport.make_branch(
458
494
self, location, format=format)
555
591
def test_constructor(self):
556
592
"""Check that creating a BranchHooks instance has the right defaults."""
557
593
hooks = _mod_branch.BranchHooks()
594
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
558
595
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
559
596
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
560
597
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
656
693
'Value "not-a-bool" is not valid for "append_revisions_only"',
657
694
self.warnings[0])
659
def test_use_fresh_values(self):
660
copy = _mod_branch.Branch.open(self.branch.base)
663
copy.get_config_stack().set('foo', 'bar')
666
self.assertFalse(self.branch.is_locked())
667
# Since the branch is locked, the option value won't be saved on disk
668
# so trying to access the config of locked branch via another older
669
# non-locked branch object pointing to the same branch is not supported
670
self.assertEqual(None, self.branch.get_config_stack().get('foo'))
671
# Using a newly created branch object works as expected
672
fresh = _mod_branch.Branch.open(self.branch.base)
673
self.assertEqual('bar', fresh.get_config_stack().get('foo'))
675
def test_set_from_config_get_from_config_stack(self):
676
self.branch.lock_write()
677
self.addCleanup(self.branch.unlock)
678
self.branch.get_config().set_user_option('foo', 'bar')
679
result = self.branch.get_config_stack().get('foo')
680
# https://bugs.launchpad.net/bzr/+bug/948344
681
self.expectFailure('BranchStack uses cache after set_user_option',
682
self.assertEqual, 'bar', result)
684
def test_set_from_config_stack_get_from_config(self):
685
self.branch.lock_write()
686
self.addCleanup(self.branch.unlock)
687
self.branch.get_config_stack().set('foo', 'bar')
688
# Since the branch is locked, the option value won't be saved on disk
689
# so mixing get() and get_user_option() is broken by design.
690
self.assertEqual(None,
691
self.branch.get_config().get_user_option('foo'))
693
def test_set_delays_write_when_branch_is_locked(self):
694
self.branch.lock_write()
695
self.addCleanup(self.branch.unlock)
696
self.branch.get_config_stack().set('foo', 'bar')
697
copy = _mod_branch.Branch.open(self.branch.base)
698
result = copy.get_config_stack().get('foo')
699
# Accessing from a different branch object is like accessing from a
700
# different process: the option has not been saved yet and the new
701
# value cannot be seen.
702
self.assertIs(None, result)
705
697
class TestPullResult(tests.TestCase):
699
def test_pull_result_to_int(self):
700
# to support old code, the pull result can be used as an int
701
r = _mod_branch.PullResult()
704
# this usage of results is not recommended for new code (because it
705
# doesn't describe very well what happened), but for api stability
706
# it's still supported
707
self.assertEqual(self.applyDeprecated(
708
symbol_versioning.deprecated_in((2, 3, 0)),
707
712
def test_report_changed(self):
708
713
r = _mod_branch.PullResult()
709
714
r.old_revid = "old-revid"