~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_controldir/test_controldir.py

  • Committer: John Arbash Meinel
  • Date: 2010-09-25 20:08:01 UTC
  • mfrom: (5444 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5445.
  • Revision ID: john@arbash-meinel.com-20100925200801-7uf0ux3uwxo9i3x0
Merge bzr.dev 5444 to resolve some small text conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for bzrdir implementations - tests a bzrdir format."""
 
17
"""Tests for control directory implementations - tests a controldir format."""
18
18
 
19
 
from cStringIO import StringIO
20
 
import errno
21
19
from itertools import izip
22
20
import os
23
 
from stat import S_ISDIR
24
21
 
25
22
import bzrlib.branch
26
23
from bzrlib import (
27
24
    bzrdir,
28
25
    check,
 
26
    controldir,
29
27
    errors,
30
28
    gpg,
31
 
    lockdir,
32
29
    osutils,
33
 
    repository,
34
 
    revision as _mod_revision,
35
 
    transactions,
36
30
    transport,
37
31
    ui,
38
32
    urlutils,
39
33
    workingtree,
40
34
    )
41
 
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
42
 
from bzrlib.errors import (FileExists,
43
 
                           NoSuchRevision,
44
 
                           NoSuchFile,
45
 
                           UninitializableFormat,
46
 
                           NotBranchError,
47
 
                           )
48
35
import bzrlib.revision
49
36
from bzrlib.tests import (
50
37
                          ChrootedTestCase,
51
 
                          TestCase,
52
 
                          TestCaseWithTransport,
53
38
                          TestNotApplicable,
54
39
                          TestSkipped,
55
40
                          )
56
 
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
57
 
from bzrlib.trace import mutter
 
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
58
42
from bzrlib.transport.local import LocalTransport
59
43
from bzrlib.ui import (
60
44
    CannedInputUIFactory,
61
45
    )
62
 
from bzrlib.upgrade import upgrade
63
46
from bzrlib.remote import RemoteBzrDir, RemoteRepository
64
47
from bzrlib.repofmt import weaverepo
65
48
 
66
49
 
67
 
class TestBzrDir(TestCaseWithBzrDir):
68
 
    # Many of these tests test for disk equality rather than checking
69
 
    # for semantic equivalence. This works well for some tests but
70
 
    # is not good at handling changes in representation or the addition
71
 
    # or removal of control data. It would be nice to for instance:
72
 
    # sprout a new branch, check that the nickname has been reset by hand
73
 
    # and then set the nickname to match the source branch, at which point
74
 
    # a semantic equivalence should pass
75
 
 
76
 
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
77
 
        """Assert that the content of source and target are identical.
78
 
 
79
 
        paths in ignore list will be completely ignored.
80
 
 
81
 
        We ignore paths that represent data which is allowed to change during
82
 
        a clone or sprout: for instance, inventory.knit contains gzip fragements
83
 
        which have timestamps in them, and as we have read the inventory from
84
 
        the source knit, the already-read data is recompressed rather than
85
 
        reading it again, which leads to changed timestamps. This is ok though,
86
 
        because the inventory.kndx file is not ignored, and the integrity of
87
 
        knit joins is tested by test_knit and test_versionedfile.
88
 
 
89
 
        :seealso: Additionally, assertRepositoryHasSameItems provides value
90
 
            rather than representation checking of repositories for
91
 
            equivalence.
92
 
        """
93
 
        files = []
94
 
        directories = ['.']
95
 
        while directories:
96
 
            dir = directories.pop()
97
 
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
98
 
                path = dir + '/' + path
99
 
                if path in ignore_list:
100
 
                    continue
101
 
                try:
102
 
                    stat = source.stat(path)
103
 
                except errors.NoSuchFile:
104
 
                    self.fail('%s not in source' % path)
105
 
                if S_ISDIR(stat.st_mode):
106
 
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
107
 
                    directories.append(path)
108
 
                else:
109
 
                    self.assertEqualDiff(source.get(path).read(),
110
 
                                         target.get(path).read(),
111
 
                                         "text for file %r differs:\n" % path)
112
 
 
113
 
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
114
 
        """require left_repo and right_repo to contain the same data."""
115
 
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
116
 
        # local repositories to remote ones...  but this is an as-yet unsolved
117
 
        # aspect of format management and the Remote protocols...
118
 
        # self.assertEqual(left_repo._format.__class__,
119
 
        #     right_repo._format.__class__)
120
 
        left_repo.lock_read()
121
 
        try:
122
 
            right_repo.lock_read()
123
 
            try:
124
 
                # revs
125
 
                all_revs = left_repo.all_revision_ids()
126
 
                self.assertEqual(left_repo.all_revision_ids(),
127
 
                    right_repo.all_revision_ids())
128
 
                for rev_id in left_repo.all_revision_ids():
129
 
                    self.assertEqual(left_repo.get_revision(rev_id),
130
 
                        right_repo.get_revision(rev_id))
131
 
                # Assert the revision trees (and thus the inventories) are equal
132
 
                sort_key = lambda rev_tree: rev_tree.get_revision_id()
133
 
                rev_trees_a = sorted(
134
 
                    left_repo.revision_trees(all_revs), key=sort_key)
135
 
                rev_trees_b = sorted(
136
 
                    right_repo.revision_trees(all_revs), key=sort_key)
137
 
                for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
138
 
                    self.assertEqual([], list(tree_a.iter_changes(tree_b)))
139
 
                # texts
140
 
                text_index = left_repo._generate_text_key_index()
141
 
                self.assertEqual(text_index,
142
 
                    right_repo._generate_text_key_index())
143
 
                desired_files = []
144
 
                for file_id, revision_id in text_index.iterkeys():
145
 
                    desired_files.append(
146
 
                        (file_id, revision_id, (file_id, revision_id)))
147
 
                left_texts = list(left_repo.iter_files_bytes(desired_files))
148
 
                right_texts = list(right_repo.iter_files_bytes(desired_files))
149
 
                left_texts.sort()
150
 
                right_texts.sort()
151
 
                self.assertEqual(left_texts, right_texts)
152
 
                # signatures
153
 
                for rev_id in all_revs:
154
 
                    try:
155
 
                        left_text = left_repo.get_signature_text(rev_id)
156
 
                    except NoSuchRevision:
157
 
                        continue
158
 
                    right_text = right_repo.get_signature_text(rev_id)
159
 
                    self.assertEqual(left_text, right_text)
160
 
            finally:
161
 
                right_repo.unlock()
162
 
        finally:
163
 
            left_repo.unlock()
 
50
class TestControlDir(TestCaseWithControlDir):
164
51
 
165
52
    def skipIfNoWorkingTree(self, a_bzrdir):
166
53
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
189
76
        """
190
77
        try:
191
78
            return a_bzrdir.create_workingtree()
192
 
        except errors.NotLocalUrl:
 
79
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
193
80
            raise TestSkipped("cannot make working tree with transport %r"
194
81
                              % a_bzrdir.transport)
195
82
 
217
104
        dir.create_branch()
218
105
        try:
219
106
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
220
 
        except errors.NotLocalUrl:
 
107
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
221
108
            raise TestSkipped("cannot make working tree with transport %r"
222
109
                              % dir.transport)
223
110
        self.assertEqual([], wt.get_parent_ids())
264
151
        bzrdir.open_repository()
265
152
 
266
153
    def test_open_workingtree_raises_no_working_tree(self):
267
 
        """BzrDir.open_workingtree() should raise NoWorkingTree (rather than
 
154
        """ControlDir.open_workingtree() should raise NoWorkingTree (rather than
268
155
        e.g. NotLocalUrl) if there is no working tree.
269
156
        """
270
157
        dir = self.make_bzrdir('source')
271
158
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
272
159
        if vfs_dir.has_workingtree():
273
 
            # This BzrDir format doesn't support BzrDirs without working trees,
274
 
            # so this test is irrelevant.
 
160
            # This ControlDir format doesn't support ControlDirs without
 
161
            # working trees, so this test is irrelevant.
275
162
            return
276
163
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
277
164
 
278
 
    def test_clone_on_transport(self):
279
 
        a_dir = self.make_bzrdir('source')
280
 
        target_transport = a_dir.root_transport.clone('..').clone('target')
281
 
        target = a_dir.clone_on_transport(target_transport)
282
 
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
283
 
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
284
 
                                    ['./.bzr/merge-hashes'])
285
 
 
286
 
    def test_clone_bzrdir_empty(self):
287
 
        dir = self.make_bzrdir('source')
288
 
        target = dir.clone(self.get_url('target'))
289
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
290
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
291
 
                                    ['./.bzr/merge-hashes'])
292
 
 
293
 
    def test_clone_bzrdir_empty_force_new_ignored(self):
294
 
        # the force_new_repo parameter should have no effect on an empty
295
 
        # bzrdir's clone logic
296
 
        dir = self.make_bzrdir('source')
297
 
        target = dir.clone(self.get_url('target'), force_new_repo=True)
298
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
299
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
300
 
                                    ['./.bzr/merge-hashes'])
301
 
 
302
 
    def test_clone_bzrdir_repository(self):
303
 
        tree = self.make_branch_and_tree('commit_tree')
304
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
305
 
        tree.add('foo')
306
 
        tree.commit('revision 1', rev_id='1')
307
 
        dir = self.make_bzrdir('source')
308
 
        repo = dir.create_repository()
309
 
        repo.fetch(tree.branch.repository)
310
 
        self.assertTrue(repo.has_revision('1'))
311
 
        target = dir.clone(self.get_url('target'))
312
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
313
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
314
 
                                    [
315
 
                                     './.bzr/merge-hashes',
316
 
                                     './.bzr/repository',
317
 
                                     ])
318
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
319
 
            target.open_repository())
320
 
 
321
165
    def test_clone_bzrdir_repository_under_shared(self):
322
166
        tree = self.make_branch_and_tree('commit_tree')
323
167
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
393
237
        self.assertFalse(branch.repository.make_working_trees())
394
238
        self.assertTrue(branch.repository.is_shared())
395
239
 
396
 
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
397
 
        tree = self.make_branch_and_tree('commit_tree')
398
 
        self.build_tree(['commit_tree/foo'])
399
 
        tree.add('foo')
400
 
        tree.commit('revision 1', rev_id='1')
401
 
        dir = self.make_bzrdir('source')
402
 
        repo = dir.create_repository()
403
 
        repo.fetch(tree.branch.repository)
404
 
        self.assertTrue(repo.has_revision('1'))
405
 
        try:
406
 
            self.make_repository('target', shared=True)
407
 
        except errors.IncompatibleFormat:
408
 
            return
409
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
410
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
411
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
412
 
                                    ['./.bzr/repository',
413
 
                                     ])
414
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
415
 
 
416
240
    def test_clone_bzrdir_repository_revision(self):
417
241
        # test for revision limiting, [smoke test, not corner case checks].
418
242
        # make a repository with some revisions,
452
276
            tree_repo.get_signature_text(rev1),
453
277
            target.repository.get_signature_text(rev1))
454
278
 
455
 
    def test_clone_bzrdir_branch_and_repo(self):
456
 
        tree = self.make_branch_and_tree('commit_tree')
457
 
        self.build_tree(['commit_tree/foo'])
458
 
        tree.add('foo')
459
 
        tree.commit('revision 1')
460
 
        source = self.make_branch('source')
461
 
        tree.branch.repository.copy_content_into(source.repository)
462
 
        tree.branch.copy_content_into(source)
463
 
        dir = source.bzrdir
464
 
        target = dir.clone(self.get_url('target'))
465
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
466
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
467
 
                                    [
468
 
                                     './.bzr/basis-inventory-cache',
469
 
                                     './.bzr/checkout/stat-cache',
470
 
                                     './.bzr/merge-hashes',
471
 
                                     './.bzr/repository',
472
 
                                     './.bzr/stat-cache',
473
 
                                    ])
474
 
        self.assertRepositoryHasSameItems(
475
 
            tree.branch.repository, target.open_repository())
476
 
 
477
279
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
478
280
        # by default cloning into a shared repo uses the shared repo.
479
281
        tree = self.make_branch_and_tree('commit_tree')
494
296
        self.assertEqual(source.revision_history(),
495
297
                         target.open_branch().revision_history())
496
298
 
497
 
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
498
 
        # by default cloning into a shared repo uses the shared repo.
499
 
        tree = self.make_branch_and_tree('commit_tree')
500
 
        self.build_tree(['commit_tree/foo'])
501
 
        tree.add('foo')
502
 
        tree.commit('revision 1')
503
 
        source = self.make_branch('source')
504
 
        tree.branch.repository.copy_content_into(source.repository)
505
 
        tree.branch.copy_content_into(source)
506
 
        try:
507
 
            self.make_repository('target', shared=True)
508
 
        except errors.IncompatibleFormat:
509
 
            return
510
 
        dir = source.bzrdir
511
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
512
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
513
 
        repo = target.open_repository()
514
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
515
 
                                    ['./.bzr/repository',
516
 
                                     ])
517
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
518
 
 
519
 
    def test_clone_bzrdir_branch_reference(self):
520
 
        # cloning should preserve the reference status of the branch in a bzrdir
521
 
        referenced_branch = self.make_branch('referencced')
522
 
        dir = self.make_bzrdir('source')
523
 
        try:
524
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
525
 
                target_branch=referenced_branch)
526
 
        except errors.IncompatibleFormat:
527
 
            # this is ok too, not all formats have to support references.
528
 
            return
529
 
        target = dir.clone(self.get_url('target'))
530
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
531
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
532
 
 
533
299
    def test_clone_bzrdir_branch_revision(self):
534
300
        # test for revision limiting, [smoke test, not corner case checks].
535
301
        # make a branch with some revisions,
547
313
        target = dir.clone(self.get_url('target'), revision_id='1')
548
314
        self.assertEqual('1', target.open_branch().last_revision())
549
315
 
550
 
    def test_clone_bzrdir_tree_branch_repo(self):
551
 
        tree = self.make_branch_and_tree('source')
552
 
        self.build_tree(['source/foo'])
553
 
        tree.add('foo')
554
 
        tree.commit('revision 1')
555
 
        dir = tree.bzrdir
556
 
        target = dir.clone(self.get_url('target'))
557
 
        self.skipIfNoWorkingTree(target)
558
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
559
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
560
 
                                    ['./.bzr/stat-cache',
561
 
                                     './.bzr/checkout/dirstate',
562
 
                                     './.bzr/checkout/stat-cache',
563
 
                                     './.bzr/checkout/merge-hashes',
564
 
                                     './.bzr/merge-hashes',
565
 
                                     './.bzr/repository',
566
 
                                     ])
567
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
568
 
            target.open_repository())
569
 
        target.open_workingtree().revert()
570
 
 
571
316
    def test_clone_on_transport_preserves_repo_format(self):
572
317
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
573
318
            format = 'knit'
587
332
            target_repo = target_repo._real_repository
588
333
        self.assertEqual(target_repo._format, source_branch.repository._format)
589
334
 
590
 
    def test_revert_inventory(self):
591
 
        tree = self.make_branch_and_tree('source')
592
 
        self.build_tree(['source/foo'])
593
 
        tree.add('foo')
594
 
        tree.commit('revision 1')
595
 
        dir = tree.bzrdir
596
 
        target = dir.clone(self.get_url('target'))
597
 
        self.skipIfNoWorkingTree(target)
598
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
599
 
                                    ['./.bzr/stat-cache',
600
 
                                     './.bzr/checkout/dirstate',
601
 
                                     './.bzr/checkout/stat-cache',
602
 
                                     './.bzr/checkout/merge-hashes',
603
 
                                     './.bzr/merge-hashes',
604
 
                                     './.bzr/repository',
605
 
                                     ])
606
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
607
 
            target.open_repository())
608
 
 
609
 
        target.open_workingtree().revert()
610
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
611
 
                                    ['./.bzr/stat-cache',
612
 
                                     './.bzr/checkout/dirstate',
613
 
                                     './.bzr/checkout/stat-cache',
614
 
                                     './.bzr/checkout/merge-hashes',
615
 
                                     './.bzr/merge-hashes',
616
 
                                     './.bzr/repository',
617
 
                                     ])
618
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
619
 
            target.open_repository())
620
 
 
621
 
    def test_clone_bzrdir_tree_branch_reference(self):
622
 
        # a tree with a branch reference (aka a checkout)
623
 
        # should stay a checkout on clone.
624
 
        referenced_branch = self.make_branch('referencced')
625
 
        dir = self.make_bzrdir('source')
626
 
        try:
627
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
628
 
                target_branch=referenced_branch)
629
 
        except errors.IncompatibleFormat:
630
 
            # this is ok too, not all formats have to support references.
631
 
            return
632
 
        self.createWorkingTreeOrSkip(dir)
633
 
        target = dir.clone(self.get_url('target'))
634
 
        self.skipIfNoWorkingTree(target)
635
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
636
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
637
 
                                    ['./.bzr/stat-cache',
638
 
                                     './.bzr/checkout/stat-cache',
639
 
                                     './.bzr/checkout/merge-hashes',
640
 
                                     './.bzr/merge-hashes',
641
 
                                     './.bzr/repository/inventory.knit',
642
 
                                     ])
643
 
 
644
335
    def test_clone_bzrdir_tree_revision(self):
645
336
        # test for revision limiting, [smoke test, not corner case checks].
646
337
        # make a tree with a revision with a last-revision
732
423
        try:
733
424
            target.open_workingtree()
734
425
        except errors.NoWorkingTree:
735
 
            # bzrdir's that never have working trees are allowed to pass;
736
 
            # whitelist them for now.
737
 
            self.assertIsInstance(target, RemoteBzrDir)
 
426
            # Some bzrdirs can never have working trees.
 
427
            self.assertFalse(target._format.supports_workingtrees)
738
428
 
739
429
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
740
430
        # the force_new_repo parameter should force use of a new repo in an empty
749
439
        target.open_branch()
750
440
        self.openWorkingTreeIfLocal(target)
751
441
 
752
 
    def test_sprout_bzrdir_repository(self):
753
 
        tree = self.make_branch_and_tree('commit_tree')
754
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
755
 
        tree.add('foo')
756
 
        tree.commit('revision 1', rev_id='1')
757
 
        dir = self.make_bzrdir('source')
758
 
        repo = dir.create_repository()
759
 
        repo.fetch(tree.branch.repository)
760
 
        self.assertTrue(repo.has_revision('1'))
761
 
        try:
762
 
            self.assertTrue(
763
 
                _mod_revision.is_null(_mod_revision.ensure_null(
764
 
                dir.open_branch().last_revision())))
765
 
        except errors.NotBranchError:
766
 
            pass
767
 
        target = dir.sprout(self.get_url('target'))
768
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
769
 
        # testing inventory isn't reasonable for repositories
770
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
771
 
                                    [
772
 
                                     './.bzr/branch',
773
 
                                     './.bzr/checkout',
774
 
                                     './.bzr/inventory',
775
 
                                     './.bzr/parent',
776
 
                                     './.bzr/repository/inventory.knit',
777
 
                                     ])
778
 
        try:
779
 
            local_inventory = dir.transport.local_abspath('inventory')
780
 
        except errors.NotLocalUrl:
781
 
            return
782
 
        try:
783
 
            # If we happen to have a tree, we'll guarantee everything
784
 
            # except for the tree root is the same.
785
 
            inventory_f = file(local_inventory, 'rb')
786
 
            self.addCleanup(inventory_f.close)
787
 
            self.assertContainsRe(inventory_f.read(),
788
 
                                  '<inventory format="5">\n</inventory>\n')
789
 
        except IOError, e:
790
 
            if e.errno != errno.ENOENT:
791
 
                raise
792
 
 
793
442
    def test_sprout_bzrdir_with_repository_to_shared(self):
794
443
        tree = self.make_branch_and_tree('commit_tree')
795
444
        self.build_tree(['commit_tree/foo'])
853
502
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
854
503
        branch = target.open_branch()
855
504
        self.assertTrue(branch.repository.has_revision('1'))
856
 
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
505
        if branch.bzrdir._format.supports_workingtrees:
857
506
            self.assertTrue(branch.repository.make_working_trees())
858
507
        self.assertFalse(branch.repository.is_shared())
859
508
 
894
543
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
895
544
        raise TestSkipped('revision limiting not strict yet')
896
545
 
897
 
    def test_sprout_bzrdir_branch_and_repo(self):
898
 
        tree = self.make_branch_and_tree('commit_tree')
899
 
        self.build_tree(['commit_tree/foo'])
900
 
        tree.add('foo')
901
 
        tree.commit('revision 1')
902
 
        source = self.make_branch('source')
903
 
        tree.branch.repository.copy_content_into(source.repository)
904
 
        tree.bzrdir.open_branch().copy_content_into(source)
905
 
        dir = source.bzrdir
906
 
        target = dir.sprout(self.get_url('target'))
907
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
908
 
        target_repo = target.open_repository()
909
 
        self.assertRepositoryHasSameItems(source.repository, target_repo)
910
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
911
 
                                    [
912
 
                                     './.bzr/basis-inventory-cache',
913
 
                                     './.bzr/branch/branch.conf',
914
 
                                     './.bzr/branch/parent',
915
 
                                     './.bzr/checkout',
916
 
                                     './.bzr/checkout/inventory',
917
 
                                     './.bzr/checkout/stat-cache',
918
 
                                     './.bzr/inventory',
919
 
                                     './.bzr/parent',
920
 
                                     './.bzr/repository',
921
 
                                     './.bzr/stat-cache',
922
 
                                     './foo',
923
 
                                     ])
924
 
 
925
546
    def test_sprout_bzrdir_branch_and_repo_shared(self):
926
547
        # sprouting a branch with a repo into a shared repo uses the shared
927
548
        # repo
1046
667
        target = dir.sprout(self.get_url('target'), revision_id='1')
1047
668
        self.assertEqual('1', target.open_branch().last_revision())
1048
669
 
1049
 
    def test_sprout_bzrdir_tree_branch_repo(self):
1050
 
        tree = self.make_branch_and_tree('source')
1051
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1052
 
        tree.add('foo')
1053
 
        tree.commit('revision 1')
1054
 
        dir = tree.bzrdir
1055
 
        target = self.sproutOrSkip(dir, self.get_url('target'))
1056
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
1057
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1058
 
                                    [
1059
 
                                     './.bzr/branch/branch.conf',
1060
 
                                     './.bzr/branch/parent',
1061
 
                                     './.bzr/checkout/dirstate',
1062
 
                                     './.bzr/checkout/stat-cache',
1063
 
                                     './.bzr/checkout/inventory',
1064
 
                                     './.bzr/inventory',
1065
 
                                     './.bzr/parent',
1066
 
                                     './.bzr/repository',
1067
 
                                     './.bzr/stat-cache',
1068
 
                                     ])
1069
 
        self.assertRepositoryHasSameItems(
1070
 
            tree.branch.repository, target.open_repository())
1071
 
 
1072
670
    def test_sprout_bzrdir_tree_branch_reference(self):
1073
671
        # sprouting should create a repository if needed and a sprouted branch.
1074
672
        # the tree state should not be copied.
1208
806
        t = transport.get_transport(self.get_url())
1209
807
        readonly_t = transport.get_transport(self.get_readonly_url())
1210
808
        made_control = self.bzrdir_format.initialize(t.base)
1211
 
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
 
809
        self.failUnless(isinstance(made_control, controldir.ControlDir))
1212
810
        self.assertEqual(self.bzrdir_format,
1213
 
                         bzrdir.BzrDirFormat.find_format(readonly_t))
 
811
                         controldir.ControlDirFormat.find_format(readonly_t))
1214
812
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1215
813
        opened_dir = bzrdir.BzrDir.open(t.base)
1216
814
        self.assertEqual(made_control._format,
1217
815
                         opened_dir._format)
1218
816
        self.assertEqual(direct_opened_dir._format,
1219
817
                         opened_dir._format)
1220
 
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
 
818
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
1221
819
 
1222
820
    def test_format_initialize_on_transport_ex(self):
1223
821
        t = self.get_transport('dir')
1405
1003
            network_name = format.network_name()
1406
1004
            self.assertEqual(real_dir._format.network_name(), network_name)
1407
1005
        else:
1408
 
            registry = bzrdir.network_format_registry
 
1006
            registry = controldir.network_format_registry
1409
1007
            network_name = format.network_name()
1410
1008
            looked_up_format = registry.get(network_name)
1411
 
            self.assertEqual(format.__class__, looked_up_format.__class__)
 
1009
            self.assertTrue(
 
1010
                issubclass(format.__class__, looked_up_format.__class__))
1412
1011
        # The network name must be a byte string.
1413
1012
        self.assertIsInstance(network_name, str)
1414
1013
 
1415
1014
    def test_open_not_bzrdir(self):
1416
1015
        # test the formats specific behaviour for no-content or similar dirs.
1417
 
        self.assertRaises(NotBranchError,
 
1016
        self.assertRaises(errors.NotBranchError,
1418
1017
                          self.bzrdir_format.open,
1419
1018
                          transport.get_transport(self.get_readonly_url()))
1420
1019
 
1553
1152
        source.branch.clone(made_control)
1554
1153
        try:
1555
1154
            made_tree = made_control.create_workingtree(revision_id='a')
1556
 
        except errors.NotLocalUrl:
 
1155
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1557
1156
            raise TestSkipped("Can't make working tree on transport %r" % t)
1558
1157
        self.assertEqual(['a'], made_tree.get_parent_ids())
1559
1158
 
1571
1170
            made_repo = made_control.create_repository()
1572
1171
            made_branch = made_control.create_branch()
1573
1172
            made_tree = made_control.create_workingtree()
1574
 
        except errors.NotLocalUrl:
 
1173
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1575
1174
            raise TestSkipped("Can't initialize %r on transport %r"
1576
1175
                              % (self.bzrdir_format, t))
1577
1176
        opened_tree = made_control.open_workingtree()
1767
1366
            self.assertTrue(isinstance(dir._format.get_converter(
1768
1367
                format=dir._format), bzrdir.Converter))
1769
1368
        dir.needs_format_conversion(
1770
 
            bzrdir.BzrDirFormat.get_default_format())
 
1369
            controldir.ControlDirFormat.get_default_format())
1771
1370
 
1772
1371
    def test_backup_copies_existing(self):
1773
1372
        tree = self.make_branch_and_tree('test')
1814
1413
        text = dir._format.get_format_description()
1815
1414
        self.failUnless(len(text))
1816
1415
 
1817
 
    def test_retire_bzrdir(self):
1818
 
        bd = self.make_bzrdir('.')
1819
 
        transport = bd.root_transport
1820
 
        # must not overwrite existing directories
1821
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1822
 
            transport=transport)
1823
 
        self.failUnless(transport.has('.bzr'))
1824
 
        bd.retire_bzrdir()
1825
 
        self.failIf(transport.has('.bzr'))
1826
 
        self.failUnless(transport.has('.bzr.retired.1'))
1827
 
 
1828
 
    def test_retire_bzrdir_limited(self):
1829
 
        bd = self.make_bzrdir('.')
1830
 
        transport = bd.root_transport
1831
 
        # must not overwrite existing directories
1832
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1833
 
            transport=transport)
1834
 
        self.failUnless(transport.has('.bzr'))
1835
 
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1836
 
            bd.retire_bzrdir, limit=0)
1837
 
 
1838
 
 
1839
 
class TestBreakLock(TestCaseWithBzrDir):
 
1416
 
 
1417
class TestBreakLock(TestCaseWithControlDir):
1840
1418
 
1841
1419
    def test_break_lock_empty(self):
1842
1420
        # break lock on an empty bzrdir should work silently.
1944
1522
        self.assertRaises(errors.LockBroken, tree.unlock)
1945
1523
 
1946
1524
 
1947
 
class TestTransportConfig(TestCaseWithBzrDir):
 
1525
class TestTransportConfig(TestCaseWithControlDir):
1948
1526
 
1949
1527
    def test_get_config(self):
1950
1528
        my_dir = self.make_bzrdir('.')
1966
1544
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1967
1545
 
1968
1546
 
1969
 
class ChrootedBzrDirTests(ChrootedTestCase):
 
1547
class ChrootedControlDirTests(ChrootedTestCase):
1970
1548
 
1971
1549
    def test_find_repository_no_repository(self):
1972
1550
        # loopback test to check the current format fails to find a
1994
1572
                          made_control.find_repository)
1995
1573
 
1996
1574
 
1997
 
class TestBzrDirControlComponent(TestCaseWithBzrDir):
1998
 
    """BzrDir implementations adequately implement ControlComponent."""
 
1575
class TestControlDirControlComponent(TestCaseWithControlDir):
 
1576
    """ControlDir implementations adequately implement ControlComponent."""
1999
1577
 
2000
1578
    def test_urls(self):
2001
1579
        bd = self.make_bzrdir('bd')