442
442
self.assertEqual(parent_bzrdir.root_transport.base,
443
443
repo_policy._stack_on_pwd)
445
def prepare_default_stacking(self):
445
def prepare_default_stacking(self, child_format='development1'):
446
446
parent_bzrdir = self.make_bzrdir('.')
447
child_branch = self.make_branch('child', format='development1')
447
child_branch = self.make_branch('child', format=child_format)
448
448
parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
449
449
new_child_transport = parent_bzrdir.transport.clone('child2')
450
450
return child_branch, new_child_transport
461
461
self.assertEqual(child_branch.base,
462
462
new_child.open_branch().get_stacked_on_url())
464
def test_clone_ignores_policy_for_unsupported_formats(self):
465
child_branch, new_child_transport = self.prepare_default_stacking(
466
child_format='pack-0.92')
467
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
468
self.assertRaises(errors.UnstackableBranchFormat,
469
new_child.open_branch().get_stacked_on_url)
471
def test_sprout_ignores_policy_for_unsupported_formats(self):
472
child_branch, new_child_transport = self.prepare_default_stacking(
473
child_format='pack-0.92')
474
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
475
self.assertRaises(errors.UnstackableBranchFormat,
476
new_child.open_branch().get_stacked_on_url)
478
def test_sprout_upgrades_format_if_stacked_specified(self):
479
child_branch, new_child_transport = self.prepare_default_stacking(
480
child_format='pack-0.92')
481
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
483
self.assertEqual(child_branch.bzrdir.root_transport.base,
484
new_child.open_branch().get_stacked_on_url())
485
repo = new_child.open_repository()
486
self.assertTrue(repo._format.supports_external_lookups)
487
self.assertFalse(repo.supports_rich_root())
489
def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
490
child_branch, new_child_transport = self.prepare_default_stacking(
491
child_format='pack-0.92')
492
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
493
stacked_on=child_branch.bzrdir.root_transport.base)
494
self.assertEqual(child_branch.bzrdir.root_transport.base,
495
new_child.open_branch().get_stacked_on_url())
496
repo = new_child.open_repository()
497
self.assertTrue(repo._format.supports_external_lookups)
498
self.assertFalse(repo.supports_rich_root())
500
def test_sprout_upgrades_to_rich_root_format_if_needed(self):
501
child_branch, new_child_transport = self.prepare_default_stacking(
502
child_format='rich-root-pack')
503
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
505
repo = new_child.open_repository()
506
self.assertTrue(repo._format.supports_external_lookups)
507
self.assertTrue(repo.supports_rich_root())
464
509
def test_add_fallback_repo_handles_absolute_urls(self):
465
510
stack_on = self.make_branch('stack_on', format='development1')
466
511
repo = self.make_repository('repo', format='development1')
1149
1194
def __init__(self, *args, **kwargs):
1150
1195
super(_TestBranch, self).__init__(*args, **kwargs)
1151
1196
self.calls = []
1153
1199
def sprout(self, *args, **kwargs):
1154
1200
self.calls.append('sprout')
1201
return _TestBranch()
1203
def copy_content_into(self, destination, revision_id=None):
1204
self.calls.append('copy_content_into')
1206
def get_parent(self):
1209
def set_parent(self, parent):
1210
self._parent = parent
1157
1213
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1182
1238
result = source_bzrdir.sprout(target_url, recurse='no')
1184
1240
# The bzrdir called the branch's sprout method.
1185
self.assertEqual(['sprout'], source_bzrdir.test_branch.calls)
1241
self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
1243
def test_sprout_parent(self):
1244
grandparent_tree = self.make_branch('grandparent')
1245
parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1246
branch_tree = parent.bzrdir.sprout('branch').open_branch()
1247
self.assertContainsRe(branch_tree.get_parent(), '/parent/$')