~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-07 10:45:44 UTC
  • mfrom: (2321.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070307104544-59e3e6358e4bdb29
(robertc) Merge dirstate and subtrees. (Robert Collins, Martin Pool, Aaaron Bentley, John A Meinel, James Westby)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from StringIO import StringIO
24
24
 
25
25
from bzrlib import (
 
26
    bzrdir,
 
27
    errors,
26
28
    help_topics,
 
29
    repository,
27
30
    symbol_versioning,
28
31
    urlutils,
29
32
    workingtree,
30
33
    )
31
34
import bzrlib.branch
32
 
import bzrlib.bzrdir as bzrdir
33
 
import bzrlib.errors as errors
34
35
from bzrlib.errors import (NotBranchError,
35
36
                           UnknownFormatError,
36
37
                           UnsupportedFormatError,
37
38
                           )
38
 
import bzrlib.repository as repository
39
39
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
40
40
from bzrlib.tests.HttpServer import HttpServer
41
41
from bzrlib.transport import get_transport
77
77
            )
78
78
        my_format_registry.set_default('knit')
79
79
        my_format_registry.register_metadir(
80
 
            'experimental-knit2',
81
 
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
82
 
            'Experimental successor to knit.  Use at your own risk.',
83
 
            )
84
 
        my_format_registry.register_metadir(
85
80
            'branch6',
86
 
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
 
81
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
87
82
            'Experimental successor to knit.  Use at your own risk.',
88
 
            branch_format='BzrBranchFormat6')
 
83
            branch_format='bzrlib.branch.BzrBranchFormat6')
89
84
        return my_format_registry
90
85
 
91
86
    def test_format_registry(self):
132
127
        default_factory = bzrdir.format_registry.get('default')
133
128
        old_default = [k for k, v in bzrdir.format_registry.iteritems()
134
129
                       if v == default_factory and k != 'default'][0]
135
 
        bzrdir.format_registry.set_default_repository('experimental-knit2')
 
130
        bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
136
131
        try:
137
 
            self.assertIs(bzrdir.format_registry.get('experimental-knit2'),
 
132
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
138
133
                          bzrdir.format_registry.get('default'))
139
134
            self.assertIs(
140
135
                repository.RepositoryFormat.get_default_format().__class__,
141
 
                knitrepo.RepositoryFormatKnit2)
 
136
                knitrepo.RepositoryFormatKnit3)
142
137
        finally:
143
138
            bzrdir.format_registry.set_default_repository(old_default)
144
139
 
477
472
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
478
473
                          transport)
479
474
 
 
475
    def test_sprout_recursive(self):
 
476
        tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
 
477
        sub_tree = self.make_branch_and_tree('tree1/subtree',
 
478
            format='dirstate-with-subtree')
 
479
        tree.add_reference(sub_tree)
 
480
        self.build_tree(['tree1/subtree/file'])
 
481
        sub_tree.add('file')
 
482
        tree.commit('Initial commit')
 
483
        tree.bzrdir.sprout('tree2')
 
484
        self.failUnlessExists('tree2/subtree/file')
 
485
 
 
486
    def test_cloning_metadir(self):
 
487
        """Ensure that cloning metadir is suitable"""
 
488
        bzrdir = self.make_bzrdir('bzrdir')
 
489
        bzrdir.cloning_metadir()
 
490
        branch = self.make_branch('branch', format='knit')
 
491
        format = branch.bzrdir.cloning_metadir()
 
492
        self.assertIsInstance(format.workingtree_format,
 
493
            workingtree.WorkingTreeFormat3)
 
494
 
 
495
    def test_sprout_recursive_treeless(self):
 
496
        tree = self.make_branch_and_tree('tree1',
 
497
            format='dirstate-with-subtree')
 
498
        sub_tree = self.make_branch_and_tree('tree1/subtree',
 
499
            format='dirstate-with-subtree')
 
500
        tree.add_reference(sub_tree)
 
501
        self.build_tree(['tree1/subtree/file'])
 
502
        sub_tree.add('file')
 
503
        tree.commit('Initial commit')
 
504
        tree.bzrdir.destroy_workingtree()
 
505
        repo = self.make_repository('repo', shared=True,
 
506
            format='dirstate-with-subtree')
 
507
        repo.set_make_working_trees(False)
 
508
        tree.bzrdir.sprout('repo/tree2')
 
509
        self.failUnlessExists('repo/tree2/subtree')
 
510
        self.failIfExists('repo/tree2/subtree/file')
 
511
 
480
512
 
481
513
class TestMeta1DirFormat(TestCaseWithTransport):
482
514
    """Tests specific to the meta1 dir format."""
503
535
        t = dir.transport
504
536
        self.assertIsDirectory('branch-lock', t)
505
537
 
506
 
        
 
538
    def test_comparison(self):
 
539
        """Equality and inequality behave properly.
 
540
 
 
541
        Metadirs should compare equal iff they have the same repo, branch and
 
542
        tree formats.
 
543
        """
 
544
        mydir = bzrdir.format_registry.make_bzrdir('knit')
 
545
        self.assertEqual(mydir, mydir)
 
546
        self.assertFalse(mydir != mydir)
 
547
        otherdir = bzrdir.format_registry.make_bzrdir('knit')
 
548
        self.assertEqual(otherdir, mydir)
 
549
        self.assertFalse(otherdir != mydir)
 
550
        otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
 
551
        self.assertNotEqual(otherdir2, mydir)
 
552
        self.assertFalse(otherdir2 == mydir)
 
553
 
 
554
    def test_needs_conversion_different_working_tree(self):
 
555
        # meta1dirs need an conversion if any element is not the default.
 
556
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
557
        # test with 
 
558
        new_default = bzrdir.format_registry.make_bzrdir('dirstate')
 
559
        bzrdir.BzrDirFormat._set_default_format(new_default)
 
560
        try:
 
561
            tree = self.make_branch_and_tree('tree', format='knit')
 
562
            self.assertTrue(tree.bzrdir.needs_format_conversion())
 
563
        finally:
 
564
            bzrdir.BzrDirFormat._set_default_format(old_format)
 
565
 
 
566
 
507
567
class TestFormat5(TestCaseWithTransport):
508
568
    """Tests specific to the version 5 bzrdir format."""
509
569
 
678
738
        result.open_branch()
679
739
        result.open_repository()
680
740
 
 
741
    def test_checkout_metadir(self):
 
742
        # checkout_metadir has reasonable working tree format even when no
 
743
        # working tree is present
 
744
        self.make_branch('branch-knit2', format='dirstate-with-subtree')
 
745
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
 
746
        checkout_format = my_bzrdir.checkout_metadir()
 
747
        self.assertIsInstance(checkout_format.workingtree_format,
 
748
                              workingtree.WorkingTreeFormat3)
 
749
 
681
750
 
682
751
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):
683
752