35
revision as _mod_revision,
37
transport as _mod_transport,
38
from bzrlib.errors import (NotBranchError,
39
NoColocatedBranchSupport,
41
UnsupportedFormatError,
43
from bzrlib.tests import (
49
import breezy.bzr.branch
50
from ..bzr.fullhistory import BzrBranchFormat5
51
from ..errors import (
53
NoColocatedBranchSupport,
55
UnsupportedFormatError,
45
59
TestCaseWithMemoryTransport,
46
60
TestCaseWithTransport,
49
from bzrlib.tests import(
53
from bzrlib.tests.test_http import TestWithTransport_pycurl
54
from bzrlib.transport import (
67
from ..transport import (
58
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
from bzrlib.transport.nosmart import NoSmartTransportDecorator
60
from bzrlib.transport.readonly import ReadonlyTransportDecorator
61
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
71
from ..transport.http import HttpTransport
72
from ..transport.nosmart import NoSmartTransportDecorator
73
from ..transport.readonly import ReadonlyTransportDecorator
74
from ..bzr import knitrepo, knitpack_repo
64
77
class TestDefaultFormat(TestCase):
66
79
def test_get_set_default_format(self):
67
80
old_format = bzrdir.BzrDirFormat.get_default_format()
68
# default is BzrDirFormat6
69
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
70
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
81
# default is BzrDirMetaFormat1
82
self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
83
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
71
84
# creating a bzr dir should now create an instrumented dir.
73
86
result = bzrdir.BzrDir.create('memory:///')
74
self.failUnless(isinstance(result, SampleBzrDir))
87
self.assertIsInstance(result, SampleBzrDir)
76
bzrdir.BzrDirFormat._set_default_format(old_format)
89
controldir.ControlDirFormat._set_default_format(old_format)
77
90
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
93
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
94
"""A deprecated bzr dir format."""
80
97
class TestFormatRegistry(TestCase):
82
99
def make_format_registry(self):
83
my_format_registry = bzrdir.BzrDirFormatRegistry()
84
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
'Pre-0.8 format. Slower and does not support checkouts or shared'
86
' repositories', deprecated=True)
87
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
my_format_registry.register_metadir('knit',
90
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
100
my_format_registry = controldir.ControlDirFormatRegistry()
101
my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
102
'Some format. Slower and unawesome and deprecated.',
104
my_format_registry.register_lazy('lazy', 'breezy.tests.test_bzrdir',
105
'DeprecatedBzrDirFormat', 'Format registered lazily',
107
bzr.register_metadir(my_format_registry, 'knit',
108
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
91
109
'Format using knits',
93
111
my_format_registry.set_default('knit')
94
my_format_registry.register_metadir(
112
bzr.register_metadir(my_format_registry,
96
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
114
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
97
115
'Experimental successor to knit. Use at your own risk.',
98
branch_format='bzrlib.branch.BzrBranchFormat6',
116
branch_format='breezy.bzr.branch.BzrBranchFormat6',
99
117
experimental=True)
100
my_format_registry.register_metadir(
118
bzr.register_metadir(my_format_registry,
102
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
120
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
103
121
'Experimental successor to knit. Use at your own risk.',
104
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
105
my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
106
'Pre-0.8 format. Slower and does not support checkouts or shared'
107
' repositories', hidden=True)
108
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
109
'BzrDirFormat6', 'Format registered lazily', deprecated=True,
122
branch_format='breezy.bzr.branch.BzrBranchFormat6', hidden=True)
123
my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
124
'Old format. Slower and does not support things. ', hidden=True)
125
my_format_registry.register_lazy('hiddenlazy', 'breezy.tests.test_bzrdir',
126
'DeprecatedBzrDirFormat', 'Format registered lazily',
127
deprecated=True, hidden=True)
111
128
return my_format_registry
113
130
def test_format_registry(self):
114
131
my_format_registry = self.make_format_registry()
115
my_bzrdir = my_format_registry.make_bzrdir('lazy')
116
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
117
my_bzrdir = my_format_registry.make_bzrdir('weave')
118
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
119
my_bzrdir = my_format_registry.make_bzrdir('default')
120
self.assertIsInstance(my_bzrdir.repository_format,
121
knitrepo.RepositoryFormatKnit1)
122
my_bzrdir = my_format_registry.make_bzrdir('knit')
123
self.assertIsInstance(my_bzrdir.repository_format,
124
knitrepo.RepositoryFormatKnit1)
125
my_bzrdir = my_format_registry.make_bzrdir('branch6')
132
my_bzrdir = my_format_registry.make_controldir('lazy')
133
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
134
my_bzrdir = my_format_registry.make_controldir('deprecated')
135
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
136
my_bzrdir = my_format_registry.make_controldir('default')
137
self.assertIsInstance(my_bzrdir.repository_format,
138
knitrepo.RepositoryFormatKnit1)
139
my_bzrdir = my_format_registry.make_controldir('knit')
140
self.assertIsInstance(my_bzrdir.repository_format,
141
knitrepo.RepositoryFormatKnit1)
142
my_bzrdir = my_format_registry.make_controldir('branch6')
126
143
self.assertIsInstance(my_bzrdir.get_branch_format(),
127
bzrlib.branch.BzrBranchFormat6)
144
breezy.bzr.branch.BzrBranchFormat6)
129
146
def test_get_help(self):
130
147
my_format_registry = self.make_format_registry()
150
166
experimental, deprecated = rest.split('Deprecated formats')
151
167
self.assertContainsRe(new, 'formats-help')
152
168
self.assertContainsRe(new,
153
':knit:\n \(native\) \(default\) Format using knits\n')
169
':knit:\n \\(native\\) \\(default\\) Format using knits\n')
154
170
self.assertContainsRe(experimental,
155
':branch6:\n \(native\) Experimental successor to knit')
171
':branch6:\n \\(native\\) Experimental successor to knit')
156
172
self.assertContainsRe(deprecated,
157
':lazy:\n \(native\) Format registered lazily\n')
173
':lazy:\n \\(native\\) Format registered lazily\n')
158
174
self.assertNotContainsRe(new, 'hidden')
160
176
def test_set_default_repository(self):
161
default_factory = bzrdir.format_registry.get('default')
162
old_default = [k for k, v in bzrdir.format_registry.iteritems()
177
default_factory = controldir.format_registry.get('default')
178
old_default = [k for k, v in controldir.format_registry.iteritems()
163
179
if v == default_factory and k != 'default'][0]
164
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
180
controldir.format_registry.set_default_repository('dirstate-with-subtree')
166
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
167
bzrdir.format_registry.get('default'))
182
self.assertIs(controldir.format_registry.get('dirstate-with-subtree'),
183
controldir.format_registry.get('default'))
169
repository.RepositoryFormat.get_default_format().__class__,
185
repository.format_registry.get_default().__class__,
170
186
knitrepo.RepositoryFormatKnit3)
172
bzrdir.format_registry.set_default_repository(old_default)
188
controldir.format_registry.set_default_repository(old_default)
174
190
def test_aliases(self):
175
a_registry = bzrdir.BzrDirFormatRegistry()
176
a_registry.register('weave', bzrdir.BzrDirFormat6,
177
'Pre-0.8 format. Slower and does not support checkouts or shared'
178
' repositories', deprecated=True)
179
a_registry.register('weavealias', bzrdir.BzrDirFormat6,
180
'Pre-0.8 format. Slower and does not support checkouts or shared'
181
' repositories', deprecated=True, alias=True)
182
self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
185
class SampleBranch(bzrlib.branch.Branch):
191
a_registry = controldir.ControlDirFormatRegistry()
192
a_registry.register('deprecated', DeprecatedBzrDirFormat,
193
'Old format. Slower and does not support stuff',
195
a_registry.register_alias('deprecatedalias', 'deprecated')
196
self.assertEqual({'deprecatedalias': 'deprecated'},
197
a_registry.aliases())
200
class SampleBranch(breezy.branch.Branch):
186
201
"""A dummy branch for guess what, dummy use."""
188
203
def __init__(self, dir):
192
class SampleRepository(bzrlib.repository.Repository):
204
self.controldir = dir
207
class SampleRepository(breezy.repository.Repository):
193
208
"""A dummy repo."""
195
210
def __init__(self, dir):
211
self.controldir = dir
199
214
class SampleBzrDir(bzrdir.BzrDir):
200
215
"""A sample BzrDir implementation to allow testing static methods."""
202
217
def create_repository(self, shared=False):
203
"""See BzrDir.create_repository."""
218
"""See ControlDir.create_repository."""
204
219
return "A repository"
206
221
def open_repository(self):
207
"""See BzrDir.open_repository."""
222
"""See ControlDir.open_repository."""
208
223
return SampleRepository(self)
210
225
def create_branch(self, name=None):
211
"""See BzrDir.create_branch."""
226
"""See ControlDir.create_branch."""
212
227
if name is not None:
213
228
raise NoColocatedBranchSupport(self)
214
229
return SampleBranch(self)
216
231
def create_workingtree(self):
217
"""See BzrDir.create_workingtree."""
232
"""See ControlDir.create_workingtree."""
248
281
def test_find_format(self):
249
282
# is the right format object found for a branch?
250
283
# create a branch with a few known format objects.
251
# this is not quite the same as
252
t = get_transport(self.get_url())
284
bzr.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
286
self.addCleanup(bzr.BzrProber.formats.remove,
287
BzrDirFormatTest1.get_format_string())
288
bzr.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
290
self.addCleanup(bzr.BzrProber.formats.remove,
291
BzrDirFormatTest2.get_format_string())
292
t = self.get_transport()
253
293
self.build_tree(["foo/", "bar/"], transport=t)
254
294
def check_format(format, url):
255
295
format.initialize(url)
256
t = get_transport(url)
296
t = _mod_transport.get_transport_from_path(url)
257
297
found_format = bzrdir.BzrDirFormat.find_format(t)
258
self.failUnless(isinstance(found_format, format.__class__))
259
check_format(bzrdir.BzrDirFormat5(), "foo")
260
check_format(bzrdir.BzrDirFormat6(), "bar")
298
self.assertIsInstance(found_format, format.__class__)
299
check_format(BzrDirFormatTest1(), "foo")
300
check_format(BzrDirFormatTest2(), "bar")
262
302
def test_find_format_nothing_there(self):
263
303
self.assertRaises(NotBranchError,
264
304
bzrdir.BzrDirFormat.find_format,
305
_mod_transport.get_transport_from_path('.'))
267
307
def test_find_format_unknown_format(self):
268
t = get_transport(self.get_url())
308
t = self.get_transport()
270
310
t.put_bytes('.bzr/branch-format', '')
271
311
self.assertRaises(UnknownFormatError,
272
312
bzrdir.BzrDirFormat.find_format,
313
_mod_transport.get_transport_from_path('.'))
275
315
def test_register_unregister_format(self):
276
316
format = SampleBzrDirFormat()
339
379
self.get_readonly_url('child'), format=format)
340
380
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
342
tree.bzrdir.open_repository()
382
tree.controldir.open_repository()
344
384
def test_create_branch_convenience(self):
345
385
# outside a repo the default convenience output is a repo+branch_tree
346
format = bzrdir.format_registry.make_bzrdir('knit')
386
format = controldir.format_registry.make_controldir('knit')
347
387
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
348
branch.bzrdir.open_workingtree()
349
branch.bzrdir.open_repository()
388
branch.controldir.open_workingtree()
389
branch.controldir.open_repository()
351
391
def test_create_branch_convenience_possible_transports(self):
352
392
"""Check that the optional 'possible_transports' is recognized"""
353
format = bzrdir.format_registry.make_bzrdir('knit')
393
format = controldir.format_registry.make_controldir('knit')
354
394
t = self.get_transport()
355
395
branch = bzrdir.BzrDir.create_branch_convenience(
356
396
'.', format=format, possible_transports=[t])
357
branch.bzrdir.open_workingtree()
358
branch.bzrdir.open_repository()
397
branch.controldir.open_workingtree()
398
branch.controldir.open_repository()
360
400
def test_create_branch_convenience_root(self):
361
401
"""Creating a branch at the root of a fs should work."""
362
402
self.vfs_transport_factory = memory.MemoryServer
363
403
# outside a repo the default convenience output is a repo+branch_tree
364
format = bzrdir.format_registry.make_bzrdir('knit')
404
format = controldir.format_registry.make_controldir('knit')
365
405
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
367
407
self.assertRaises(errors.NoWorkingTree,
368
branch.bzrdir.open_workingtree)
369
branch.bzrdir.open_repository()
408
branch.controldir.open_workingtree)
409
branch.controldir.open_repository()
371
411
def test_create_branch_convenience_under_shared_repo(self):
372
412
# inside a repo the default convenience output is a branch+ follow the
373
413
# repo tree policy
374
format = bzrdir.format_registry.make_bzrdir('knit')
414
format = controldir.format_registry.make_controldir('knit')
375
415
self.make_repository('.', shared=True, format=format)
376
416
branch = bzrdir.BzrDir.create_branch_convenience('child',
378
branch.bzrdir.open_workingtree()
418
branch.controldir.open_workingtree()
379
419
self.assertRaises(errors.NoRepositoryPresent,
380
branch.bzrdir.open_repository)
420
branch.controldir.open_repository)
382
422
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
383
423
# inside a repo the default convenience output is a branch+ follow the
384
424
# repo tree policy but we can override that
385
format = bzrdir.format_registry.make_bzrdir('knit')
425
format = controldir.format_registry.make_controldir('knit')
386
426
self.make_repository('.', shared=True, format=format)
387
427
branch = bzrdir.BzrDir.create_branch_convenience('child',
388
428
force_new_tree=False, format=format)
389
429
self.assertRaises(errors.NoWorkingTree,
390
branch.bzrdir.open_workingtree)
430
branch.controldir.open_workingtree)
391
431
self.assertRaises(errors.NoRepositoryPresent,
392
branch.bzrdir.open_repository)
432
branch.controldir.open_repository)
394
434
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
395
435
# inside a repo the default convenience output is a branch+ follow the
396
436
# repo tree policy
397
format = bzrdir.format_registry.make_bzrdir('knit')
437
format = controldir.format_registry.make_controldir('knit')
398
438
repo = self.make_repository('.', shared=True, format=format)
399
439
repo.set_make_working_trees(False)
400
440
branch = bzrdir.BzrDir.create_branch_convenience('child',
402
442
self.assertRaises(errors.NoWorkingTree,
403
branch.bzrdir.open_workingtree)
443
branch.controldir.open_workingtree)
404
444
self.assertRaises(errors.NoRepositoryPresent,
405
branch.bzrdir.open_repository)
445
branch.controldir.open_repository)
407
447
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
408
448
# inside a repo the default convenience output is a branch+ follow the
409
449
# repo tree policy but we can override that
410
format = bzrdir.format_registry.make_bzrdir('knit')
450
format = controldir.format_registry.make_controldir('knit')
411
451
repo = self.make_repository('.', shared=True, format=format)
412
452
repo.set_make_working_trees(False)
413
453
branch = bzrdir.BzrDir.create_branch_convenience('child',
414
454
force_new_tree=True, format=format)
415
branch.bzrdir.open_workingtree()
455
branch.controldir.open_workingtree()
416
456
self.assertRaises(errors.NoRepositoryPresent,
417
branch.bzrdir.open_repository)
457
branch.controldir.open_repository)
419
459
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
420
460
# inside a repo the default convenience output is overridable to give
421
461
# repo+branch+tree
422
format = bzrdir.format_registry.make_bzrdir('knit')
462
format = controldir.format_registry.make_controldir('knit')
423
463
self.make_repository('.', shared=True, format=format)
424
464
branch = bzrdir.BzrDir.create_branch_convenience('child',
425
465
force_new_repo=True, format=format)
426
branch.bzrdir.open_repository()
427
branch.bzrdir.open_workingtree()
466
branch.controldir.open_repository()
467
branch.controldir.open_workingtree()
430
470
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
432
472
def test_acquire_repository_standalone(self):
433
473
"""The default acquisition policy should create a standalone branch."""
434
my_bzrdir = self.make_bzrdir('.')
474
my_bzrdir = self.make_controldir('.')
435
475
repo_policy = my_bzrdir.determine_repository_policy()
436
476
repo, is_new = repo_policy.acquire_repository()
437
self.assertEqual(repo.bzrdir.root_transport.base,
477
self.assertEqual(repo.controldir.root_transport.base,
438
478
my_bzrdir.root_transport.base)
439
479
self.assertFalse(repo.is_shared())
441
481
def test_determine_stacking_policy(self):
442
parent_bzrdir = self.make_bzrdir('.')
443
child_bzrdir = self.make_bzrdir('child')
482
parent_bzrdir = self.make_controldir('.')
483
child_bzrdir = self.make_controldir('child')
444
484
parent_bzrdir.get_config().set_default_stack_on('http://example.org')
445
485
repo_policy = child_bzrdir.determine_repository_policy()
446
486
self.assertEqual('http://example.org', repo_policy._stack_on)
448
488
def test_determine_stacking_policy_relative(self):
449
parent_bzrdir = self.make_bzrdir('.')
450
child_bzrdir = self.make_bzrdir('child')
489
parent_bzrdir = self.make_controldir('.')
490
child_bzrdir = self.make_controldir('child')
451
491
parent_bzrdir.get_config().set_default_stack_on('child2')
452
492
repo_policy = child_bzrdir.determine_repository_policy()
453
493
self.assertEqual('child2', repo_policy._stack_on)
464
504
def test_clone_on_transport_obeys_stacking_policy(self):
465
505
child_branch, new_child_transport = self.prepare_default_stacking()
466
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
506
new_child = child_branch.controldir.clone_on_transport(new_child_transport)
467
507
self.assertEqual(child_branch.base,
468
508
new_child.open_branch().get_stacked_on_url())
470
510
def test_default_stacking_with_stackable_branch_unstackable_repo(self):
471
511
# Make stackable source branch with an unstackable repo format.
472
source_bzrdir = self.make_bzrdir('source')
473
pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
474
source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
512
source_bzrdir = self.make_controldir('source')
513
knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
514
source_branch = breezy.bzr.branch.BzrBranchFormat7().initialize(
476
516
# Make a directory with a default stacking policy
477
parent_bzrdir = self.make_bzrdir('parent')
517
parent_bzrdir = self.make_controldir('parent')
478
518
stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
479
519
parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
480
520
# Clone source into directory
481
521
target = source_bzrdir.clone(self.get_url('parent/target'))
523
def test_format_initialize_on_transport_ex_stacked_on(self):
524
# trunk is a stackable format. Note that its in the same server area
525
# which is what launchpad does, but not sufficient to exercise the
527
trunk = self.make_branch('trunk', format='1.9')
528
t = self.get_transport('stacked')
529
old_fmt = controldir.format_registry.make_controldir('pack-0.92')
530
repo_name = old_fmt.repository_format.network_name()
531
# Should end up with a 1.9 format (stackable)
532
repo, control, require_stacking, repo_policy = \
533
old_fmt.initialize_on_transport_ex(t,
534
repo_format_name=repo_name, stacked_on='../trunk',
537
# Repositories are open write-locked
538
self.assertTrue(repo.is_write_locked())
539
self.addCleanup(repo.unlock)
541
repo = control.open_repository()
542
self.assertIsInstance(control, bzrdir.BzrDir)
543
opened = bzrdir.BzrDir.open(t.base)
544
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
545
self.assertEqual(control._format.network_name(),
546
old_fmt.network_name())
547
self.assertEqual(control._format.network_name(),
548
opened._format.network_name())
549
self.assertEqual(control.__class__, opened.__class__)
550
self.assertLength(1, repo._fallback_repositories)
483
552
def test_sprout_obeys_stacking_policy(self):
484
553
child_branch, new_child_transport = self.prepare_default_stacking()
485
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
554
new_child = child_branch.controldir.sprout(new_child_transport.base)
486
555
self.assertEqual(child_branch.base,
487
556
new_child.open_branch().get_stacked_on_url())
489
558
def test_clone_ignores_policy_for_unsupported_formats(self):
490
559
child_branch, new_child_transport = self.prepare_default_stacking(
491
560
child_format='pack-0.92')
492
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
493
self.assertRaises(errors.UnstackableBranchFormat,
561
new_child = child_branch.controldir.clone_on_transport(new_child_transport)
562
self.assertRaises(branch.UnstackableBranchFormat,
494
563
new_child.open_branch().get_stacked_on_url)
496
565
def test_sprout_ignores_policy_for_unsupported_formats(self):
497
566
child_branch, new_child_transport = self.prepare_default_stacking(
498
567
child_format='pack-0.92')
499
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
500
self.assertRaises(errors.UnstackableBranchFormat,
568
new_child = child_branch.controldir.sprout(new_child_transport.base)
569
self.assertRaises(branch.UnstackableBranchFormat,
501
570
new_child.open_branch().get_stacked_on_url)
503
572
def test_sprout_upgrades_format_if_stacked_specified(self):
504
573
child_branch, new_child_transport = self.prepare_default_stacking(
505
574
child_format='pack-0.92')
506
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
575
new_child = child_branch.controldir.sprout(new_child_transport.base,
508
self.assertEqual(child_branch.bzrdir.root_transport.base,
577
self.assertEqual(child_branch.controldir.root_transport.base,
509
578
new_child.open_branch().get_stacked_on_url())
510
579
repo = new_child.open_repository()
511
580
self.assertTrue(repo._format.supports_external_lookups)
672
741
self.assertEqual(branch, None)
673
742
self.assertEqual(
674
743
osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
675
repo.bzrdir.transport.local_abspath('repository'))
744
repo.controldir.transport.local_abspath('repository'))
676
745
self.assertEqual(relpath, 'baz')
678
747
def test_open_containing_from_transport(self):
679
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
680
get_transport(self.get_readonly_url('')))
681
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
682
get_transport(self.get_readonly_url('g/p/q')))
748
self.assertRaises(NotBranchError,
749
bzrdir.BzrDir.open_containing_from_transport,
750
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
751
self.assertRaises(NotBranchError,
752
bzrdir.BzrDir.open_containing_from_transport,
753
_mod_transport.get_transport_from_url(
754
self.get_readonly_url('g/p/q')))
683
755
control = bzrdir.BzrDir.create(self.get_url())
684
756
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
685
get_transport(self.get_readonly_url('')))
757
_mod_transport.get_transport_from_url(
758
self.get_readonly_url('')))
686
759
self.assertEqual('', relpath)
687
760
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
688
get_transport(self.get_readonly_url('g/p/q')))
761
_mod_transport.get_transport_from_url(
762
self.get_readonly_url('g/p/q')))
689
763
self.assertEqual('g/p/q', relpath)
691
765
def test_open_containing_tree_or_branch(self):
735
809
# transport pointing at bzrdir should give a bzrdir with root transport
736
810
# set to the given transport
737
811
control = bzrdir.BzrDir.create(self.get_url())
738
transport = get_transport(self.get_url())
739
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
740
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
812
t = self.get_transport()
813
opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
814
self.assertEqual(t.base, opened_bzrdir.root_transport.base)
741
815
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
743
817
def test_open_from_transport_no_bzrdir(self):
744
transport = get_transport(self.get_url())
745
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
818
t = self.get_transport()
819
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
748
821
def test_open_from_transport_bzrdir_in_parent(self):
749
822
control = bzrdir.BzrDir.create(self.get_url())
750
transport = get_transport(self.get_url())
751
transport.mkdir('subdir')
752
transport = transport.clone('subdir')
753
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
823
t = self.get_transport()
825
t = t.clone('subdir')
826
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
756
828
def test_sprout_recursive(self):
757
829
tree = self.make_branch_and_tree('tree1',
758
format='dirstate-with-subtree')
830
format='development-subtree')
759
831
sub_tree = self.make_branch_and_tree('tree1/subtree',
760
format='dirstate-with-subtree')
761
sub_tree.set_root_id('subtree-root')
832
format='development-subtree')
833
sub_tree.set_root_id(b'subtree-root')
762
834
tree.add_reference(sub_tree)
763
835
self.build_tree(['tree1/subtree/file'])
764
836
sub_tree.add('file')
765
837
tree.commit('Initial commit')
766
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
838
tree2 = tree.controldir.sprout('tree2').open_workingtree()
767
839
tree2.lock_read()
768
840
self.addCleanup(tree2.unlock)
769
self.failUnlessExists('tree2/subtree/file')
770
self.assertEqual('tree-reference', tree2.kind('subtree-root'))
841
self.assertPathExists('tree2/subtree/file')
844
tree2.kind('subtree', 'subtree-root'))
772
846
def test_cloning_metadir(self):
773
847
"""Ensure that cloning metadir is suitable"""
774
bzrdir = self.make_bzrdir('bzrdir')
848
bzrdir = self.make_controldir('bzrdir')
775
849
bzrdir.cloning_metadir()
776
850
branch = self.make_branch('branch', format='knit')
777
format = branch.bzrdir.cloning_metadir()
851
format = branch.controldir.cloning_metadir()
778
852
self.assertIsInstance(format.workingtree_format,
779
workingtree.WorkingTreeFormat3)
853
workingtree_4.WorkingTreeFormat6)
781
855
def test_sprout_recursive_treeless(self):
782
856
tree = self.make_branch_and_tree('tree1',
783
format='dirstate-with-subtree')
857
format='development-subtree')
784
858
sub_tree = self.make_branch_and_tree('tree1/subtree',
785
format='dirstate-with-subtree')
859
format='development-subtree')
786
860
tree.add_reference(sub_tree)
787
861
self.build_tree(['tree1/subtree/file'])
788
862
sub_tree.add('file')
789
863
tree.commit('Initial commit')
790
tree.bzrdir.destroy_workingtree()
864
# The following line force the orhaning to reveal bug #634470
865
tree.branch.get_config_stack().set(
866
'transform.orphan_policy', 'move')
867
tree.controldir.destroy_workingtree()
868
# FIXME: subtree/.bzr is left here which allows the test to pass (or
869
# fail :-( ) -- vila 20100909
791
870
repo = self.make_repository('repo', shared=True,
792
format='dirstate-with-subtree')
871
format='development-subtree')
793
872
repo.set_make_working_trees(False)
794
tree.bzrdir.sprout('repo/tree2')
795
self.failUnlessExists('repo/tree2/subtree')
796
self.failIfExists('repo/tree2/subtree/file')
873
# FIXME: we just deleted the workingtree and now we want to use it ????
874
# At a minimum, we should use tree.branch below (but this fails too
875
# currently) or stop calling this test 'treeless'. Specifically, I've
876
# turn the line below into an assertRaises when 'subtree/.bzr' is
877
# orphaned and sprout tries to access the branch there (which is left
878
# by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
879
# [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
880
# #634470. -- vila 20100909
881
self.assertRaises(errors.NotBranchError,
882
tree.controldir.sprout, 'repo/tree2')
883
# self.assertPathExists('repo/tree2/subtree')
884
# self.assertPathDoesNotExist('repo/tree2/subtree/file')
798
886
def make_foo_bar_baz(self):
799
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
800
bar = self.make_branch('foo/bar').bzrdir
801
baz = self.make_branch('baz').bzrdir
887
foo = bzrdir.BzrDir.create_branch_convenience('foo').controldir
888
bar = self.make_branch('foo/bar').controldir
889
baz = self.make_branch('baz').controldir
802
890
return foo, bar, baz
804
def test_find_bzrdirs(self):
805
foo, bar, baz = self.make_foo_bar_baz()
806
transport = get_transport(self.get_url())
807
self.assertEqualBzrdirs([baz, foo, bar],
808
bzrdir.BzrDir.find_bzrdirs(transport))
810
def test_find_bzrdirs_list_current(self):
892
def test_find_controldirs(self):
893
foo, bar, baz = self.make_foo_bar_baz()
894
t = self.get_transport()
895
self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_controldirs(t))
897
def make_fake_permission_denied_transport(self, transport, paths):
898
"""Create a transport that raises PermissionDenied for some paths."""
901
raise errors.PermissionDenied(path)
903
path_filter_server = pathfilter.PathFilteringServer(transport, filter)
904
path_filter_server.start_server()
905
self.addCleanup(path_filter_server.stop_server)
906
path_filter_transport = pathfilter.PathFilteringTransport(
907
path_filter_server, '.')
908
return (path_filter_server, path_filter_transport)
910
def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
911
"""Check that each branch url ends with the given suffix."""
912
for actual_bzrdir in actual_bzrdirs:
913
self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
915
def test_find_controldirs_permission_denied(self):
916
foo, bar, baz = self.make_foo_bar_baz()
917
t = self.get_transport()
918
path_filter_server, path_filter_transport = \
919
self.make_fake_permission_denied_transport(t, ['foo'])
921
self.assertBranchUrlsEndWith('/baz/',
922
bzrdir.BzrDir.find_controldirs(path_filter_transport))
924
smart_transport = self.make_smart_server('.',
925
backing_server=path_filter_server)
926
self.assertBranchUrlsEndWith('/baz/',
927
bzrdir.BzrDir.find_controldirs(smart_transport))
929
def test_find_controldirs_list_current(self):
811
930
def list_current(transport):
812
931
return [s for s in transport.list_dir('') if s != 'baz']
814
933
foo, bar, baz = self.make_foo_bar_baz()
815
transport = get_transport(self.get_url())
816
self.assertEqualBzrdirs([foo, bar],
817
bzrdir.BzrDir.find_bzrdirs(transport,
818
list_current=list_current))
821
def test_find_bzrdirs_evaluate(self):
934
t = self.get_transport()
935
self.assertEqualBzrdirs(
937
bzrdir.BzrDir.find_controldirs(t, list_current=list_current))
939
def test_find_controldirs_evaluate(self):
822
940
def evaluate(bzrdir):
824
942
repo = bzrdir.open_repository()
825
except NoRepositoryPresent:
943
except errors.NoRepositoryPresent:
826
944
return True, bzrdir.root_transport.base
828
946
return False, bzrdir.root_transport.base
830
948
foo, bar, baz = self.make_foo_bar_baz()
831
transport = get_transport(self.get_url())
949
t = self.get_transport()
832
950
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
833
list(bzrdir.BzrDir.find_bzrdirs(transport,
951
list(bzrdir.BzrDir.find_controldirs(t, evaluate=evaluate)))
836
953
def assertEqualBzrdirs(self, first, second):
837
954
first = list(first)
843
960
def test_find_branches(self):
844
961
root = self.make_repository('', shared=True)
845
962
foo, bar, baz = self.make_foo_bar_baz()
846
qux = self.make_bzrdir('foo/qux')
847
transport = get_transport(self.get_url())
848
branches = bzrdir.BzrDir.find_branches(transport)
963
qux = self.make_controldir('foo/qux')
964
t = self.get_transport()
965
branches = bzrdir.BzrDir.find_branches(t)
849
966
self.assertEqual(baz.root_transport.base, branches[0].base)
850
967
self.assertEqual(foo.root_transport.base, branches[1].base)
851
968
self.assertEqual(bar.root_transport.base, branches[2].base)
853
970
# ensure this works without a top-level repo
854
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
971
branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
855
972
self.assertEqual(foo.root_transport.base, branches[0].base)
856
973
self.assertEqual(bar.root_transport.base, branches[1].base)
976
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
978
def test_find_controldirs_missing_repo(self):
979
t = self.get_transport()
980
arepo = self.make_repository('arepo', shared=True)
981
abranch_url = arepo.user_url + '/abranch'
982
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
983
t.delete_tree('arepo/.bzr')
984
self.assertRaises(errors.NoRepositoryPresent,
985
branch.Branch.open, abranch_url)
986
self.make_branch('baz')
987
for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
988
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
859
991
class TestMeta1DirFormat(TestCaseWithTransport):
860
992
"""Tests specific to the meta1 dir format."""
887
1020
Metadirs should compare equal iff they have the same repo, branch and
890
mydir = bzrdir.format_registry.make_bzrdir('knit')
1023
mydir = controldir.format_registry.make_controldir('knit')
891
1024
self.assertEqual(mydir, mydir)
892
1025
self.assertFalse(mydir != mydir)
893
otherdir = bzrdir.format_registry.make_bzrdir('knit')
1026
otherdir = controldir.format_registry.make_controldir('knit')
894
1027
self.assertEqual(otherdir, mydir)
895
1028
self.assertFalse(otherdir != mydir)
896
otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
1029
otherdir2 = controldir.format_registry.make_controldir('development-subtree')
897
1030
self.assertNotEqual(otherdir2, mydir)
898
1031
self.assertFalse(otherdir2 == mydir)
1033
def test_with_features(self):
1034
tree = self.make_branch_and_tree('tree', format='2a')
1035
tree.controldir.update_feature_flags({b"bar": b"required"})
1036
self.assertRaises(bzrdir.MissingFeature, bzrdir.BzrDir.open, 'tree')
1037
bzrdir.BzrDirMetaFormat1.register_feature(b'bar')
1038
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, b'bar')
1039
dir = bzrdir.BzrDir.open('tree')
1040
self.assertEqual(b"required", dir._format.features.get(b"bar"))
1041
tree.controldir.update_feature_flags({
1043
b"nonexistant": None})
1044
dir = bzrdir.BzrDir.open('tree')
1045
self.assertEqual({}, dir._format.features)
900
1047
def test_needs_conversion_different_working_tree(self):
901
1048
# meta1dirs need an conversion if any element is not the default.
902
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1049
new_format = controldir.format_registry.make_controldir('dirstate')
903
1050
tree = self.make_branch_and_tree('tree', format='knit')
904
self.assertTrue(tree.bzrdir.needs_format_conversion(
1051
self.assertTrue(tree.controldir.needs_format_conversion(
907
1054
def test_initialize_on_format_uses_smart_transport(self):
908
1055
self.setup_smart_server_with_call_log()
909
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1056
new_format = controldir.format_registry.make_controldir('dirstate')
910
1057
transport = self.get_transport('target')
911
1058
transport.ensure_base()
912
1059
self.reset_smart_call_log()
921
1068
self.assertEqual(2, rpc_count)
924
class TestFormat5(TestCaseWithTransport):
925
"""Tests specific to the version 5 bzrdir format."""
927
def test_same_lockfiles_between_tree_repo_branch(self):
928
# this checks that only a single lockfiles instance is created
929
# for format 5 objects
930
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
931
def check_dir_components_use_same_lock(dir):
932
ctrl_1 = dir.open_repository().control_files
933
ctrl_2 = dir.open_branch().control_files
934
ctrl_3 = dir.open_workingtree()._control_files
935
self.assertTrue(ctrl_1 is ctrl_2)
936
self.assertTrue(ctrl_2 is ctrl_3)
937
check_dir_components_use_same_lock(dir)
938
# and if we open it normally.
939
dir = bzrdir.BzrDir.open(self.get_url())
940
check_dir_components_use_same_lock(dir)
942
def test_can_convert(self):
943
# format 5 dirs are convertable
944
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
945
self.assertTrue(dir.can_convert_format())
947
def test_needs_conversion(self):
948
# format 5 dirs need a conversion if they are not the default,
950
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
951
# don't need to convert it to itself
952
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
953
# do need to convert it to the current default
954
self.assertTrue(dir.needs_format_conversion(
955
bzrdir.BzrDirFormat.get_default_format()))
958
class TestFormat6(TestCaseWithTransport):
959
"""Tests specific to the version 6 bzrdir format."""
961
def test_same_lockfiles_between_tree_repo_branch(self):
962
# this checks that only a single lockfiles instance is created
963
# for format 6 objects
964
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
965
def check_dir_components_use_same_lock(dir):
966
ctrl_1 = dir.open_repository().control_files
967
ctrl_2 = dir.open_branch().control_files
968
ctrl_3 = dir.open_workingtree()._control_files
969
self.assertTrue(ctrl_1 is ctrl_2)
970
self.assertTrue(ctrl_2 is ctrl_3)
971
check_dir_components_use_same_lock(dir)
972
# and if we open it normally.
973
dir = bzrdir.BzrDir.open(self.get_url())
974
check_dir_components_use_same_lock(dir)
976
def test_can_convert(self):
977
# format 6 dirs are convertable
978
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
979
self.assertTrue(dir.can_convert_format())
981
def test_needs_conversion(self):
982
# format 6 dirs need an conversion if they are not the default.
983
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
984
self.assertTrue(dir.needs_format_conversion(
985
bzrdir.BzrDirFormat.get_default_format()))
988
class NotBzrDir(bzrlib.bzrdir.BzrDir):
989
"""A non .bzr based control directory."""
991
def __init__(self, transport, format):
992
self._format = format
993
self.root_transport = transport
994
self.transport = transport.clone('.not')
997
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
998
"""A test class representing any non-.bzr based disk format."""
1000
def initialize_on_transport(self, transport):
1001
"""Initialize a new .not dir in the base directory of a Transport."""
1002
transport.mkdir('.not')
1003
return self.open(transport)
1005
def open(self, transport):
1006
"""Open this directory."""
1007
return NotBzrDir(transport, self)
1010
def _known_formats(self):
1011
return set([NotBzrDirFormat()])
1014
def probe_transport(self, transport):
1015
"""Our format is present if the transport ends in '.not/'."""
1016
if transport.has('.not'):
1017
return NotBzrDirFormat()
1020
class TestNotBzrDir(TestCaseWithTransport):
1021
"""Tests for using the bzrdir api with a non .bzr based disk format.
1023
If/when one of these is in the core, we can let the implementation tests
1027
def test_create_and_find_format(self):
1028
# create a .notbzr dir
1029
format = NotBzrDirFormat()
1030
dir = format.initialize(self.get_url())
1031
self.assertIsInstance(dir, NotBzrDir)
1033
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
1035
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1036
get_transport(self.get_url()))
1037
self.assertIsInstance(found, NotBzrDirFormat)
1039
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
1041
def test_included_in_known_formats(self):
1042
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
1044
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1045
for format in formats:
1046
if isinstance(format, NotBzrDirFormat):
1048
self.fail("No NotBzrDirFormat in %s" % formats)
1050
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
1053
1071
class NonLocalTests(TestCaseWithTransport):
1054
1072
"""Tests for bzrdir static behaviour on non local paths."""
1245
1254
def __init__(self, *args, **kwargs):
1246
1255
super(_TestBzrDir, self).__init__(*args, **kwargs)
1247
self.test_branch = _TestBranch()
1256
self.test_branch = _TestBranch(self.transport)
1248
1257
self.test_branch.repository = self.create_repository()
1250
def open_branch(self, unsupported=False):
1259
def open_branch(self, unsupported=False, possible_transports=None):
1251
1260
return self.test_branch
1253
1262
def cloning_metadir(self, require_stacking=False):
1254
1263
return _TestBzrDirFormat()
1257
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1266
class _TestBranchFormat(breezy.branch.BranchFormat):
1258
1267
"""Test Branch format for TestBzrDirSprout."""
1261
class _TestBranch(bzrlib.branch.Branch):
1270
class _TestBranch(breezy.branch.Branch):
1262
1271
"""Test Branch implementation for TestBzrDirSprout."""
1264
def __init__(self, *args, **kwargs):
1273
def __init__(self, transport, *args, **kwargs):
1265
1274
self._format = _TestBranchFormat()
1275
self._transport = transport
1276
self.base = transport.base
1266
1277
super(_TestBranch, self).__init__(*args, **kwargs)
1267
1278
self.calls = []
1268
1279
self._parent = None
1270
1281
def sprout(self, *args, **kwargs):
1271
1282
self.calls.append('sprout')
1272
return _TestBranch()
1283
return _TestBranch(self._transport)
1274
1285
def copy_content_into(self, destination, revision_id=None):
1275
1286
self.calls.append('copy_content_into')
1288
def last_revision(self):
1289
return _mod_revision.NULL_REVISION
1277
1291
def get_parent(self):
1278
1292
return self._parent
1294
def _get_config(self):
1295
return config.TransportConfig(self._transport, 'branch.conf')
1297
def _get_config_store(self):
1298
return config.BranchStore(self)
1280
1300
def set_parent(self, parent):
1281
1301
self._parent = parent
1303
def lock_read(self):
1304
return lock.LogicalLockResult(self.unlock)
1284
1310
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1349
1375
self.assertLength(1, calls)
1350
1376
params = calls[0]
1351
1377
self.assertIsInstance(params, RepoInitHookParams)
1352
self.assertTrue(hasattr(params, 'bzrdir'))
1378
self.assertTrue(hasattr(params, 'controldir'))
1353
1379
self.assertTrue(hasattr(params, 'repository'))
1381
def test_post_repo_init_hook_repr(self):
1383
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1384
lambda params: param_reprs.append(repr(params)), None)
1385
self.make_repository('foo')
1386
self.assertLength(1, param_reprs)
1387
param_repr = param_reprs[0]
1388
self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1391
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1392
# FIXME: This may need to be unified with test_osutils.TestBackupNames or
1393
# moved to per_bzrdir or per_transport for better coverage ?
1397
super(TestGenerateBackupName, self).setUp()
1398
self._transport = self.get_transport()
1399
bzrdir.BzrDir.create(self.get_url(),
1400
possible_transports=[self._transport])
1401
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1404
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1406
def test_exiting(self):
1407
self._transport.put_bytes("a.~1~", "some content")
1408
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1411
class TestMeta1DirColoFormat(TestCaseWithTransport):
1412
"""Tests specific to the meta1 dir with colocated branches format."""
1414
def test_supports_colo(self):
1415
format = bzrdir.BzrDirMetaFormat1Colo()
1416
self.assertTrue(format.colocated_branches)
1418
def test_upgrade_from_2a(self):
1419
tree = self.make_branch_and_tree('.', format='2a')
1420
format = bzrdir.BzrDirMetaFormat1Colo()
1421
self.assertTrue(tree.controldir.needs_format_conversion(format))
1422
converter = tree.controldir._format.get_converter(format)
1423
result = converter.convert(tree.controldir, None)
1424
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1425
self.assertFalse(result.needs_format_conversion(format))
1427
def test_downgrade_to_2a(self):
1428
tree = self.make_branch_and_tree('.', format='development-colo')
1429
format = bzrdir.BzrDirMetaFormat1()
1430
self.assertTrue(tree.controldir.needs_format_conversion(format))
1431
converter = tree.controldir._format.get_converter(format)
1432
result = converter.convert(tree.controldir, None)
1433
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1434
self.assertFalse(result.needs_format_conversion(format))
1436
def test_downgrade_to_2a_too_many_branches(self):
1437
tree = self.make_branch_and_tree('.', format='development-colo')
1438
tree.controldir.create_branch(name="another-colocated-branch")
1439
converter = tree.controldir._format.get_converter(
1440
bzrdir.BzrDirMetaFormat1())
1441
result = converter.convert(tree.controldir, bzrdir.BzrDirMetaFormat1())
1442
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1444
def test_nested(self):
1445
tree = self.make_branch_and_tree('.', format='development-colo')
1446
tree.controldir.create_branch(name='foo')
1447
tree.controldir.create_branch(name='fool/bla')
1449
errors.ParentBranchExists, tree.controldir.create_branch,
1452
def test_parent(self):
1453
tree = self.make_branch_and_tree('.', format='development-colo')
1454
tree.controldir.create_branch(name='fool/bla')
1455
tree.controldir.create_branch(name='foo/bar')
1457
errors.AlreadyBranchError, tree.controldir.create_branch,
1461
class SampleBzrFormat(bzrdir.BzrFormat):
1464
def get_format_string(cls):
1465
return b"First line\n"
1468
class TestBzrFormat(TestCase):
1469
"""Tests for BzrFormat."""
1471
def test_as_string(self):
1472
format = SampleBzrFormat()
1473
format.features = {b"foo": b"required"}
1474
self.assertEqual(format.as_string(),
1477
format.features["another"] = "optional"
1478
self.assertEqual(format.as_string(),
1481
b"optional another\n")
1483
def test_network_name(self):
1484
# The network string should include the feature info
1485
format = SampleBzrFormat()
1486
format.features = {b"foo": b"required"}
1488
b"First line\nrequired foo\n",
1489
format.network_name())
1491
def test_from_string_no_features(self):
1493
format = SampleBzrFormat.from_string(
1495
self.assertEqual({}, format.features)
1497
def test_from_string_with_feature(self):
1499
format = SampleBzrFormat.from_string(
1500
b"First line\nrequired foo\n")
1501
self.assertEqual(b"required", format.features.get(b"foo"))
1503
def test_from_string_format_string_mismatch(self):
1504
# The first line has to match the format string
1505
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1506
b"Second line\nrequired foo\n")
1508
def test_from_string_missing_space(self):
1509
# At least one space is required in the feature lines
1510
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1511
b"First line\nfoo\n")
1513
def test_from_string_with_spaces(self):
1514
# Feature with spaces (in case we add stuff like this in the future)
1515
format = SampleBzrFormat.from_string(
1516
b"First line\nrequired foo with spaces\n")
1517
self.assertEqual(b"required", format.features.get(b"foo with spaces"))
1520
format1 = SampleBzrFormat()
1521
format1.features = {b"nested-trees": b"optional"}
1522
format2 = SampleBzrFormat()
1523
format2.features = {b"nested-trees": b"optional"}
1524
self.assertEqual(format1, format1)
1525
self.assertEqual(format1, format2)
1526
format3 = SampleBzrFormat()
1527
self.assertNotEqual(format1, format3)
1529
def test_check_support_status_optional(self):
1530
# Optional, so silently ignore
1531
format = SampleBzrFormat()
1532
format.features = {b"nested-trees": b"optional"}
1533
format.check_support_status(True)
1534
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1535
SampleBzrFormat.register_feature(b"nested-trees")
1536
format.check_support_status(True)
1538
def test_check_support_status_required(self):
1539
# Optional, so trigger an exception
1540
format = SampleBzrFormat()
1541
format.features = {b"nested-trees": b"required"}
1542
self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1544
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1545
SampleBzrFormat.register_feature(b"nested-trees")
1546
format.check_support_status(True)
1548
def test_check_support_status_unknown(self):
1549
# treat unknown necessity as required
1550
format = SampleBzrFormat()
1551
format.features = {b"nested-trees": b"unknown"}
1552
self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1554
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1555
SampleBzrFormat.register_feature(b"nested-trees")
1556
format.check_support_status(True)
1558
def test_feature_already_registered(self):
1559
# a feature can only be registered once
1560
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1561
SampleBzrFormat.register_feature(b"nested-trees")
1562
self.assertRaises(bzrdir.FeatureAlreadyRegistered,
1563
SampleBzrFormat.register_feature, b"nested-trees")
1565
def test_feature_with_space(self):
1566
# spaces are not allowed in feature names
1567
self.assertRaises(ValueError, SampleBzrFormat.register_feature,