423
424
self.assertFalse(repo.is_shared())
427
def test_determine_stacking_policy(self):
428
parent_bzrdir = self.make_bzrdir('.')
429
child_bzrdir = self.make_bzrdir('child')
430
parent_bzrdir.get_config().set_default_stack_on('http://example.org')
431
repo_policy = child_bzrdir.determine_repository_policy()
432
self.assertEqual('http://example.org', repo_policy._stack_on)
434
def test_determine_stacking_policy_relative(self):
435
parent_bzrdir = self.make_bzrdir('.')
436
child_bzrdir = self.make_bzrdir('child')
437
parent_bzrdir.get_config().set_default_stack_on('child2')
438
repo_policy = child_bzrdir.determine_repository_policy()
439
self.assertEqual('child2', repo_policy._stack_on)
440
self.assertEqual(parent_bzrdir.root_transport.base,
441
repo_policy._stack_on_pwd)
443
def prepare_default_stacking(self):
444
parent_bzrdir = self.make_bzrdir('.')
445
child_branch = self.make_branch('child', format='development1')
446
parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
447
new_child_transport = parent_bzrdir.transport.clone('child2')
448
return child_branch, new_child_transport
450
def test_clone_on_transport_obeys_stacking_policy(self):
451
child_branch, new_child_transport = self.prepare_default_stacking()
452
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
453
self.assertEqual(child_branch.base,
454
new_child.open_branch().get_stacked_on_url())
456
def test_sprout_obeys_stacking_policy(self):
457
child_branch, new_child_transport = self.prepare_default_stacking()
458
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
459
self.assertEqual(child_branch.base,
460
new_child.open_branch().get_stacked_on_url())
462
def test_add_fallback_repo_handles_absolute_urls(self):
463
stack_on = self.make_branch('stack_on', format='development1')
464
repo = self.make_repository('repo', format='development1')
465
policy = bzrdir.UseExistingRepository(repo, stack_on.base)
466
policy._add_fallback(repo)
468
def test_add_fallback_repo_handles_relative_urls(self):
469
stack_on = self.make_branch('stack_on', format='development1')
470
repo = self.make_repository('repo', format='development1')
471
policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
472
policy._add_fallback(repo)
474
def test_configure_relative_branch_stacking_url(self):
475
stack_on = self.make_branch('stack_on', format='development1')
476
stacked = self.make_branch('stack_on/stacked', format='development1')
477
policy = bzrdir.UseExistingRepository(stacked.repository,
479
policy.configure_branch(stacked)
480
self.assertEqual('..', stacked.get_stacked_on_url())
482
def test_relative_branch_stacking_to_absolute(self):
483
stack_on = self.make_branch('stack_on', format='development1')
484
stacked = self.make_branch('stack_on/stacked', format='development1')
485
policy = bzrdir.UseExistingRepository(stacked.repository,
486
'.', self.get_readonly_url('stack_on'))
487
policy.configure_branch(stacked)
488
self.assertEqual(self.get_readonly_url('stack_on'),
489
stacked.get_stacked_on_url())
426
492
class ChrootedTests(TestCaseWithTransport):
427
493
"""A support class that provides readonly urls outside the local namespace.
447
516
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
448
517
self.assertEqual('g/p/q', relpath)
519
def test_open_containing_tree_branch_or_repository_empty(self):
520
self.assertRaises(errors.NotBranchError,
521
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
522
self.get_readonly_url(''))
524
def test_open_containing_tree_branch_or_repository_all(self):
525
self.make_branch_and_tree('topdir')
526
tree, branch, repo, relpath = \
527
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
529
self.assertEqual(os.path.realpath('topdir'),
530
os.path.realpath(tree.basedir))
531
self.assertEqual(os.path.realpath('topdir'),
532
self.local_branch_path(branch))
534
os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
535
repo.bzrdir.transport.local_abspath('repository'))
536
self.assertEqual(relpath, 'foo')
538
def test_open_containing_tree_branch_or_repository_no_tree(self):
539
self.make_branch('branch')
540
tree, branch, repo, relpath = \
541
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
543
self.assertEqual(tree, None)
544
self.assertEqual(os.path.realpath('branch'),
545
self.local_branch_path(branch))
547
os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
548
repo.bzrdir.transport.local_abspath('repository'))
549
self.assertEqual(relpath, 'foo')
551
def test_open_containing_tree_branch_or_repository_repo(self):
552
self.make_repository('repo')
553
tree, branch, repo, relpath = \
554
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
556
self.assertEqual(tree, None)
557
self.assertEqual(branch, None)
559
os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
560
repo.bzrdir.transport.local_abspath('repository'))
561
self.assertEqual(relpath, '')
563
def test_open_containing_tree_branch_or_repository_shared_repo(self):
564
self.make_repository('shared', shared=True)
565
bzrdir.BzrDir.create_branch_convenience('shared/branch',
566
force_new_tree=False)
567
tree, branch, repo, relpath = \
568
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
570
self.assertEqual(tree, None)
571
self.assertEqual(os.path.realpath('shared/branch'),
572
self.local_branch_path(branch))
574
os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
575
repo.bzrdir.transport.local_abspath('repository'))
576
self.assertEqual(relpath, '')
578
def test_open_containing_tree_branch_or_repository_branch_subdir(self):
579
self.make_branch_and_tree('foo')
580
self.build_tree(['foo/bar/'])
581
tree, branch, repo, relpath = \
582
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
584
self.assertEqual(os.path.realpath('foo'),
585
os.path.realpath(tree.basedir))
586
self.assertEqual(os.path.realpath('foo'),
587
self.local_branch_path(branch))
589
os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
590
repo.bzrdir.transport.local_abspath('repository'))
591
self.assertEqual(relpath, 'bar')
593
def test_open_containing_tree_branch_or_repository_repo_subdir(self):
594
self.make_repository('bar')
595
self.build_tree(['bar/baz/'])
596
tree, branch, repo, relpath = \
597
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
599
self.assertEqual(tree, None)
600
self.assertEqual(branch, None)
602
os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
603
repo.bzrdir.transport.local_abspath('repository'))
604
self.assertEqual(relpath, 'baz')
450
606
def test_open_containing_from_transport(self):
451
607
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
452
608
get_transport(self.get_readonly_url('')))
461
617
self.assertEqual('g/p/q', relpath)
463
619
def test_open_containing_tree_or_branch(self):
464
def local_branch_path(branch):
465
return os.path.realpath(
466
urlutils.local_path_from_url(branch.base))
468
620
self.make_branch_and_tree('topdir')
469
621
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
471
623
self.assertEqual(os.path.realpath('topdir'),
472
624
os.path.realpath(tree.basedir))
473
625
self.assertEqual(os.path.realpath('topdir'),
474
local_branch_path(branch))
626
self.local_branch_path(branch))
475
627
self.assertIs(tree.bzrdir, branch.bzrdir)
476
628
self.assertEqual('foo', relpath)
477
629
# opening from non-local should not return the tree
486
638
self.assertIs(tree, None)
487
639
self.assertEqual(os.path.realpath('topdir/foo'),
488
local_branch_path(branch))
640
self.local_branch_path(branch))
489
641
self.assertEqual('', relpath)
491
643
def test_open_tree_or_branch(self):
492
def local_branch_path(branch):
493
return os.path.realpath(
494
urlutils.local_path_from_url(branch.base))
496
644
self.make_branch_and_tree('topdir')
497
645
tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
498
646
self.assertEqual(os.path.realpath('topdir'),
499
647
os.path.realpath(tree.basedir))
500
648
self.assertEqual(os.path.realpath('topdir'),
501
local_branch_path(branch))
649
self.local_branch_path(branch))
502
650
self.assertIs(tree.bzrdir, branch.bzrdir)
503
651
# opening from non-local should not return the tree
504
652
tree, branch = bzrdir.BzrDir.open_tree_or_branch(