~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_bzrdir/test_bzrdir.py

  • Committer: Shannon Weyrick
  • Date: 2011-11-04 13:40:04 UTC
  • mfrom: (6238 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6256.
  • Revision ID: weyrick@mozek.us-20111104134004-033t2wqhc3ydzm0a
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import bzrlib.branch
23
23
from bzrlib import (
 
24
    bzrdir,
24
25
    errors,
25
26
    repository,
26
27
    revision as _mod_revision,
27
28
    transport,
28
29
    workingtree,
29
30
    )
 
31
from bzrlib.remote import RemoteBzrDirFormat
30
32
from bzrlib.tests import (
 
33
    TestNotApplicable,
31
34
    TestSkipped,
32
35
    )
33
36
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
328
331
                                     './.bzr/repository',
329
332
                                     ])
330
333
        self.assertRepositoryHasSameItems(tree.branch.repository,
331
 
            target.open_repository())
 
334
            target.open_branch().repository)
332
335
        target.open_workingtree().revert()
333
336
 
334
337
    def test_revert_inventory(self):
348
351
                                     './.bzr/repository',
349
352
                                     ])
350
353
        self.assertRepositoryHasSameItems(tree.branch.repository,
351
 
            target.open_repository())
 
354
            target.open_branch().repository)
352
355
 
353
356
        target.open_workingtree().revert()
354
357
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
360
363
                                     './.bzr/repository',
361
364
                                     ])
362
365
        self.assertRepositoryHasSameItems(tree.branch.repository,
363
 
            target.open_repository())
 
366
            target.open_branch().repository)
364
367
 
365
368
    def test_clone_bzrdir_tree_branch_reference(self):
366
369
        # a tree with a branch reference (aka a checkout)
500
503
        self.assertNotEqual(dir.transport.base, target.transport.base)
501
504
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
502
505
                                    [
503
 
                                     './.bzr/branch/branch.conf',
504
 
                                     './.bzr/branch/parent',
 
506
                                     './.bzr/branch',
505
507
                                     './.bzr/checkout/dirstate',
506
508
                                     './.bzr/checkout/stat-cache',
507
509
                                     './.bzr/checkout/inventory',
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('.')
 
602
 
 
603
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
604
        """Execute initialize_on_transport_ex and check it succeeded correctly.
 
605
 
 
606
        This involves checking that the disk objects were created, open with
 
607
        the same format returned, and had the expected disk format.
 
608
 
 
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.
 
613
        """
 
614
        if not self.bzrdir_format.is_initializable():
 
615
            raise TestNotApplicable("control dir format is not "
 
616
                "initializable")
 
617
        repo, control, require_stacking, repo_policy = \
 
618
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
 
619
        if repo is not None:
 
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__)
 
636
        return repo, control
 
637
 
 
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
 
642
        # branch.
 
643
        balloon = self.make_bzrdir('balloon')
 
644
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
 
645
            stack_on = self.make_branch('stack-on', format='1.9')
 
646
        else:
 
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()
 
651
        try:
 
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]
 
665
        self.assertEqual(
 
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())
 
670
 
 
671