66
64
old_format = bzrdir.BzrDirFormat.get_default_format()
67
65
# default is BzrDirFormat6
68
66
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
69
self.applyDeprecated(symbol_versioning.zero_fourteen,
70
bzrdir.BzrDirFormat.set_default_format,
67
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
72
68
# creating a bzr dir should now create an instrumented dir.
74
70
result = bzrdir.BzrDir.create('memory:///')
75
71
self.failUnless(isinstance(result, SampleBzrDir))
77
self.applyDeprecated(symbol_versioning.zero_fourteen,
78
bzrdir.BzrDirFormat.set_default_format, old_format)
73
bzrdir.BzrDirFormat._set_default_format(old_format)
79
74
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
281
276
# now open_downlevel should fail too.
282
277
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
284
def test_create_repository_deprecated(self):
285
# new interface is to make the bzrdir, then a repository within that.
286
format = SampleBzrDirFormat()
287
repo = self.applyDeprecated(zero_ninetyone,
288
bzrdir.BzrDir.create_repository,
289
self.get_url(), format=format)
290
self.assertEqual('A repository', repo)
292
def test_create_repository_shared(self):
293
# new interface is to make the bzrdir, then a repository within that.
294
old_format = bzrdir.BzrDirFormat.get_default_format()
295
repo = self.applyDeprecated(zero_ninetyone,
296
bzrdir.BzrDir.create_repository,
298
self.assertTrue(repo.is_shared())
300
def test_create_repository_nonshared(self):
301
# new interface is to make the bzrdir, then a repository within that.
302
old_format = bzrdir.BzrDirFormat.get_default_format()
303
repo = self.applyDeprecated(zero_ninetyone,
304
bzrdir.BzrDir.create_repository,
306
self.assertFalse(repo.is_shared())
308
def test_create_repository_under_shared(self):
309
# an explicit create_repository always does so.
310
# we trust the format is right from the 'create_repository test'
311
# new interface is to make the bzrdir, then a repository within that.
312
format = bzrdir.format_registry.make_bzrdir('knit')
313
self.make_repository('.', shared=True, format=format)
314
repo = self.applyDeprecated(zero_ninetyone,
315
bzrdir.BzrDir.create_repository,
316
self.get_url('child'),
318
self.assertTrue(isinstance(repo, repository.Repository))
319
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
321
279
def test_create_branch_and_repo_uses_default(self):
322
280
format = SampleBzrDirFormat()
323
281
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
478
451
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
479
452
self.assertEqual('g/p/q', relpath)
454
def test_open_containing_tree_branch_or_repository_empty(self):
455
self.assertRaises(errors.NotBranchError,
456
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
457
self.get_readonly_url(''))
459
def test_open_containing_tree_branch_or_repository_all(self):
460
self.make_branch_and_tree('topdir')
461
tree, branch, repo, relpath = \
462
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
464
self.assertEqual(os.path.realpath('topdir'),
465
os.path.realpath(tree.basedir))
466
self.assertEqual(os.path.realpath('topdir'),
467
self.local_branch_path(branch))
469
os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
470
repo.bzrdir.transport.local_abspath('repository'))
471
self.assertEqual(relpath, 'foo')
473
def test_open_containing_tree_branch_or_repository_no_tree(self):
474
self.make_branch('branch')
475
tree, branch, repo, relpath = \
476
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
478
self.assertEqual(tree, None)
479
self.assertEqual(os.path.realpath('branch'),
480
self.local_branch_path(branch))
482
os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
483
repo.bzrdir.transport.local_abspath('repository'))
484
self.assertEqual(relpath, 'foo')
486
def test_open_containing_tree_branch_or_repository_repo(self):
487
self.make_repository('repo')
488
tree, branch, repo, relpath = \
489
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
491
self.assertEqual(tree, None)
492
self.assertEqual(branch, None)
494
os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
495
repo.bzrdir.transport.local_abspath('repository'))
496
self.assertEqual(relpath, '')
498
def test_open_containing_tree_branch_or_repository_shared_repo(self):
499
self.make_repository('shared', shared=True)
500
bzrdir.BzrDir.create_branch_convenience('shared/branch',
501
force_new_tree=False)
502
tree, branch, repo, relpath = \
503
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
505
self.assertEqual(tree, None)
506
self.assertEqual(os.path.realpath('shared/branch'),
507
self.local_branch_path(branch))
509
os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
510
repo.bzrdir.transport.local_abspath('repository'))
511
self.assertEqual(relpath, '')
513
def test_open_containing_tree_branch_or_repository_branch_subdir(self):
514
self.make_branch_and_tree('foo')
515
self.build_tree(['foo/bar/'])
516
tree, branch, repo, relpath = \
517
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
519
self.assertEqual(os.path.realpath('foo'),
520
os.path.realpath(tree.basedir))
521
self.assertEqual(os.path.realpath('foo'),
522
self.local_branch_path(branch))
524
os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
525
repo.bzrdir.transport.local_abspath('repository'))
526
self.assertEqual(relpath, 'bar')
528
def test_open_containing_tree_branch_or_repository_repo_subdir(self):
529
self.make_repository('bar')
530
self.build_tree(['bar/baz/'])
531
tree, branch, repo, relpath = \
532
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
534
self.assertEqual(tree, None)
535
self.assertEqual(branch, None)
537
os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
538
repo.bzrdir.transport.local_abspath('repository'))
539
self.assertEqual(relpath, 'baz')
481
541
def test_open_containing_from_transport(self):
482
542
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
483
543
get_transport(self.get_readonly_url('')))
492
552
self.assertEqual('g/p/q', relpath)
494
554
def test_open_containing_tree_or_branch(self):
495
def local_branch_path(branch):
496
return os.path.realpath(
497
urlutils.local_path_from_url(branch.base))
499
555
self.make_branch_and_tree('topdir')
500
556
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
502
558
self.assertEqual(os.path.realpath('topdir'),
503
559
os.path.realpath(tree.basedir))
504
560
self.assertEqual(os.path.realpath('topdir'),
505
local_branch_path(branch))
561
self.local_branch_path(branch))
506
562
self.assertIs(tree.bzrdir, branch.bzrdir)
507
563
self.assertEqual('foo', relpath)
508
564
# opening from non-local should not return the tree
517
573
self.assertIs(tree, None)
518
574
self.assertEqual(os.path.realpath('topdir/foo'),
519
local_branch_path(branch))
575
self.local_branch_path(branch))
520
576
self.assertEqual('', relpath)
522
578
def test_open_tree_or_branch(self):
523
def local_branch_path(branch):
524
return os.path.realpath(
525
urlutils.local_path_from_url(branch.base))
527
579
self.make_branch_and_tree('topdir')
528
580
tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
529
581
self.assertEqual(os.path.realpath('topdir'),
530
582
os.path.realpath(tree.basedir))
531
583
self.assertEqual(os.path.realpath('topdir'),
532
local_branch_path(branch))
584
self.local_branch_path(branch))
533
585
self.assertIs(tree.bzrdir, branch.bzrdir)
534
586
# opening from non-local should not return the tree
535
587
tree, branch = bzrdir.BzrDir.open_tree_or_branch(