~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

  • Committer: Robert Collins
  • Date: 2006-02-13 08:15:16 UTC
  • mto: (1534.5.2 bzr-dir)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060213081516-3d13375f0de0ccb6
find_repository sufficiently robust.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        except errors.UninitializableFormat:
67
67
            raise TestSkipped('Uninitializable branch format')
68
68
 
69
 
    def make_repository(self, relpath):
 
69
    def make_repository(self, relpath, shared=False):
70
70
        try:
71
71
            url = self.get_url(relpath)
72
72
            segments = url.split('/')
78
78
                except FileExists:
79
79
                    pass
80
80
            made_control = self.bzrdir_format.initialize(url)
81
 
            return made_control.create_repository()
 
81
            return made_control.create_repository(shared=shared)
82
82
        except UninitializableFormat:
83
83
            raise TestSkipped("Format %s is not initializable.")
84
84
 
354
354
            # they may not be initializable.
355
355
            return
356
356
        # supported formats must be able to init and open
357
 
        url = self.get_url()
 
357
        url = self.get_url('subdir')
 
358
        get_transport(self.get_url()).mkdir('subdir')
358
359
        made_control = self.bzrdir_format.initialize(url)
359
 
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url())
 
360
        try:
 
361
            repo = made_control.open_repository()
 
362
            # if there is a repository, then the format cannot ever hit this 
 
363
            # code path.
 
364
            return
 
365
        except errors.NoRepositoryPresent:
 
366
            pass
 
367
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
360
368
        self.assertRaises(errors.NoRepositoryPresent,
361
369
                          self.branch_format.find_repository,
362
370
                          opened_control)
559
567
                         branch.BranchFormat.find_format(opened_control))
560
568
 
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
566
 
        #   found.
567
 
        parent_bzrdir = self.make_branch('.')
 
570
        # finding a repo stops at standalone branches even if there is a
 
571
        # higher repository available.
 
572
        try:
 
573
            repo = self.make_repository('.', shared=True)
 
574
        except errors.IncompatibleFormat:
 
575
            # need a shared repository to test this.
 
576
            return
 
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'))
 
584
        try:
 
585
            child_repo = innermost_control.open_repository()
 
586
            # if there is a repository, then the format cannot ever hit this 
 
587
            # code path.
 
588
            return
 
589
        except errors.NoRepositoryPresent:
 
590
            pass
 
591
        self.assertRaises(errors.NoRepositoryPresent,
 
592
                          self.branch_format.find_repository,
 
593
                          innermost_control)
 
594
 
 
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.
 
598
        try:
 
599
            repo = self.make_repository('.', shared=True)
 
600
        except errors.IncompatibleFormat:
 
601
            # need a shared repository to test this.
 
602
            return
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,
573
 
                          made_control)
 
606
        try:
 
607
            child_repo = made_control.open_repository()
 
608
            # if there is a repository, then the format cannot ever hit this 
 
609
            # code path.
 
610
            return
 
611
        except errors.NoRepositoryPresent:
 
612
            pass
 
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)
 
616
        
 
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
 
619
        try:
 
620
            containing_repo = self.make_repository('.', shared=True)
 
621
        except errors.IncompatibleFormat:
 
622
            # need a shared repository to test this.
 
623
            return
 
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)
 
629
 
 
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
 
632
        try:
 
633
            containing_repo = self.make_repository('.', shared=True)
 
634
        except errors.IncompatibleFormat:
 
635
            # need a shared repository to test this.
 
636
            return
 
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)
 
647
 
 
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.
 
651
        try:
 
652
            repo = self.make_repository('.', shared=True)
 
653
        except errors.IncompatibleFormat:
 
654
            # need a shared repository to test this.
 
655
            return
 
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)
 
660
        try:
 
661
            child_repo = made_control.open_repository()
 
662
            # if there is a repository, then the format cannot ever hit this 
 
663
            # code path.
 
664
            return
 
665
        except errors.NoRepositoryPresent:
 
666
            pass
 
667
        innermost_control = self.bzrdir_format.initialize(
 
668
            self.get_url('intermediate/child'))
 
669
        try:
 
670
            child_repo = innermost_control.open_repository()
 
671
            # if there is a repository, then the format cannot ever hit this 
 
672
            # code path.
 
673
            return
 
674
        except errors.NoRepositoryPresent:
 
675
            pass
 
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)
 
679