440
442
self.assertEqual(parent_bzrdir.root_transport.base,
441
443
repo_policy._stack_on_pwd)
443
def prepare_default_stacking(self):
445
def prepare_default_stacking(self, child_format='development1'):
444
446
parent_bzrdir = self.make_bzrdir('.')
445
child_branch = self.make_branch('child', format='development1')
447
child_branch = self.make_branch('child', format=child_format)
446
448
parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
447
449
new_child_transport = parent_bzrdir.transport.clone('child2')
448
450
return child_branch, new_child_transport
459
461
self.assertEqual(child_branch.base,
460
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())
462
509
def test_add_fallback_repo_handles_absolute_urls(self):
463
510
stack_on = self.make_branch('stack_on', format='development1')
464
511
repo = self.make_repository('repo', format='development1')
531
578
self.assertEqual(os.path.realpath('topdir'),
532
579
self.local_branch_path(branch))
533
580
self.assertEqual(
534
os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
581
osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
535
582
repo.bzrdir.transport.local_abspath('repository'))
536
583
self.assertEqual(relpath, 'foo')
544
591
self.assertEqual(os.path.realpath('branch'),
545
592
self.local_branch_path(branch))
546
593
self.assertEqual(
547
os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
594
osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
548
595
repo.bzrdir.transport.local_abspath('repository'))
549
596
self.assertEqual(relpath, 'foo')
556
603
self.assertEqual(tree, None)
557
604
self.assertEqual(branch, None)
558
605
self.assertEqual(
559
os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
606
osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
560
607
repo.bzrdir.transport.local_abspath('repository'))
561
608
self.assertEqual(relpath, '')
571
618
self.assertEqual(os.path.realpath('shared/branch'),
572
619
self.local_branch_path(branch))
573
620
self.assertEqual(
574
os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
621
osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
575
622
repo.bzrdir.transport.local_abspath('repository'))
576
623
self.assertEqual(relpath, '')
586
633
self.assertEqual(os.path.realpath('foo'),
587
634
self.local_branch_path(branch))
588
635
self.assertEqual(
589
os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
636
osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
590
637
repo.bzrdir.transport.local_abspath('repository'))
591
638
self.assertEqual(relpath, 'bar')
599
646
self.assertEqual(tree, None)
600
647
self.assertEqual(branch, None)
601
648
self.assertEqual(
602
os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
649
osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
603
650
repo.bzrdir.transport.local_abspath('repository'))
604
651
self.assertEqual(relpath, 'baz')
1113
1160
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1114
1161
self.build_tree(['a'])
1115
1162
self.assertEquals(['a'], self.get_ls())
1165
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1166
"""Test BzrDirFormat implementation for TestBzrDirSprout."""
1168
def _open(self, transport):
1169
return _TestBzrDir(transport, self)
1172
class _TestBzrDir(bzrdir.BzrDirMeta1):
1173
"""Test BzrDir implementation for TestBzrDirSprout.
1175
When created a _TestBzrDir already has repository and a branch. The branch
1176
is a test double as well.
1179
def __init__(self, *args, **kwargs):
1180
super(_TestBzrDir, self).__init__(*args, **kwargs)
1181
self.test_branch = _TestBranch()
1182
self.test_branch.repository = self.create_repository()
1184
def open_branch(self, unsupported=False):
1185
return self.test_branch
1187
def cloning_metadir(self, require_stacking=False):
1188
return _TestBzrDirFormat()
1191
class _TestBranch(bzrlib.branch.Branch):
1192
"""Test Branch implementation for TestBzrDirSprout."""
1194
def __init__(self, *args, **kwargs):
1195
super(_TestBranch, self).__init__(*args, **kwargs)
1199
def sprout(self, *args, **kwargs):
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
1213
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1215
def test_sprout_uses_branch_sprout(self):
1216
"""BzrDir.sprout calls Branch.sprout.
1218
Usually, BzrDir.sprout should delegate to the branch's sprout method
1219
for part of the work. This allows the source branch to control the
1220
choice of format for the new branch.
1222
There are exceptions, but this tests avoids them:
1223
- if there's no branch in the source bzrdir,
1224
- or if the stacking has been requested and the format needs to be
1225
overridden to satisfy that.
1227
# Make an instrumented bzrdir.
1228
t = self.get_transport('source')
1230
source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1231
# The instrumented bzrdir has a test_branch attribute that logs calls
1232
# made to the branch contained in that bzrdir. Initially the test
1233
# branch exists but no calls have been made to it.
1234
self.assertEqual([], source_bzrdir.test_branch.calls)
1237
target_url = self.get_url('target')
1238
result = source_bzrdir.sprout(target_url, recurse='no')
1240
# The bzrdir called the branch's sprout method.
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/$')