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