597
600
self.assertTrue(isinstance(found_transport, transport.Transport))
598
601
# and the dir which has been initialized for us must exist.
599
602
found_transport.list_dir('.')
604
def assertInitializeEx(self, t, need_meta=False, **kwargs):
605
"""Execute initialize_on_transport_ex and check it succeeded correctly.
607
This involves checking that the disk objects were created, open with
608
the same format returned, and had the expected disk format.
610
:param t: The transport to initialize on.
611
:param **kwargs: Additional arguments to pass to
612
initialize_on_transport_ex.
613
:return: the resulting repo, control dir tuple.
615
if not self.bzrdir_format.is_initializable():
616
raise TestNotApplicable("control dir format is not "
618
repo, control, require_stacking, repo_policy = \
619
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
621
# Repositories are open write-locked
622
self.assertTrue(repo.is_write_locked())
623
self.addCleanup(repo.unlock)
624
self.assertIsInstance(control, bzrdir.BzrDir)
625
opened = bzrdir.BzrDir.open(t.base)
626
expected_format = self.bzrdir_format
627
if need_meta and expected_format.fixed_components:
628
# Pre-metadir formats change when we are making something that
629
# needs a metaformat, because clone is used for push.
630
expected_format = bzrdir.BzrDirMetaFormat1()
631
if not isinstance(expected_format, RemoteBzrDirFormat):
632
self.assertEqual(control._format.network_name(),
633
expected_format.network_name())
634
self.assertEqual(control._format.network_name(),
635
opened._format.network_name())
636
self.assertEqual(control.__class__, opened.__class__)
639
def test_format_initialize_on_transport_ex_default_stack_on(self):
640
# When initialize_on_transport_ex uses a stacked-on branch because of
641
# a stacking policy on the target, the location of the fallback
642
# repository is the same as the external location of the stacked-on
644
balloon = self.make_bzrdir('balloon')
645
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
646
stack_on = self.make_branch('stack-on', format='1.9')
648
stack_on = self.make_branch('stack-on')
649
if not stack_on.repository._format.supports_nesting_repositories:
650
raise TestNotApplicable("requires nesting repositories")
651
config = self.make_bzrdir('.').get_config()
653
config.set_default_stack_on('stack-on')
654
except errors.BzrError:
655
raise TestNotApplicable('Only relevant for stackable formats.')
656
# Initialize a bzrdir subject to the policy.
657
t = self.get_transport('stacked')
658
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
659
repo_name = repo_fmt.repository_format.network_name()
660
repo, control = self.assertInitializeEx(
661
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
662
# self.addCleanup(repo.unlock)
663
# There's one fallback repo, with a public location.
664
self.assertLength(1, repo._fallback_repositories)
665
fallback_repo = repo._fallback_repositories[0]
667
stack_on.base, fallback_repo.bzrdir.root_transport.base)
668
# The bzrdir creates a branch in stacking-capable format.
669
new_branch = control.create_branch()
670
self.assertTrue(new_branch._format.supports_stacking())