536
480
# must not overwrite existing directories
537
481
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
538
482
transport=transport)
539
self.assertTrue(transport.has('.bzr'))
483
self.failUnless(transport.has('.bzr'))
540
484
self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
541
485
bd.retire_bzrdir, limit=0)
543
def test_get_branch_transport(self):
544
dir = self.make_bzrdir('.')
545
# without a format, get_branch_transport gives use a transport
546
# which -may- point to an existing dir.
547
self.assertTrue(isinstance(dir.get_branch_transport(None),
548
transport.Transport))
549
# with a given format, either the bzr dir supports identifiable
550
# branches, or it supports anonymous branch formats, but not both.
551
anonymous_format = AnonymousTestBranchFormat()
552
identifiable_format = IdentifiableTestBranchFormat()
554
found_transport = dir.get_branch_transport(anonymous_format)
555
self.assertRaises(errors.IncompatibleFormat,
556
dir.get_branch_transport,
558
except errors.IncompatibleFormat:
559
found_transport = dir.get_branch_transport(identifiable_format)
560
self.assertTrue(isinstance(found_transport, transport.Transport))
561
# and the dir which has been initialized for us must exist.
562
found_transport.list_dir('.')
564
def test_get_repository_transport(self):
565
dir = self.make_bzrdir('.')
566
# without a format, get_repository_transport gives use a transport
567
# which -may- point to an existing dir.
568
self.assertTrue(isinstance(dir.get_repository_transport(None),
569
transport.Transport))
570
# with a given format, either the bzr dir supports identifiable
571
# repositories, or it supports anonymous repository formats, but not both.
572
anonymous_format = AnonymousTestRepositoryFormat()
573
identifiable_format = IdentifiableTestRepositoryFormat()
575
found_transport = dir.get_repository_transport(anonymous_format)
576
self.assertRaises(errors.IncompatibleFormat,
577
dir.get_repository_transport,
579
except errors.IncompatibleFormat:
580
found_transport = dir.get_repository_transport(identifiable_format)
581
self.assertTrue(isinstance(found_transport, transport.Transport))
582
# and the dir which has been initialized for us must exist.
583
found_transport.list_dir('.')
585
def test_get_workingtree_transport(self):
586
dir = self.make_bzrdir('.')
587
# without a format, get_workingtree_transport gives use a transport
588
# which -may- point to an existing dir.
589
self.assertTrue(isinstance(dir.get_workingtree_transport(None),
590
transport.Transport))
591
# with a given format, either the bzr dir supports identifiable
592
# trees, or it supports anonymous tree formats, but not both.
593
anonymous_format = AnonymousTestWorkingTreeFormat()
594
identifiable_format = IdentifiableTestWorkingTreeFormat()
596
found_transport = dir.get_workingtree_transport(anonymous_format)
597
self.assertRaises(errors.IncompatibleFormat,
598
dir.get_workingtree_transport,
600
except errors.IncompatibleFormat:
601
found_transport = dir.get_workingtree_transport(identifiable_format)
602
self.assertTrue(isinstance(found_transport, transport.Transport))
603
# and the dir which has been initialized for us must exist.
604
found_transport.list_dir('.')
606
def assertInitializeEx(self, t, need_meta=False, **kwargs):
607
"""Execute initialize_on_transport_ex and check it succeeded correctly.
609
This involves checking that the disk objects were created, open with
610
the same format returned, and had the expected disk format.
612
:param t: The transport to initialize on.
613
:param **kwargs: Additional arguments to pass to
614
initialize_on_transport_ex.
615
:return: the resulting repo, control dir tuple.
617
if not self.bzrdir_format.is_initializable():
618
raise TestNotApplicable("control dir format is not "
620
repo, control, require_stacking, repo_policy = \
621
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
623
# Repositories are open write-locked
624
self.assertTrue(repo.is_write_locked())
625
self.addCleanup(repo.unlock)
626
self.assertIsInstance(control, bzrdir.BzrDir)
627
opened = bzrdir.BzrDir.open(t.base)
628
expected_format = self.bzrdir_format
629
if need_meta and expected_format.fixed_components:
630
# Pre-metadir formats change when we are making something that
631
# needs a metaformat, because clone is used for push.
632
expected_format = bzrdir.BzrDirMetaFormat1()
633
if not isinstance(expected_format, RemoteBzrDirFormat):
634
self.assertEqual(control._format.network_name(),
635
expected_format.network_name())
636
self.assertEqual(control._format.network_name(),
637
opened._format.network_name())
638
self.assertEqual(control.__class__, opened.__class__)
641
def test_format_initialize_on_transport_ex_default_stack_on(self):
642
# When initialize_on_transport_ex uses a stacked-on branch because of
643
# a stacking policy on the target, the location of the fallback
644
# repository is the same as the external location of the stacked-on
646
balloon = self.make_bzrdir('balloon')
647
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
648
stack_on = self.make_branch('stack-on', format='1.9')
650
stack_on = self.make_branch('stack-on')
651
if not stack_on.repository._format.supports_nesting_repositories:
652
raise TestNotApplicable("requires nesting repositories")
653
config = self.make_bzrdir('.').get_config()
655
config.set_default_stack_on('stack-on')
656
except errors.BzrError:
657
raise TestNotApplicable('Only relevant for stackable formats.')
658
# Initialize a bzrdir subject to the policy.
659
t = self.get_transport('stacked')
660
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
661
repo_name = repo_fmt.repository_format.network_name()
662
repo, control = self.assertInitializeEx(
663
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
664
# self.addCleanup(repo.unlock)
665
# There's one fallback repo, with a public location.
666
self.assertLength(1, repo._fallback_repositories)
667
fallback_repo = repo._fallback_repositories[0]
669
stack_on.base, fallback_repo.bzrdir.root_transport.base)
670
# The bzrdir creates a branch in stacking-capable format.
671
new_branch = control.create_branch()
672
self.assertTrue(new_branch._format.supports_stacking())
674
def test_no_leftover_dirs(self):
675
# bug 886196: development-colo uses a branch-lock directory
676
# in the user directory rather than the control directory.
677
if not self.bzrdir_format.colocated_branches:
678
raise TestNotApplicable(
679
"format does not support colocated branches")
680
branch = self.make_branch('.', format='development-colo')
681
branch.bzrdir.create_branch(name="another-colocated-branch")
683
branch.bzrdir.user_transport.list_dir("."),
686
def test_get_branches(self):
687
repo = self.make_repository('branch-1')
688
if not repo.bzrdir._format.colocated_branches:
689
raise TestNotApplicable('Format does not support colocation')
690
target_branch = repo.bzrdir.create_branch(name='foo')
691
repo.bzrdir.set_branch_reference(target_branch)
692
self.assertEqual(set(["", 'foo']),
693
set(repo.bzrdir.get_branches().keys()))