559
567
branch.BranchFormat.find_format(opened_control))
561
569
def test_find_repository_no_repo_under_standalone_branch(self):
562
# branch formats that support shared storage need to find their
563
# repository using the defined search order:
564
# * the branch's bzrdir
565
# * every containing bzrdir until the root or a non shared repo is
567
parent_bzrdir = self.make_branch('.')
570
# finding a repo stops at standalone branches even if there is a
571
# higher repository available.
573
repo = self.make_repository('.', shared=True)
574
except errors.IncompatibleFormat:
575
# need a shared repository to test this.
577
url = self.get_url('intermediate')
578
get_transport(self.get_url()).mkdir('intermediate')
579
get_transport(self.get_url()).mkdir('intermediate/child')
580
made_control = self.bzrdir_format.initialize(url)
581
made_control.create_repository()
582
innermost_control = self.bzrdir_format.initialize(
583
self.get_url('intermediate/child'))
585
child_repo = innermost_control.open_repository()
586
# if there is a repository, then the format cannot ever hit this
589
except errors.NoRepositoryPresent:
591
self.assertRaises(errors.NoRepositoryPresent,
592
self.branch_format.find_repository,
595
def test_find_repository_containing_shared_repository(self):
596
# find repo inside a shared repo with an empty control dir
597
# returns the shared repo.
599
repo = self.make_repository('.', shared=True)
600
except errors.IncompatibleFormat:
601
# need a shared repository to test this.
568
603
url = self.get_url('childbzrdir')
569
604
get_transport(self.get_url()).mkdir('childbzrdir')
570
605
made_control = self.bzrdir_format.initialize(url)
571
self.assertRaises(errors.NoRepositoryPresent,
572
self.branch_format.find_repository,
607
child_repo = made_control.open_repository()
608
# if there is a repository, then the format cannot ever hit this
611
except errors.NoRepositoryPresent:
613
found_repo = self.branch_format.find_repository(made_control)
614
self.assertEqual(repo.bzrdir.root_transport.base,
615
found_repo.bzrdir.root_transport.base)
617
def test_find_repository_standalone_with_containing_shared_repository(self):
618
# find repo inside a standalone repo inside a shared repo finds the standalone repo
620
containing_repo = self.make_repository('.', shared=True)
621
except errors.IncompatibleFormat:
622
# need a shared repository to test this.
624
child_repo = self.make_repository('childrepo')
625
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
626
found_repo = self.branch_format.find_repository(opened_control)
627
self.assertEqual(child_repo.bzrdir.root_transport.base,
628
found_repo.bzrdir.root_transport.base)
630
def test_find_repository_shared_within_shared_repository(self):
631
# find repo at a shared repo inside a shared repo finds the inner repo
633
containing_repo = self.make_repository('.', shared=True)
634
except errors.IncompatibleFormat:
635
# need a shared repository to test this.
637
url = self.get_url('childrepo')
638
get_transport(self.get_url()).mkdir('childrepo')
639
child_control = self.bzrdir_format.initialize(url)
640
child_repo = child_control.create_repository(shared=True)
641
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
642
found_repo = self.branch_format.find_repository(opened_control)
643
self.assertEqual(child_repo.bzrdir.root_transport.base,
644
found_repo.bzrdir.root_transport.base)
645
self.assertNotEqual(child_repo.bzrdir.root_transport.base,
646
containing_repo.bzrdir.root_transport.base)
648
def test_find_repository_with_nested_dirs_works(self):
649
# find repo inside a bzrdir inside a bzrdir inside a shared repo
650
# finds the outer shared repo.
652
repo = self.make_repository('.', shared=True)
653
except errors.IncompatibleFormat:
654
# need a shared repository to test this.
656
url = self.get_url('intermediate')
657
get_transport(self.get_url()).mkdir('intermediate')
658
get_transport(self.get_url()).mkdir('intermediate/child')
659
made_control = self.bzrdir_format.initialize(url)
661
child_repo = made_control.open_repository()
662
# if there is a repository, then the format cannot ever hit this
665
except errors.NoRepositoryPresent:
667
innermost_control = self.bzrdir_format.initialize(
668
self.get_url('intermediate/child'))
670
child_repo = innermost_control.open_repository()
671
# if there is a repository, then the format cannot ever hit this
674
except errors.NoRepositoryPresent:
676
found_repo = self.branch_format.find_repository(innermost_control)
677
self.assertEqual(repo.bzrdir.root_transport.base,
678
found_repo.bzrdir.root_transport.base)