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_sprout_upgrades_to_rich_root_format_if_needed(self):
490
child_branch, new_child_transport = self.prepare_default_stacking(
491
child_format='rich-root-pack')
494
return child_branch.bzrdir.sprout(new_child_transport.base,
496
except errors.IncompatibleRepositories:
497
raise AssertionError(
498
'Rich root format should be sprout-compatible')
499
self.expectFailure('Rich root format should be sprout-compatible',
501
repo = new_child.open_repository()
502
self.assertTrue(repo._format.supports_external_lookups)
503
self.assertTrue(repo.supports_rich_root())
462
505
def test_add_fallback_repo_handles_absolute_urls(self):
463
506
stack_on = self.make_branch('stack_on', format='development1')
464
507
repo = self.make_repository('repo', format='development1')
531
574
self.assertEqual(os.path.realpath('topdir'),
532
575
self.local_branch_path(branch))
533
576
self.assertEqual(
534
os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
577
osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
535
578
repo.bzrdir.transport.local_abspath('repository'))
536
579
self.assertEqual(relpath, 'foo')
544
587
self.assertEqual(os.path.realpath('branch'),
545
588
self.local_branch_path(branch))
546
589
self.assertEqual(
547
os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
590
osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
548
591
repo.bzrdir.transport.local_abspath('repository'))
549
592
self.assertEqual(relpath, 'foo')
556
599
self.assertEqual(tree, None)
557
600
self.assertEqual(branch, None)
558
601
self.assertEqual(
559
os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
602
osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
560
603
repo.bzrdir.transport.local_abspath('repository'))
561
604
self.assertEqual(relpath, '')
571
614
self.assertEqual(os.path.realpath('shared/branch'),
572
615
self.local_branch_path(branch))
573
616
self.assertEqual(
574
os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
617
osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
575
618
repo.bzrdir.transport.local_abspath('repository'))
576
619
self.assertEqual(relpath, '')
586
629
self.assertEqual(os.path.realpath('foo'),
587
630
self.local_branch_path(branch))
588
631
self.assertEqual(
589
os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
632
osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
590
633
repo.bzrdir.transport.local_abspath('repository'))
591
634
self.assertEqual(relpath, 'bar')
599
642
self.assertEqual(tree, None)
600
643
self.assertEqual(branch, None)
601
644
self.assertEqual(
602
os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
645
osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
603
646
repo.bzrdir.transport.local_abspath('repository'))
604
647
self.assertEqual(relpath, 'baz')
1113
1156
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1114
1157
self.build_tree(['a'])
1115
1158
self.assertEquals(['a'], self.get_ls())
1161
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1162
"""Test BzrDirFormat implementation for TestBzrDirSprout."""
1164
def _open(self, transport):
1165
return _TestBzrDir(transport, self)
1168
class _TestBzrDir(bzrdir.BzrDirMeta1):
1169
"""Test BzrDir implementation for TestBzrDirSprout.
1171
When created a _TestBzrDir already has repository and a branch. The branch
1172
is a test double as well.
1175
def __init__(self, *args, **kwargs):
1176
super(_TestBzrDir, self).__init__(*args, **kwargs)
1177
self.test_branch = _TestBranch()
1178
self.test_branch.repository = self.create_repository()
1180
def open_branch(self, unsupported=False):
1181
return self.test_branch
1183
def cloning_metadir(self, require_stacking=False):
1184
return _TestBzrDirFormat()
1187
class _TestBranch(bzrlib.branch.Branch):
1188
"""Test Branch implementation for TestBzrDirSprout."""
1190
def __init__(self, *args, **kwargs):
1191
super(_TestBranch, self).__init__(*args, **kwargs)
1195
def sprout(self, *args, **kwargs):
1196
self.calls.append('sprout')
1197
return _TestBranch()
1199
def copy_content_into(self, destination, revision_id=None):
1200
self.calls.append('copy_content_into')
1202
def get_parent(self):
1205
def set_parent(self, parent):
1206
self._parent = parent
1209
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1211
def test_sprout_uses_branch_sprout(self):
1212
"""BzrDir.sprout calls Branch.sprout.
1214
Usually, BzrDir.sprout should delegate to the branch's sprout method
1215
for part of the work. This allows the source branch to control the
1216
choice of format for the new branch.
1218
There are exceptions, but this tests avoids them:
1219
- if there's no branch in the source bzrdir,
1220
- or if the stacking has been requested and the format needs to be
1221
overridden to satisfy that.
1223
# Make an instrumented bzrdir.
1224
t = self.get_transport('source')
1226
source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1227
# The instrumented bzrdir has a test_branch attribute that logs calls
1228
# made to the branch contained in that bzrdir. Initially the test
1229
# branch exists but no calls have been made to it.
1230
self.assertEqual([], source_bzrdir.test_branch.calls)
1233
target_url = self.get_url('target')
1234
result = source_bzrdir.sprout(target_url, recurse='no')
1236
# The bzrdir called the branch's sprout method.
1237
self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
1239
def test_sprout_parent(self):
1240
grandparent_tree = self.make_branch('grandparent')
1241
parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1242
branch_tree = parent.bzrdir.sprout('branch').open_branch()
1243
self.assertContainsRe(branch_tree.get_parent(), '/parent/$')