159
163
for file_id, revision_id in text_index.iterkeys():
160
164
desired_files.append(
161
165
(file_id, revision_id, (file_id, revision_id)))
162
left_texts = list(left_repo.iter_files_bytes(desired_files))
163
right_texts = list(right_repo.iter_files_bytes(desired_files))
166
left_texts = [(identifier, "".join(bytes_iterator)) for
167
(identifier, bytes_iterator) in
168
left_repo.iter_files_bytes(desired_files)]
169
right_texts = [(identifier, "".join(bytes_iterator)) for
170
(identifier, bytes_iterator) in
171
right_repo.iter_files_bytes(desired_files)]
164
172
left_texts.sort()
165
173
right_texts.sort()
166
174
self.assertEqual(left_texts, right_texts)
597
604
self.assertTrue(isinstance(found_transport, transport.Transport))
598
605
# and the dir which has been initialized for us must exist.
599
606
found_transport.list_dir('.')
608
def assertInitializeEx(self, t, need_meta=False, **kwargs):
609
"""Execute initialize_on_transport_ex and check it succeeded correctly.
611
This involves checking that the disk objects were created, open with
612
the same format returned, and had the expected disk format.
614
:param t: The transport to initialize on.
615
:param **kwargs: Additional arguments to pass to
616
initialize_on_transport_ex.
617
:return: the resulting repo, control dir tuple.
619
if not self.bzrdir_format.is_initializable():
620
raise TestNotApplicable("control dir format is not "
622
repo, control, require_stacking, repo_policy = \
623
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
625
# Repositories are open write-locked
626
self.assertTrue(repo.is_write_locked())
627
self.addCleanup(repo.unlock)
628
self.assertIsInstance(control, bzrdir.BzrDir)
629
opened = bzrdir.BzrDir.open(t.base)
630
expected_format = self.bzrdir_format
631
if need_meta and expected_format.fixed_components:
632
# Pre-metadir formats change when we are making something that
633
# needs a metaformat, because clone is used for push.
634
expected_format = bzrdir.BzrDirMetaFormat1()
635
if not isinstance(expected_format, RemoteBzrDirFormat):
636
self.assertEqual(control._format.network_name(),
637
expected_format.network_name())
638
self.assertEqual(control._format.network_name(),
639
opened._format.network_name())
640
self.assertEqual(control.__class__, opened.__class__)
643
def test_format_initialize_on_transport_ex_default_stack_on(self):
644
# When initialize_on_transport_ex uses a stacked-on branch because of
645
# a stacking policy on the target, the location of the fallback
646
# repository is the same as the external location of the stacked-on
648
balloon = self.make_bzrdir('balloon')
649
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
650
stack_on = self.make_branch('stack-on', format='1.9')
652
stack_on = self.make_branch('stack-on')
653
if not stack_on.repository._format.supports_nesting_repositories:
654
raise TestNotApplicable("requires nesting repositories")
655
config = self.make_bzrdir('.').get_config()
657
config.set_default_stack_on('stack-on')
658
except errors.BzrError:
659
raise TestNotApplicable('Only relevant for stackable formats.')
660
# Initialize a bzrdir subject to the policy.
661
t = self.get_transport('stacked')
662
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
663
repo_name = repo_fmt.repository_format.network_name()
664
repo, control = self.assertInitializeEx(
665
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
666
# self.addCleanup(repo.unlock)
667
# There's one fallback repo, with a public location.
668
self.assertLength(1, repo._fallback_repositories)
669
fallback_repo = repo._fallback_repositories[0]
671
stack_on.base, fallback_repo.bzrdir.root_transport.base)
672
# The bzrdir creates a branch in stacking-capable format.
673
new_branch = control.create_branch()
674
self.assertTrue(new_branch._format.supports_stacking())
676
def test_no_leftover_dirs(self):
677
# bug 886196: development-colo uses a branch-lock directory
678
# in the user directory rather than the control directory.
679
if not self.bzrdir_format.colocated_branches:
680
raise TestNotApplicable(
681
"format does not support colocated branches")
682
branch = self.make_branch('.', format='development-colo')
683
branch.bzrdir.create_branch(name="another-colocated-branch")
685
branch.bzrdir.user_transport.list_dir("."),
688
def test_get_branches(self):
689
repo = self.make_repository('branch-1')
691
target_branch = repo.bzrdir.create_branch(name='foo')
692
except errors.NoColocatedBranchSupport:
693
raise TestNotApplicable('Format does not support colocation')
694
reference = branch.BranchReferenceFormat().initialize(
695
repo.bzrdir, target_branch=target_branch)
696
self.assertEqual(set([None, 'foo']),
697
set(repo.bzrdir.get_branches().keys()))