~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(vila) Fix bzrlib.tests.test_gpg.TestVerify.test_verify_revoked_signature
 with recent versions of gpg. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
import os
23
 
from stat import S_ISDIR
24
20
 
25
21
import bzrlib.branch
26
22
from bzrlib import (
27
 
    bzrdir,
 
23
    bzrdir as _mod_bzrdir,
28
24
    check,
29
25
    controldir,
30
26
    errors,
36
32
    urlutils,
37
33
    workingtree,
38
34
    )
39
 
from bzrlib.errors import (NoSuchRevision,
40
 
                           NotBranchError,
41
 
                           )
42
 
import bzrlib.revision
43
35
from bzrlib.tests import (
44
 
                          ChrootedTestCase,
45
 
                          TestNotApplicable,
46
 
                          TestSkipped,
47
 
                          )
 
36
    fixtures,
 
37
    ChrootedTestCase,
 
38
    TestNotApplicable,
 
39
    TestSkipped,
 
40
    )
48
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
49
42
from bzrlib.transport.local import LocalTransport
50
43
from bzrlib.ui import (
51
44
    CannedInputUIFactory,
52
45
    )
53
 
from bzrlib.remote import RemoteBzrDir, RemoteRepository
54
 
from bzrlib.repofmt import weaverepo
 
46
from bzrlib.remote import (
 
47
    RemoteBzrDir,
 
48
    RemoteBzrDirFormat,
 
49
    RemoteRepository,
 
50
    )
55
51
 
56
52
 
57
53
class TestControlDir(TestCaseWithControlDir):
58
 
    # Many of these tests test for disk equality rather than checking
59
 
    # for semantic equivalence. This works well for some tests but
60
 
    # is not good at handling changes in representation or the addition
61
 
    # or removal of control data. It would be nice to for instance:
62
 
    # sprout a new branch, check that the nickname has been reset by hand
63
 
    # and then set the nickname to match the source branch, at which point
64
 
    # a semantic equivalence should pass
65
 
 
66
 
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
67
 
        """Assert that the content of source and target are identical.
68
 
 
69
 
        paths in ignore list will be completely ignored.
70
 
 
71
 
        We ignore paths that represent data which is allowed to change during
72
 
        a clone or sprout: for instance, inventory.knit contains gzip fragements
73
 
        which have timestamps in them, and as we have read the inventory from
74
 
        the source knit, the already-read data is recompressed rather than
75
 
        reading it again, which leads to changed timestamps. This is ok though,
76
 
        because the inventory.kndx file is not ignored, and the integrity of
77
 
        knit joins is tested by test_knit and test_versionedfile.
78
 
 
79
 
        :seealso: Additionally, assertRepositoryHasSameItems provides value
80
 
            rather than representation checking of repositories for
81
 
            equivalence.
82
 
        """
83
 
        files = []
84
 
        directories = ['.']
85
 
        while directories:
86
 
            dir = directories.pop()
87
 
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
88
 
                path = dir + '/' + path
89
 
                if path in ignore_list:
90
 
                    continue
91
 
                try:
92
 
                    stat = source.stat(path)
93
 
                except errors.NoSuchFile:
94
 
                    self.fail('%s not in source' % path)
95
 
                if S_ISDIR(stat.st_mode):
96
 
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
97
 
                    directories.append(path)
98
 
                else:
99
 
                    self.assertEqualDiff(source.get(path).read(),
100
 
                                         target.get(path).read(),
101
 
                                         "text for file %r differs:\n" % path)
102
 
 
103
 
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
104
 
        """require left_repo and right_repo to contain the same data."""
105
 
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
106
 
        # local repositories to remote ones...  but this is an as-yet unsolved
107
 
        # aspect of format management and the Remote protocols...
108
 
        # self.assertEqual(left_repo._format.__class__,
109
 
        #     right_repo._format.__class__)
110
 
        left_repo.lock_read()
111
 
        try:
112
 
            right_repo.lock_read()
113
 
            try:
114
 
                # revs
115
 
                all_revs = left_repo.all_revision_ids()
116
 
                self.assertEqual(left_repo.all_revision_ids(),
117
 
                    right_repo.all_revision_ids())
118
 
                for rev_id in left_repo.all_revision_ids():
119
 
                    self.assertEqual(left_repo.get_revision(rev_id),
120
 
                        right_repo.get_revision(rev_id))
121
 
                # Assert the revision trees (and thus the inventories) are equal
122
 
                sort_key = lambda rev_tree: rev_tree.get_revision_id()
123
 
                rev_trees_a = sorted(
124
 
                    left_repo.revision_trees(all_revs), key=sort_key)
125
 
                rev_trees_b = sorted(
126
 
                    right_repo.revision_trees(all_revs), key=sort_key)
127
 
                for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
128
 
                    self.assertEqual([], list(tree_a.iter_changes(tree_b)))
129
 
                # texts
130
 
                text_index = left_repo._generate_text_key_index()
131
 
                self.assertEqual(text_index,
132
 
                    right_repo._generate_text_key_index())
133
 
                desired_files = []
134
 
                for file_id, revision_id in text_index.iterkeys():
135
 
                    desired_files.append(
136
 
                        (file_id, revision_id, (file_id, revision_id)))
137
 
                left_texts = list(left_repo.iter_files_bytes(desired_files))
138
 
                right_texts = list(right_repo.iter_files_bytes(desired_files))
139
 
                left_texts.sort()
140
 
                right_texts.sort()
141
 
                self.assertEqual(left_texts, right_texts)
142
 
                # signatures
143
 
                for rev_id in all_revs:
144
 
                    try:
145
 
                        left_text = left_repo.get_signature_text(rev_id)
146
 
                    except NoSuchRevision:
147
 
                        continue
148
 
                    right_text = right_repo.get_signature_text(rev_id)
149
 
                    self.assertEqual(left_text, right_text)
150
 
            finally:
151
 
                right_repo.unlock()
152
 
        finally:
153
 
            left_repo.unlock()
154
54
 
155
55
    def skipIfNoWorkingTree(self, a_bzrdir):
156
56
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
179
79
        """
180
80
        try:
181
81
            return a_bzrdir.create_workingtree()
182
 
        except errors.NotLocalUrl:
 
82
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
183
83
            raise TestSkipped("cannot make working tree with transport %r"
184
84
                              % a_bzrdir.transport)
185
85
 
201
101
                                    create_tree_if_local=create_tree_if_local)
202
102
        return target
203
103
 
 
104
    def test_uninitializable(self):
 
105
        if self.bzrdir_format.is_initializable():
 
106
            raise TestNotApplicable("format is initializable")
 
107
        t = self.get_transport()
 
108
        self.assertRaises(errors.UninitializableFormat,
 
109
            self.bzrdir_format.initialize, t.base)
 
110
 
 
111
    def test_multiple_initialization(self):
 
112
        # loopback test to check the current format initializes to itself.
 
113
        if not self.bzrdir_format.is_initializable():
 
114
            # unsupported formats are not loopback testable
 
115
            # because the default open will not open them and
 
116
            # they may not be initializable.
 
117
            raise TestNotApplicable("format is not initializable")
 
118
        self.bzrdir_format.initialize('.')
 
119
        self.assertRaises(errors.AlreadyControlDirError,
 
120
            self.bzrdir_format.initialize, '.')
 
121
 
204
122
    def test_create_null_workingtree(self):
205
123
        dir = self.make_bzrdir('dir1')
206
124
        dir.create_repository()
207
125
        dir.create_branch()
208
126
        try:
209
 
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
210
 
        except errors.NotLocalUrl:
 
127
            wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
 
128
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
211
129
            raise TestSkipped("cannot make working tree with transport %r"
212
130
                              % dir.transport)
213
131
        self.assertEqual([], wt.get_parent_ids())
222
140
            bzrdir.destroy_workingtree()
223
141
        except errors.UnsupportedOperation:
224
142
            raise TestSkipped('Format does not support destroying tree')
225
 
        self.failIfExists('tree/file')
 
143
        self.assertPathDoesNotExist('tree/file')
226
144
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
227
145
        bzrdir.create_workingtree()
228
 
        self.failUnlessExists('tree/file')
 
146
        self.assertPathExists('tree/file')
229
147
        bzrdir.destroy_workingtree_metadata()
230
 
        self.failUnlessExists('tree/file')
 
148
        self.assertPathExists('tree/file')
231
149
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
232
150
 
233
151
    def test_destroy_branch(self):
241
159
        bzrdir.create_branch()
242
160
        bzrdir.open_branch()
243
161
 
 
162
    def test_destroy_branch_no_branch(self):
 
163
        branch = self.make_repository('branch')
 
164
        bzrdir = branch.bzrdir
 
165
        try:
 
166
            self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
 
167
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
 
168
            raise TestNotApplicable('Format does not support destroying branch')
 
169
 
244
170
    def test_destroy_repository(self):
245
171
        repo = self.make_repository('repository')
246
172
        bzrdir = repo.bzrdir
249
175
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
250
176
            raise TestNotApplicable('Format does not support destroying'
251
177
                                    ' repository')
 
178
        self.assertRaises(errors.NoRepositoryPresent,
 
179
            bzrdir.destroy_repository)
252
180
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
253
181
        bzrdir.create_repository()
254
182
        bzrdir.open_repository()
258
186
        e.g. NotLocalUrl) if there is no working tree.
259
187
        """
260
188
        dir = self.make_bzrdir('source')
261
 
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
 
189
        vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
262
190
        if vfs_dir.has_workingtree():
263
191
            # This ControlDir format doesn't support ControlDirs without
264
192
            # working trees, so this test is irrelevant.
265
 
            return
 
193
            raise TestNotApplicable("format does not support "
 
194
                "control directories without working tree")
266
195
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
267
196
 
268
 
    def test_clone_on_transport(self):
269
 
        a_dir = self.make_bzrdir('source')
270
 
        target_transport = a_dir.root_transport.clone('..').clone('target')
271
 
        target = a_dir.clone_on_transport(target_transport)
272
 
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
273
 
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
274
 
                                    ['./.bzr/merge-hashes'])
275
 
 
276
 
    def test_clone_bzrdir_empty(self):
277
 
        dir = self.make_bzrdir('source')
278
 
        target = dir.clone(self.get_url('target'))
279
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
280
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
281
 
                                    ['./.bzr/merge-hashes'])
282
 
 
283
 
    def test_clone_bzrdir_empty_force_new_ignored(self):
284
 
        # the force_new_repo parameter should have no effect on an empty
285
 
        # bzrdir's clone logic
286
 
        dir = self.make_bzrdir('source')
287
 
        target = dir.clone(self.get_url('target'), force_new_repo=True)
288
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
289
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
290
 
                                    ['./.bzr/merge-hashes'])
291
 
 
292
 
    def test_clone_bzrdir_repository(self):
293
 
        tree = self.make_branch_and_tree('commit_tree')
294
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
295
 
        tree.add('foo')
296
 
        tree.commit('revision 1', rev_id='1')
297
 
        dir = self.make_bzrdir('source')
298
 
        repo = dir.create_repository()
299
 
        repo.fetch(tree.branch.repository)
300
 
        self.assertTrue(repo.has_revision('1'))
301
 
        target = dir.clone(self.get_url('target'))
302
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
303
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
304
 
                                    [
305
 
                                     './.bzr/merge-hashes',
306
 
                                     './.bzr/repository',
307
 
                                     ])
308
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
309
 
            target.open_repository())
310
 
 
311
197
    def test_clone_bzrdir_repository_under_shared(self):
312
198
        tree = self.make_branch_and_tree('commit_tree')
313
199
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
315
201
        tree.commit('revision 1', rev_id='1')
316
202
        dir = self.make_bzrdir('source')
317
203
        repo = dir.create_repository()
 
204
        if not repo._format.supports_nesting_repositories:
 
205
            raise TestNotApplicable("repository format does not support "
 
206
                "nesting")
318
207
        repo.fetch(tree.branch.repository)
319
208
        self.assertTrue(repo.has_revision('1'))
320
209
        try:
321
210
            self.make_repository('target', shared=True)
322
211
        except errors.IncompatibleFormat:
323
 
            return
 
212
            raise TestNotApplicable("repository format does not support "
 
213
                "shared repositories")
324
214
        target = dir.clone(self.get_url('target/child'))
325
215
        self.assertNotEqual(dir.transport.base, target.transport.base)
326
216
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
330
220
        try:
331
221
            shared_repo = self.make_repository('shared', shared=True)
332
222
        except errors.IncompatibleFormat:
333
 
            return
 
223
            raise TestNotApplicable("repository format does not support "
 
224
                "shared repositories")
 
225
        if not shared_repo._format.supports_nesting_repositories:
 
226
            raise TestNotApplicable("format does not support nesting "
 
227
                "repositories")
334
228
        # Make a branch, 'commit_tree', and working tree outside of the shared
335
229
        # repository, and commit some revisions to it.
336
230
        tree = self.make_branch_and_tree('commit_tree')
337
231
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
338
232
        tree.add('foo')
339
233
        tree.commit('revision 1', rev_id='1')
340
 
        tree.bzrdir.open_branch().set_revision_history([])
 
234
        tree.bzrdir.open_branch().generate_revision_history(
 
235
            _mod_revision.NULL_REVISION)
341
236
        tree.set_parent_trees([])
342
237
        tree.commit('revision 2', rev_id='2')
343
238
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
360
255
        try:
361
256
            shared_repo = self.make_repository('shared', shared=True)
362
257
        except errors.IncompatibleFormat:
363
 
            return
 
258
            raise TestNotApplicable("repository format does not support "
 
259
                "shared repositories")
 
260
        if not shared_repo._format.supports_nesting_repositories:
 
261
            raise TestNotApplicable("format does not support nesting "
 
262
                "repositories")
364
263
        tree = self.make_branch_and_tree('commit_tree')
365
264
        self.build_tree(['commit_tree/foo'])
366
265
        tree.add('foo')
367
266
        tree.commit('revision 1', rev_id='1')
368
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
267
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
268
            _mod_revision.NULL_REVISION)
369
269
        tree.set_parent_trees([])
370
270
        tree.commit('revision 2', rev_id='2')
371
271
        tree.branch.repository.copy_content_into(shared_repo)
383
283
        self.assertFalse(branch.repository.make_working_trees())
384
284
        self.assertTrue(branch.repository.is_shared())
385
285
 
386
 
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
387
 
        tree = self.make_branch_and_tree('commit_tree')
388
 
        self.build_tree(['commit_tree/foo'])
389
 
        tree.add('foo')
390
 
        tree.commit('revision 1', rev_id='1')
391
 
        dir = self.make_bzrdir('source')
392
 
        repo = dir.create_repository()
393
 
        repo.fetch(tree.branch.repository)
394
 
        self.assertTrue(repo.has_revision('1'))
395
 
        try:
396
 
            self.make_repository('target', shared=True)
397
 
        except errors.IncompatibleFormat:
398
 
            return
399
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
400
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
401
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
402
 
                                    ['./.bzr/repository',
403
 
                                     ])
404
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
405
 
 
406
286
    def test_clone_bzrdir_repository_revision(self):
407
287
        # test for revision limiting, [smoke test, not corner case checks].
408
288
        # make a repository with some revisions,
412
292
        self.build_tree(['commit_tree/foo'])
413
293
        tree.add('foo')
414
294
        tree.commit('revision 1', rev_id='1')
415
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
295
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
296
            _mod_revision.NULL_REVISION)
416
297
        tree.set_parent_trees([])
417
298
        tree.commit('revision 2', rev_id='2')
418
299
        source = self.make_repository('source')
423
304
 
424
305
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
425
306
        # Bug #430868 is about an email containing '.sig'
426
 
        os.environ['BZR_EMAIL'] = 'murphy@host.sighup.org'
 
307
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
427
308
        tree = self.make_branch_and_tree('commit_tree')
428
309
        self.build_tree(['commit_tree/foo'])
429
310
        tree.add('foo')
442
323
            tree_repo.get_signature_text(rev1),
443
324
            target.repository.get_signature_text(rev1))
444
325
 
445
 
    def test_clone_bzrdir_branch_and_repo(self):
446
 
        tree = self.make_branch_and_tree('commit_tree')
447
 
        self.build_tree(['commit_tree/foo'])
448
 
        tree.add('foo')
449
 
        tree.commit('revision 1')
450
 
        source = self.make_branch('source')
451
 
        tree.branch.repository.copy_content_into(source.repository)
452
 
        tree.branch.copy_content_into(source)
453
 
        dir = source.bzrdir
454
 
        target = dir.clone(self.get_url('target'))
455
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
456
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
457
 
                                    [
458
 
                                     './.bzr/basis-inventory-cache',
459
 
                                     './.bzr/checkout/stat-cache',
460
 
                                     './.bzr/merge-hashes',
461
 
                                     './.bzr/repository',
462
 
                                     './.bzr/stat-cache',
463
 
                                    ])
464
 
        self.assertRepositoryHasSameItems(
465
 
            tree.branch.repository, target.open_repository())
466
 
 
467
326
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
468
327
        # by default cloning into a shared repo uses the shared repo.
469
328
        tree = self.make_branch_and_tree('commit_tree')
474
333
        tree.branch.repository.copy_content_into(source.repository)
475
334
        tree.branch.copy_content_into(source)
476
335
        try:
477
 
            self.make_repository('target', shared=True)
 
336
            shared_repo = self.make_repository('target', shared=True)
478
337
        except errors.IncompatibleFormat:
479
 
            return
 
338
            raise TestNotApplicable("repository format does not support "
 
339
                "shared repositories")
 
340
        if not shared_repo._format.supports_nesting_repositories:
 
341
            raise TestNotApplicable("format does not support nesting "
 
342
                "repositories")
480
343
        dir = source.bzrdir
481
344
        target = dir.clone(self.get_url('target/child'))
482
345
        self.assertNotEqual(dir.transport.base, target.transport.base)
483
346
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
484
 
        self.assertEqual(source.revision_history(),
485
 
                         target.open_branch().revision_history())
486
 
 
487
 
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
488
 
        # by default cloning into a shared repo uses the shared repo.
489
 
        tree = self.make_branch_and_tree('commit_tree')
490
 
        self.build_tree(['commit_tree/foo'])
491
 
        tree.add('foo')
492
 
        tree.commit('revision 1')
493
 
        source = self.make_branch('source')
494
 
        tree.branch.repository.copy_content_into(source.repository)
495
 
        tree.branch.copy_content_into(source)
496
 
        try:
497
 
            self.make_repository('target', shared=True)
498
 
        except errors.IncompatibleFormat:
499
 
            return
500
 
        dir = source.bzrdir
501
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
502
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
503
 
        repo = target.open_repository()
504
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
505
 
                                    ['./.bzr/repository',
506
 
                                     ])
507
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
508
 
 
509
 
    def test_clone_bzrdir_branch_reference(self):
510
 
        # cloning should preserve the reference status of the branch in a bzrdir
511
 
        referenced_branch = self.make_branch('referencced')
512
 
        dir = self.make_bzrdir('source')
513
 
        try:
514
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
515
 
                target_branch=referenced_branch)
516
 
        except errors.IncompatibleFormat:
517
 
            # this is ok too, not all formats have to support references.
518
 
            return
519
 
        target = dir.clone(self.get_url('target'))
520
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
521
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
347
        self.assertEqual(source.last_revision(),
 
348
                         target.open_branch().last_revision())
522
349
 
523
350
    def test_clone_bzrdir_branch_revision(self):
524
351
        # test for revision limiting, [smoke test, not corner case checks].
537
364
        target = dir.clone(self.get_url('target'), revision_id='1')
538
365
        self.assertEqual('1', target.open_branch().last_revision())
539
366
 
540
 
    def test_clone_bzrdir_tree_branch_repo(self):
541
 
        tree = self.make_branch_and_tree('source')
542
 
        self.build_tree(['source/foo'])
543
 
        tree.add('foo')
544
 
        tree.commit('revision 1')
545
 
        dir = tree.bzrdir
546
 
        target = dir.clone(self.get_url('target'))
547
 
        self.skipIfNoWorkingTree(target)
548
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
549
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
550
 
                                    ['./.bzr/stat-cache',
551
 
                                     './.bzr/checkout/dirstate',
552
 
                                     './.bzr/checkout/stat-cache',
553
 
                                     './.bzr/checkout/merge-hashes',
554
 
                                     './.bzr/merge-hashes',
555
 
                                     './.bzr/repository',
556
 
                                     ])
557
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
558
 
            target.open_repository())
559
 
        target.open_workingtree().revert()
560
 
 
561
367
    def test_clone_on_transport_preserves_repo_format(self):
562
 
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
 
368
        if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
563
369
            format = 'knit'
564
370
        else:
565
371
            format = None
577
383
            target_repo = target_repo._real_repository
578
384
        self.assertEqual(target_repo._format, source_branch.repository._format)
579
385
 
580
 
    def test_revert_inventory(self):
581
 
        tree = self.make_branch_and_tree('source')
582
 
        self.build_tree(['source/foo'])
583
 
        tree.add('foo')
584
 
        tree.commit('revision 1')
585
 
        dir = tree.bzrdir
586
 
        target = dir.clone(self.get_url('target'))
587
 
        self.skipIfNoWorkingTree(target)
588
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
589
 
                                    ['./.bzr/stat-cache',
590
 
                                     './.bzr/checkout/dirstate',
591
 
                                     './.bzr/checkout/stat-cache',
592
 
                                     './.bzr/checkout/merge-hashes',
593
 
                                     './.bzr/merge-hashes',
594
 
                                     './.bzr/repository',
595
 
                                     ])
596
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
597
 
            target.open_repository())
598
 
 
599
 
        target.open_workingtree().revert()
600
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
601
 
                                    ['./.bzr/stat-cache',
602
 
                                     './.bzr/checkout/dirstate',
603
 
                                     './.bzr/checkout/stat-cache',
604
 
                                     './.bzr/checkout/merge-hashes',
605
 
                                     './.bzr/merge-hashes',
606
 
                                     './.bzr/repository',
607
 
                                     ])
608
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
609
 
            target.open_repository())
610
 
 
611
 
    def test_clone_bzrdir_tree_branch_reference(self):
612
 
        # a tree with a branch reference (aka a checkout)
613
 
        # should stay a checkout on clone.
614
 
        referenced_branch = self.make_branch('referencced')
615
 
        dir = self.make_bzrdir('source')
616
 
        try:
617
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
618
 
                target_branch=referenced_branch)
619
 
        except errors.IncompatibleFormat:
620
 
            # this is ok too, not all formats have to support references.
621
 
            return
622
 
        self.createWorkingTreeOrSkip(dir)
623
 
        target = dir.clone(self.get_url('target'))
624
 
        self.skipIfNoWorkingTree(target)
625
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
626
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
627
 
                                    ['./.bzr/stat-cache',
628
 
                                     './.bzr/checkout/stat-cache',
629
 
                                     './.bzr/checkout/merge-hashes',
630
 
                                     './.bzr/merge-hashes',
631
 
                                     './.bzr/repository/inventory.knit',
632
 
                                     ])
633
 
 
634
386
    def test_clone_bzrdir_tree_revision(self):
635
387
        # test for revision limiting, [smoke test, not corner case checks].
636
388
        # make a tree with a revision with a last-revision
662
414
            repo.set_make_working_trees(False)
663
415
            self.assertFalse(repo.make_working_trees())
664
416
 
665
 
        dir = tree.bzrdir
666
 
        a_dir = dir.clone(self.get_url('repo/a'))
667
 
        a_dir.open_branch()
 
417
        a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
 
418
        a_branch = a_dir.open_branch()
 
419
        # If the new control dir actually uses the repository, it should
 
420
        # not have a working tree.
 
421
        if not a_branch.repository.has_same_location(repo):
 
422
            raise TestNotApplicable('new control dir does not use repository')
668
423
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
669
424
 
670
425
    def test_clone_respects_stacked(self):
671
426
        branch = self.make_branch('parent')
672
427
        child_transport = self.get_transport('child')
673
 
        child = branch.bzrdir.clone_on_transport(child_transport,
674
 
                                                 stacked_on=branch.base)
 
428
        try:
 
429
            child = branch.bzrdir.clone_on_transport(child_transport,
 
430
                                                     stacked_on=branch.base)
 
431
        except (errors.UnstackableBranchFormat,
 
432
                errors.UnstackableRepositoryFormat):
 
433
            raise TestNotApplicable("branch or repository format does "
 
434
                "not support stacking")
675
435
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
676
436
 
 
437
    def test_set_branch_reference(self):
 
438
        """set_branch_reference creates a branch reference"""
 
439
        referenced_branch = self.make_branch('referenced')
 
440
        dir = self.make_bzrdir('source')
 
441
        try:
 
442
            reference = dir.set_branch_reference(referenced_branch)
 
443
        except errors.IncompatibleFormat:
 
444
            # this is ok too, not all formats have to support references.
 
445
            raise TestNotApplicable("control directory does not "
 
446
                "support branch references")
 
447
        self.assertEqual(
 
448
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
449
            dir.get_branch_reference())
 
450
 
 
451
    def test_set_branch_reference_on_existing_reference(self):
 
452
        """set_branch_reference creates a branch reference"""
 
453
        referenced_branch1 = self.make_branch('old-referenced')
 
454
        referenced_branch2 = self.make_branch('new-referenced')
 
455
        dir = self.make_bzrdir('source')
 
456
        try:
 
457
            reference = dir.set_branch_reference(referenced_branch1)
 
458
        except errors.IncompatibleFormat:
 
459
            # this is ok too, not all formats have to support references.
 
460
            raise TestNotApplicable("control directory does not "
 
461
                "support branch references")
 
462
        reference = dir.set_branch_reference(referenced_branch2)
 
463
        self.assertEqual(
 
464
            referenced_branch2.bzrdir.root_transport.abspath('') + '/',
 
465
            dir.get_branch_reference())
 
466
 
 
467
    def test_set_branch_reference_on_existing_branch(self):
 
468
        """set_branch_reference creates a branch reference"""
 
469
        referenced_branch = self.make_branch('referenced')
 
470
        dir = self.make_branch('source').bzrdir
 
471
        try:
 
472
            reference = dir.set_branch_reference(referenced_branch)
 
473
        except errors.IncompatibleFormat:
 
474
            # this is ok too, not all formats have to support references.
 
475
            raise TestNotApplicable("control directory does not "
 
476
                "support branch references")
 
477
        self.assertEqual(
 
478
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
479
            dir.get_branch_reference())
 
480
 
677
481
    def test_get_branch_reference_on_reference(self):
678
482
        """get_branch_reference should return the right url."""
679
483
        referenced_branch = self.make_branch('referenced')
680
484
        dir = self.make_bzrdir('source')
681
485
        try:
682
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
683
 
                target_branch=referenced_branch)
 
486
            dir.set_branch_reference(referenced_branch)
684
487
        except errors.IncompatibleFormat:
685
488
            # this is ok too, not all formats have to support references.
686
 
            return
 
489
            raise TestNotApplicable("control directory does not "
 
490
                "support branch references")
687
491
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
688
492
            dir.get_branch_reference())
689
493
 
697
501
        dir = self.make_bzrdir('source')
698
502
        if dir.has_branch():
699
503
            # this format does not support branchless bzrdirs.
700
 
            return
 
504
            raise TestNotApplicable("format does not support "
 
505
                "branchless control directories")
701
506
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
702
507
 
703
508
    def test_sprout_bzrdir_empty(self):
704
509
        dir = self.make_bzrdir('source')
705
510
        target = dir.sprout(self.get_url('target'))
706
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
511
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
707
512
        # creates a new repository branch and tree
708
513
        target.open_repository()
709
514
        target.open_branch()
715
520
        try:
716
521
            self.make_repository('target', shared=True)
717
522
        except errors.IncompatibleFormat:
718
 
            return
 
523
            raise TestNotApplicable("format does not support shared "
 
524
                "repositories")
719
525
        target = dir.sprout(self.get_url('target/child'))
720
526
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
721
527
        target.open_branch()
722
528
        try:
723
529
            target.open_workingtree()
724
530
        except errors.NoWorkingTree:
725
 
            # bzrdir's that never have working trees are allowed to pass;
726
 
            # whitelist them for now.
727
 
            self.assertIsInstance(target, RemoteBzrDir)
 
531
            # Some bzrdirs can never have working trees.
 
532
            repo = target.find_repository()
 
533
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
728
534
 
729
535
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
730
536
        # the force_new_repo parameter should force use of a new repo in an empty
733
539
        try:
734
540
            self.make_repository('target', shared=True)
735
541
        except errors.IncompatibleFormat:
736
 
            return
 
542
            raise TestNotApplicable("format does not support shared "
 
543
                "repositories")
737
544
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
738
545
        target.open_repository()
739
546
        target.open_branch()
740
547
        self.openWorkingTreeIfLocal(target)
741
548
 
742
 
    def test_sprout_bzrdir_repository(self):
743
 
        tree = self.make_branch_and_tree('commit_tree')
744
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
745
 
        tree.add('foo')
746
 
        tree.commit('revision 1', rev_id='1')
747
 
        dir = self.make_bzrdir('source')
748
 
        repo = dir.create_repository()
749
 
        repo.fetch(tree.branch.repository)
750
 
        self.assertTrue(repo.has_revision('1'))
751
 
        try:
752
 
            self.assertTrue(
753
 
                _mod_revision.is_null(_mod_revision.ensure_null(
754
 
                dir.open_branch().last_revision())))
755
 
        except errors.NotBranchError:
756
 
            pass
757
 
        target = dir.sprout(self.get_url('target'))
758
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
759
 
        # testing inventory isn't reasonable for repositories
760
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
761
 
                                    [
762
 
                                     './.bzr/branch',
763
 
                                     './.bzr/checkout',
764
 
                                     './.bzr/inventory',
765
 
                                     './.bzr/parent',
766
 
                                     './.bzr/repository/inventory.knit',
767
 
                                     ])
768
 
        try:
769
 
            local_inventory = dir.transport.local_abspath('inventory')
770
 
        except errors.NotLocalUrl:
771
 
            return
772
 
        try:
773
 
            # If we happen to have a tree, we'll guarantee everything
774
 
            # except for the tree root is the same.
775
 
            inventory_f = file(local_inventory, 'rb')
776
 
            self.addCleanup(inventory_f.close)
777
 
            self.assertContainsRe(inventory_f.read(),
778
 
                                  '<inventory format="5">\n</inventory>\n')
779
 
        except IOError, e:
780
 
            if e.errno != errno.ENOENT:
781
 
                raise
782
 
 
783
549
    def test_sprout_bzrdir_with_repository_to_shared(self):
784
550
        tree = self.make_branch_and_tree('commit_tree')
785
551
        self.build_tree(['commit_tree/foo'])
786
552
        tree.add('foo')
787
553
        tree.commit('revision 1', rev_id='1')
788
 
        tree.bzrdir.open_branch().set_revision_history([])
 
554
        tree.bzrdir.open_branch().generate_revision_history(
 
555
            _mod_revision.NULL_REVISION)
789
556
        tree.set_parent_trees([])
790
557
        tree.commit('revision 2', rev_id='2')
791
558
        source = self.make_repository('source')
794
561
        try:
795
562
            shared_repo = self.make_repository('target', shared=True)
796
563
        except errors.IncompatibleFormat:
797
 
            return
 
564
            raise TestNotApplicable("format does not support "
 
565
                "shared repositories")
798
566
        target = dir.sprout(self.get_url('target/child'))
799
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
567
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
800
568
        self.assertTrue(shared_repo.has_revision('1'))
801
569
 
802
570
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
803
571
        try:
804
572
            shared_repo = self.make_repository('shared', shared=True)
805
573
        except errors.IncompatibleFormat:
806
 
            return
 
574
            raise TestNotApplicable("format does not support shared "
 
575
                "repositories")
 
576
        if not shared_repo._format.supports_nesting_repositories:
 
577
            raise TestNotApplicable("format does not support nesting "
 
578
                "repositories")
807
579
        tree = self.make_branch_and_tree('commit_tree')
808
580
        self.build_tree(['commit_tree/foo'])
809
581
        tree.add('foo')
810
582
        tree.commit('revision 1', rev_id='1')
811
 
        tree.bzrdir.open_branch().set_revision_history([])
 
583
        tree.bzrdir.open_branch().generate_revision_history(
 
584
            _mod_revision.NULL_REVISION)
812
585
        tree.set_parent_trees([])
813
586
        tree.commit('revision 2', rev_id='2')
814
587
        tree.branch.repository.copy_content_into(shared_repo)
823
596
        try:
824
597
            shared_repo = self.make_repository('shared', shared=True)
825
598
        except errors.IncompatibleFormat:
826
 
            return
 
599
            raise TestNotApplicable("format does not support shared "
 
600
                "repositories")
 
601
        if not shared_repo._format.supports_nesting_repositories:
 
602
            raise TestNotApplicable("format does not support nesting "
 
603
                "repositories")
827
604
        tree = self.make_branch_and_tree('commit_tree')
828
605
        self.build_tree(['commit_tree/foo'])
829
606
        tree.add('foo')
830
607
        tree.commit('revision 1', rev_id='1')
831
 
        tree.bzrdir.open_branch().set_revision_history([])
 
608
        tree.bzrdir.open_branch().generate_revision_history(
 
609
            _mod_revision.NULL_REVISION)
832
610
        tree.set_parent_trees([])
833
611
        tree.commit('revision 2', rev_id='2')
834
612
        tree.branch.repository.copy_content_into(shared_repo)
842
620
        self.assertNotEqual(dir.transport.base, target.transport.base)
843
621
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
844
622
        branch = target.open_branch()
845
 
        self.assertTrue(branch.repository.has_revision('1'))
846
 
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
623
        # The sprouted bzrdir has a branch, so only revisions referenced by
 
624
        # that branch are copied, rather than the whole repository.  It's an
 
625
        # empty branch, so none are copied.
 
626
        self.assertEqual([], branch.repository.all_revision_ids())
 
627
        if branch.bzrdir._format.supports_workingtrees:
847
628
            self.assertTrue(branch.repository.make_working_trees())
848
629
        self.assertFalse(branch.repository.is_shared())
849
630
 
852
633
        self.build_tree(['commit_tree/foo'])
853
634
        tree.add('foo')
854
635
        tree.commit('revision 1', rev_id='1')
855
 
        tree.bzrdir.open_branch().set_revision_history([])
 
636
        tree.bzrdir.open_branch().generate_revision_history(
 
637
            _mod_revision.NULL_REVISION)
856
638
        tree.set_parent_trees([])
857
639
        tree.commit('revision 2', rev_id='2')
858
640
        source = self.make_repository('source')
861
643
        try:
862
644
            shared_repo = self.make_repository('target', shared=True)
863
645
        except errors.IncompatibleFormat:
864
 
            return
 
646
            raise TestNotApplicable("format does not support shared "
 
647
                "repositories")
865
648
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
866
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
649
        self.assertNotEqual(
 
650
            dir.control_transport.base,
 
651
            target.control_transport.base)
867
652
        self.assertFalse(shared_repo.has_revision('1'))
868
653
 
869
654
    def test_sprout_bzrdir_repository_revision(self):
875
660
        self.build_tree(['commit_tree/foo'])
876
661
        tree.add('foo')
877
662
        tree.commit('revision 1', rev_id='1')
878
 
        tree.bzrdir.open_branch().set_revision_history([])
 
663
        br = tree.bzrdir.open_branch()
 
664
        br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
879
665
        tree.set_parent_trees([])
880
666
        tree.commit('revision 2', rev_id='2')
881
667
        source = self.make_repository('source')
884
670
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
885
671
        raise TestSkipped('revision limiting not strict yet')
886
672
 
887
 
    def test_sprout_bzrdir_branch_and_repo(self):
888
 
        tree = self.make_branch_and_tree('commit_tree')
889
 
        self.build_tree(['commit_tree/foo'])
890
 
        tree.add('foo')
891
 
        tree.commit('revision 1')
892
 
        source = self.make_branch('source')
893
 
        tree.branch.repository.copy_content_into(source.repository)
894
 
        tree.bzrdir.open_branch().copy_content_into(source)
895
 
        dir = source.bzrdir
896
 
        target = dir.sprout(self.get_url('target'))
897
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
898
 
        target_repo = target.open_repository()
899
 
        self.assertRepositoryHasSameItems(source.repository, target_repo)
900
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
901
 
                                    [
902
 
                                     './.bzr/basis-inventory-cache',
903
 
                                     './.bzr/branch/branch.conf',
904
 
                                     './.bzr/branch/parent',
905
 
                                     './.bzr/checkout',
906
 
                                     './.bzr/checkout/inventory',
907
 
                                     './.bzr/checkout/stat-cache',
908
 
                                     './.bzr/inventory',
909
 
                                     './.bzr/parent',
910
 
                                     './.bzr/repository',
911
 
                                     './.bzr/stat-cache',
912
 
                                     './foo',
913
 
                                     ])
914
 
 
915
673
    def test_sprout_bzrdir_branch_and_repo_shared(self):
916
674
        # sprouting a branch with a repo into a shared repo uses the shared
917
675
        # repo
926
684
        try:
927
685
            shared_repo = self.make_repository('target', shared=True)
928
686
        except errors.IncompatibleFormat:
929
 
            return
 
687
            raise TestNotApplicable("format does not support shared "
 
688
                "repositories")
930
689
        target = dir.sprout(self.get_url('target/child'))
931
690
        self.assertTrue(shared_repo.has_revision('1'))
932
691
 
944
703
        try:
945
704
            shared_repo = self.make_repository('target', shared=True)
946
705
        except errors.IncompatibleFormat:
947
 
            return
 
706
            raise TestNotApplicable("format does not support shared "
 
707
                "repositories")
948
708
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
949
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
709
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
950
710
        self.assertFalse(shared_repo.has_revision('1'))
951
711
 
952
712
    def test_sprout_bzrdir_branch_reference(self):
954
714
        referenced_branch = self.make_branch('referenced')
955
715
        dir = self.make_bzrdir('source')
956
716
        try:
957
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
958
 
                target_branch=referenced_branch)
 
717
            dir.set_branch_reference(referenced_branch)
959
718
        except errors.IncompatibleFormat:
960
 
            # this is ok too, not all formats have to support references.
961
 
            return
 
719
            raise TestNotApplicable("format does not support branch "
 
720
                "references")
962
721
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
963
722
        target = dir.sprout(self.get_url('target'))
964
723
        self.assertNotEqual(dir.transport.base, target.transport.base)
974
733
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
975
734
        dir = self.make_bzrdir('source')
976
735
        try:
977
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
978
 
                target_branch=referenced_tree.branch)
 
736
            dir.set_branch_reference(referenced_tree.branch)
979
737
        except errors.IncompatibleFormat:
980
 
            # this is ok too, not all formats have to support references.
981
 
            return
 
738
            raise TestNotApplicable("format does not support branch "
 
739
                "references")
982
740
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
983
741
        try:
984
742
            shared_repo = self.make_repository('target', shared=True)
985
743
        except errors.IncompatibleFormat:
986
 
            return
 
744
            raise TestNotApplicable("format does not support "
 
745
                "shared repositories")
987
746
        target = dir.sprout(self.get_url('target/child'))
988
747
        self.assertNotEqual(dir.transport.base, target.transport.base)
989
748
        # we want target to have a branch that is in-place.
1000
759
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
1001
760
        dir = self.make_bzrdir('source')
1002
761
        try:
1003
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1004
 
                target_branch=referenced_tree.branch)
 
762
            dir.set_branch_reference(referenced_tree.branch)
1005
763
        except errors.IncompatibleFormat:
1006
764
            # this is ok too, not all formats have to support references.
1007
 
            return
 
765
            raise TestNotApplicable("format does not support "
 
766
                "branch references")
1008
767
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1009
768
        try:
1010
769
            shared_repo = self.make_repository('target', shared=True)
1011
770
        except errors.IncompatibleFormat:
1012
 
            return
 
771
            raise TestNotApplicable("format does not support shared "
 
772
                "repositories")
1013
773
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1014
774
        self.assertNotEqual(dir.transport.base, target.transport.base)
1015
775
        # we want target to have a branch that is in-place.
1036
796
        target = dir.sprout(self.get_url('target'), revision_id='1')
1037
797
        self.assertEqual('1', target.open_branch().last_revision())
1038
798
 
1039
 
    def test_sprout_bzrdir_tree_branch_repo(self):
1040
 
        tree = self.make_branch_and_tree('source')
1041
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1042
 
        tree.add('foo')
1043
 
        tree.commit('revision 1')
1044
 
        dir = tree.bzrdir
1045
 
        target = self.sproutOrSkip(dir, self.get_url('target'))
1046
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
1047
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1048
 
                                    [
1049
 
                                     './.bzr/branch/branch.conf',
1050
 
                                     './.bzr/branch/parent',
1051
 
                                     './.bzr/checkout/dirstate',
1052
 
                                     './.bzr/checkout/stat-cache',
1053
 
                                     './.bzr/checkout/inventory',
1054
 
                                     './.bzr/inventory',
1055
 
                                     './.bzr/parent',
1056
 
                                     './.bzr/repository',
1057
 
                                     './.bzr/stat-cache',
1058
 
                                     ])
1059
 
        self.assertRepositoryHasSameItems(
1060
 
            tree.branch.repository, target.open_repository())
 
799
    def test_sprout_bzrdir_branch_with_tags(self):
 
800
        # when sprouting a branch all revisions named in the tags are copied
 
801
        # too.
 
802
        builder = self.make_branch_builder('source')
 
803
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
804
        try:
 
805
            source.tags.set_tag('tag-a', 'rev-2')
 
806
        except errors.TagsNotSupported:
 
807
            raise TestNotApplicable('Branch format does not support tags.')
 
808
        source.get_config_stack().set('branch.fetch_tags', True)
 
809
        # Now source has a tag not in its ancestry.  Sprout its controldir.
 
810
        dir = source.bzrdir
 
811
        target = dir.sprout(self.get_url('target'))
 
812
        # The tag is present, and so is its revision.
 
813
        new_branch = target.open_branch()
 
814
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
815
        new_branch.repository.get_revision('rev-2')
 
816
 
 
817
    def test_sprout_bzrdir_branch_with_absent_tag(self):
 
818
        # tags referencing absent revisions are copied (and those absent
 
819
        # revisions do not prevent the sprout.)
 
820
        builder = self.make_branch_builder('source')
 
821
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
822
        source = builder.get_branch()
 
823
        try:
 
824
            source.tags.set_tag('tag-a', 'missing-rev')
 
825
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
826
            raise TestNotApplicable('Branch format does not support tags '
 
827
                'or tags referencing ghost revisions.')
 
828
        # Now source has a tag pointing to an absent revision.  Sprout its
 
829
        # controldir.
 
830
        dir = source.bzrdir
 
831
        target = dir.sprout(self.get_url('target'))
 
832
        # The tag is present in the target
 
833
        new_branch = target.open_branch()
 
834
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
835
 
 
836
    def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
 
837
        # tags referencing absent revisions are copied (and those absent
 
838
        # revisions do not prevent the sprout.)
 
839
        builder = self.make_branch_builder('source')
 
840
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
841
        source = builder.get_branch()
 
842
        try:
 
843
            source.tags.set_tag('tag-a', 'missing-rev')
 
844
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
845
            raise TestNotApplicable('Branch format does not support tags '
 
846
                'or tags referencing missing revisions.')
 
847
        # Now source has a tag pointing to an absent revision.  Sprout its
 
848
        # controldir.
 
849
        dir = source.bzrdir
 
850
        target = dir.sprout(self.get_url('target'), source_branch=source)
 
851
        # The tag is present in the target
 
852
        new_branch = target.open_branch()
 
853
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
854
 
 
855
    def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
 
856
        # dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
 
857
        # the branch at that bzrdir, the ancestry of all of those, but no other
 
858
        # revs (not even the tip of the source branch).
 
859
        builder = self.make_branch_builder('source')
 
860
        builder.build_commit(message="Base", rev_id='base-rev')
 
861
        # Make three parallel lines of ancestry off this base.
 
862
        source = builder.get_branch()
 
863
        builder.build_commit(message="Rev A1", rev_id='rev-a1')
 
864
        builder.build_commit(message="Rev A2", rev_id='rev-a2')
 
865
        builder.build_commit(message="Rev A3", rev_id='rev-a3')
 
866
        source.set_last_revision_info(1, 'base-rev')
 
867
        builder.build_commit(message="Rev B1", rev_id='rev-b1')
 
868
        builder.build_commit(message="Rev B2", rev_id='rev-b2')
 
869
        builder.build_commit(message="Rev B3", rev_id='rev-b3')
 
870
        source.set_last_revision_info(1, 'base-rev')
 
871
        builder.build_commit(message="Rev C1", rev_id='rev-c1')
 
872
        builder.build_commit(message="Rev C2", rev_id='rev-c2')
 
873
        builder.build_commit(message="Rev C3", rev_id='rev-c3')
 
874
        # Set the branch tip to A2
 
875
        source.set_last_revision_info(3, 'rev-a2')
 
876
        try:
 
877
            # Create a tag for B2, and for an absent rev
 
878
            source.tags.set_tag('tag-non-ancestry', 'rev-b2')
 
879
        except errors.TagsNotSupported:
 
880
            raise TestNotApplicable('Branch format does not support tags ')
 
881
        try:
 
882
            source.tags.set_tag('tag-absent', 'absent-rev')
 
883
        except errors.GhostTagsNotSupported:
 
884
            has_ghost_tag = False
 
885
        else:
 
886
            has_ghost_tag = True
 
887
        source.get_config_stack().set('branch.fetch_tags', True)
 
888
        # And ask sprout for C2
 
889
        dir = source.bzrdir
 
890
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
 
891
        # The tags are present
 
892
        new_branch = target.open_branch()
 
893
        if has_ghost_tag:
 
894
            self.assertEqual(
 
895
                {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
 
896
                new_branch.tags.get_tag_dict())
 
897
        else:
 
898
            self.assertEqual(
 
899
                {'tag-non-ancestry': 'rev-b2'},
 
900
                new_branch.tags.get_tag_dict())
 
901
        # And the revs for A2, B2 and C2's ancestries are present, but no
 
902
        # others.
 
903
        self.assertEqual(
 
904
            ['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
 
905
            sorted(new_branch.repository.all_revision_ids()))
1061
906
 
1062
907
    def test_sprout_bzrdir_tree_branch_reference(self):
1063
908
        # sprouting should create a repository if needed and a sprouted branch.
1065
910
        referenced_branch = self.make_branch('referencced')
1066
911
        dir = self.make_bzrdir('source')
1067
912
        try:
1068
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1069
 
                target_branch=referenced_branch)
 
913
            dir.set_branch_reference(referenced_branch)
1070
914
        except errors.IncompatibleFormat:
1071
915
            # this is ok too, not all formats have to support references.
1072
 
            return
 
916
            raise TestNotApplicable("format does not support "
 
917
                "branch references")
1073
918
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1074
919
        tree = self.createWorkingTreeOrSkip(dir)
1075
920
        self.build_tree(['source/subdir/'])
1091
936
        referenced_branch = self.make_branch('referencced')
1092
937
        dir = self.make_bzrdir('source')
1093
938
        try:
1094
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1095
 
                target_branch=referenced_branch)
 
939
            dir.set_branch_reference(referenced_branch)
1096
940
        except errors.IncompatibleFormat:
1097
941
            # this is ok too, not all formats have to support references.
1098
 
            return
 
942
            raise TestNotApplicable("format does not support "
 
943
                "branch references")
1099
944
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1100
945
        tree = self.createWorkingTreeOrSkip(dir)
1101
946
        self.build_tree(['source/foo'])
1147
992
        tree.commit('revision 1', rev_id='1')
1148
993
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1149
994
        dir = tree.bzrdir
1150
 
        if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
1151
 
            self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
1152
 
                              self.get_url('target'),
1153
 
                              create_tree_if_local=False)
1154
 
            return
1155
 
        target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
1156
 
        self.failIfExists('target/foo')
 
995
        try:
 
996
            target = dir.sprout(self.get_url('target'),
 
997
                create_tree_if_local=False)
 
998
        except errors.MustHaveWorkingTree:
 
999
            raise TestNotApplicable("control dir format requires working tree")
 
1000
        self.assertPathDoesNotExist('target/foo')
1157
1001
        self.assertEqual(tree.branch.last_revision(),
1158
1002
                         target.open_branch().last_revision())
1159
1003
 
1182
1026
 
1183
1027
    def test_format_initialize_find_open(self):
1184
1028
        # loopback test to check the current format initializes to itself.
1185
 
        if not self.bzrdir_format.is_supported():
 
1029
        if not self.bzrdir_format.is_initializable():
1186
1030
            # unsupported formats are not loopback testable
1187
1031
            # because the default open will not open them and
1188
1032
            # they may not be initializable.
1189
 
            return
 
1033
            raise TestNotApplicable("format is not initializable")
1190
1034
        # for remote formats, there must be no prior assumption about the
1191
1035
        # network name to use - it's possible that this may somehow have got
1192
1036
        # in through an unisolated test though - see
1195
1039
            '_network_name', None),
1196
1040
            None)
1197
1041
        # supported formats must be able to init and open
1198
 
        t = transport.get_transport(self.get_url())
1199
 
        readonly_t = transport.get_transport(self.get_readonly_url())
 
1042
        t = self.get_transport()
 
1043
        readonly_t = self.get_readonly_transport()
1200
1044
        made_control = self.bzrdir_format.initialize(t.base)
1201
 
        self.failUnless(isinstance(made_control, controldir.ControlDir))
 
1045
        self.assertIsInstance(made_control, controldir.ControlDir)
 
1046
        if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
 
1047
            return
1202
1048
        self.assertEqual(self.bzrdir_format,
1203
1049
                         controldir.ControlDirFormat.find_format(readonly_t))
1204
1050
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1205
 
        opened_dir = bzrdir.BzrDir.open(t.base)
 
1051
        opened_dir = controldir.ControlDir.open(t.base)
1206
1052
        self.assertEqual(made_control._format,
1207
1053
                         opened_dir._format)
1208
1054
        self.assertEqual(direct_opened_dir._format,
1209
1055
                         opened_dir._format)
1210
 
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
 
1056
        self.assertIsInstance(opened_dir, controldir.ControlDir)
1211
1057
 
1212
1058
    def test_format_initialize_on_transport_ex(self):
1213
1059
        t = self.get_transport('dir')
1219
1065
        self.assertInitializeEx(t, use_existing_dir=True)
1220
1066
 
1221
1067
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
1222
 
        if not self.bzrdir_format.is_supported():
1223
 
            # Not initializable - not a failure either.
1224
 
            return
 
1068
        if not self.bzrdir_format.is_initializable():
 
1069
            raise TestNotApplicable("format is not initializable")
1225
1070
        t = self.get_transport('dir')
1226
1071
        t.ensure_base()
1227
1072
        self.assertRaises(errors.FileExists,
1233
1078
        self.assertInitializeEx(t, create_prefix=True)
1234
1079
 
1235
1080
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
1236
 
        if not self.bzrdir_format.is_supported():
1237
 
            # Not initializable - not a failure either.
1238
 
            return
 
1081
        if not self.bzrdir_format.is_initializable():
 
1082
            raise TestNotApplicable("format is not initializable")
1239
1083
        t = self.get_transport('missing/dir')
1240
1084
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1241
1085
            create_prefix=False)
1242
1086
 
1243
1087
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1244
1088
        t = self.get_transport('repo')
1245
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1089
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1246
1090
        repo_name = repo_fmt.repository_format.network_name()
1247
1091
        repo = repo_fmt.initialize_on_transport_ex(t,
1248
1092
            repo_format_name=repo_name, shared_repo=True)[0]
1249
1093
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1250
1094
            force_new_repo=True, repo_format_name=repo_name)
1251
 
        if control is None:
1252
 
            # uninitialisable format
1253
 
            return
1254
1095
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1255
1096
            made_repo.bzrdir.root_transport.base)
1256
1097
 
1257
1098
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1258
1099
        t = self.get_transport('repo')
1259
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1100
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1260
1101
        repo_name = repo_fmt.repository_format.network_name()
1261
1102
        repo = repo_fmt.initialize_on_transport_ex(t,
1262
1103
            repo_format_name=repo_name, shared_repo=True)[0]
1263
1104
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1264
1105
            force_new_repo=False, repo_format_name=repo_name)
1265
 
        if control is None:
1266
 
            # uninitialisable format
1267
 
            return
1268
 
        if not isinstance(control._format, (bzrdir.BzrDirFormat5,
1269
 
            bzrdir.BzrDirFormat6,)):
 
1106
        if not control._format.fixed_components:
1270
1107
            self.assertEqual(repo.bzrdir.root_transport.base,
1271
1108
                made_repo.bzrdir.root_transport.base)
1272
1109
 
1273
 
    def test_format_initialize_on_transport_ex_stacked_on(self):
1274
 
        # trunk is a stackable format.  Note that its in the same server area
1275
 
        # which is what launchpad does, but not sufficient to exercise the
1276
 
        # general case.
1277
 
        trunk = self.make_branch('trunk', format='1.9')
1278
 
        t = self.get_transport('stacked')
1279
 
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1280
 
        repo_name = old_fmt.repository_format.network_name()
1281
 
        # Should end up with a 1.9 format (stackable)
1282
 
        repo, control = self.assertInitializeEx(t, need_meta=True,
1283
 
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
1284
 
        if control is None:
1285
 
            # uninitialisable format
1286
 
            return
1287
 
        self.assertLength(1, repo._fallback_repositories)
1288
 
 
1289
 
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1290
 
        # When initialize_on_transport_ex uses a stacked-on branch because of
1291
 
        # a stacking policy on the target, the location of the fallback
1292
 
        # repository is the same as the external location of the stacked-on
1293
 
        # branch.
1294
 
        balloon = self.make_bzrdir('balloon')
1295
 
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1296
 
            stack_on = self.make_branch('stack-on', format='1.9')
1297
 
        else:
1298
 
            stack_on = self.make_branch('stack-on')
1299
 
        config = self.make_bzrdir('.').get_config()
1300
 
        try:
1301
 
            config.set_default_stack_on('stack-on')
1302
 
        except errors.BzrError:
1303
 
            raise TestNotApplicable('Only relevant for stackable formats.')
1304
 
        # Initialize a bzrdir subject to the policy.
1305
 
        t = self.get_transport('stacked')
1306
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1307
 
        repo_name = repo_fmt.repository_format.network_name()
1308
 
        repo, control = self.assertInitializeEx(
1309
 
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1310
 
        # self.addCleanup(repo.unlock)
1311
 
        if control is None:
1312
 
            # uninitialisable format
1313
 
            return
1314
 
        # There's one fallback repo, with a public location.
1315
 
        self.assertLength(1, repo._fallback_repositories)
1316
 
        fallback_repo = repo._fallback_repositories[0]
1317
 
        self.assertEqual(
1318
 
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
1319
 
        # The bzrdir creates a branch in stacking-capable format.
1320
 
        new_branch = control.create_branch()
1321
 
        self.assertTrue(new_branch._format.supports_stacking())
1322
 
 
1323
1110
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1324
1111
        t = self.get_transport('dir')
1325
1112
        repo, control = self.assertInitializeEx(t)
1328
1115
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1329
1116
        t = self.get_transport('dir')
1330
1117
        # 1.6 is likely to never be default
1331
 
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
 
1118
        fmt = controldir.format_registry.make_bzrdir('1.6')
1332
1119
        repo_name = fmt.repository_format.network_name()
1333
1120
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1334
 
        if control is None:
1335
 
            # uninitialisable format
1336
 
            return
1337
 
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
1338
 
            bzrdir.BzrDirFormat6)):
 
1121
        if self.bzrdir_format.fixed_components:
1339
1122
            # must stay with the all-in-one-format.
1340
1123
            repo_name = self.bzrdir_format.network_name()
1341
1124
        self.assertEqual(repo_name, repo._format.network_name())
1342
1125
 
1343
 
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
1126
    def assertInitializeEx(self, t, **kwargs):
1344
1127
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1345
1128
 
1346
1129
        This involves checking that the disk objects were created, open with
1351
1134
            initialize_on_transport_ex.
1352
1135
        :return: the resulting repo, control dir tuple.
1353
1136
        """
1354
 
        if not self.bzrdir_format.is_supported():
1355
 
            # Not initializable - not a failure either.
1356
 
            return None, None
 
1137
        if not self.bzrdir_format.is_initializable():
 
1138
            raise TestNotApplicable("control dir format is not "
 
1139
                "initializable")
1357
1140
        repo, control, require_stacking, repo_policy = \
1358
1141
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1359
1142
        if repo is not None:
1360
1143
            # Repositories are open write-locked
1361
1144
            self.assertTrue(repo.is_write_locked())
1362
1145
            self.addCleanup(repo.unlock)
1363
 
        self.assertIsInstance(control, bzrdir.BzrDir)
1364
 
        opened = bzrdir.BzrDir.open(t.base)
 
1146
        self.assertIsInstance(control, controldir.ControlDir)
 
1147
        opened = controldir.ControlDir.open(t.base)
1365
1148
        expected_format = self.bzrdir_format
1366
 
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
1367
 
            # Current RemoteBzrDirFormat's do not reliably get network_name
1368
 
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
1369
 
            self.assertIsInstance(control, RemoteBzrDir)
1370
 
        else:
1371
 
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1372
 
                bzrdir.BzrDirFormat6)):
1373
 
                # Pre-metadir formats change when we are making something that
1374
 
                # needs a metaformat, because clone is used for push.
1375
 
                expected_format = bzrdir.BzrDirMetaFormat1()
 
1149
        if not isinstance(expected_format, RemoteBzrDirFormat):
1376
1150
            self.assertEqual(control._format.network_name(),
1377
1151
                expected_format.network_name())
1378
1152
            self.assertEqual(control._format.network_name(),
1389
1163
        # key in the registry gives back the same format. For remote obects
1390
1164
        # we check that the network_name of the RemoteBzrDirFormat we have
1391
1165
        # locally matches the actual format present on disk.
1392
 
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
 
1166
        if isinstance(format, RemoteBzrDirFormat):
1393
1167
            dir._ensure_real()
1394
1168
            real_dir = dir._real_bzrdir
1395
1169
            network_name = format.network_name()
1396
1170
            self.assertEqual(real_dir._format.network_name(), network_name)
1397
1171
        else:
1398
 
            registry = bzrdir.network_format_registry
 
1172
            registry = controldir.network_format_registry
1399
1173
            network_name = format.network_name()
1400
1174
            looked_up_format = registry.get(network_name)
1401
 
            self.assertEqual(format.__class__, looked_up_format.__class__)
 
1175
            self.assertTrue(
 
1176
                issubclass(format.__class__, looked_up_format.__class__))
1402
1177
        # The network name must be a byte string.
1403
1178
        self.assertIsInstance(network_name, str)
1404
1179
 
1405
1180
    def test_open_not_bzrdir(self):
1406
1181
        # test the formats specific behaviour for no-content or similar dirs.
1407
 
        self.assertRaises(NotBranchError,
 
1182
        self.assertRaises(errors.NotBranchError,
1408
1183
                          self.bzrdir_format.open,
1409
 
                          transport.get_transport(self.get_readonly_url()))
 
1184
                          transport.get_transport_from_url(self.get_readonly_url()))
1410
1185
 
1411
1186
    def test_create_branch(self):
1412
1187
        # a bzrdir can construct a branch and repository for itself.
1413
 
        if not self.bzrdir_format.is_supported():
 
1188
        if not self.bzrdir_format.is_initializable():
1414
1189
            # unsupported formats are not loopback testable
1415
1190
            # because the default open will not open them and
1416
1191
            # they may not be initializable.
1417
 
            return
1418
 
        t = transport.get_transport(self.get_url())
 
1192
            raise TestNotApplicable("format is not initializable")
 
1193
        t = self.get_transport()
1419
1194
        made_control = self.bzrdir_format.initialize(t.base)
1420
1195
        made_repo = made_control.create_repository()
1421
1196
        made_branch = made_control.create_branch()
1422
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
1197
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
 
1198
        self.assertEqual(made_control, made_branch.bzrdir)
 
1199
 
 
1200
    def test_create_branch_append_revisions_only(self):
 
1201
        # a bzrdir can construct a branch and repository for itself.
 
1202
        if not self.bzrdir_format.is_initializable():
 
1203
            # unsupported formats are not loopback testable
 
1204
            # because the default open will not open them and
 
1205
            # they may not be initializable.
 
1206
            raise TestNotApplicable("format is not initializable")
 
1207
        t = self.get_transport()
 
1208
        made_control = self.bzrdir_format.initialize(t.base)
 
1209
        made_repo = made_control.create_repository()
 
1210
        try:
 
1211
            made_branch = made_control.create_branch(
 
1212
                append_revisions_only=True)
 
1213
        except errors.UpgradeRequired:
 
1214
            raise TestNotApplicable("format does not support "
 
1215
                "append_revisions_only setting")
 
1216
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
 
1217
        self.assertEquals(True, made_branch.get_append_revisions_only())
1423
1218
        self.assertEqual(made_control, made_branch.bzrdir)
1424
1219
 
1425
1220
    def test_open_branch(self):
1426
 
        if not self.bzrdir_format.is_supported():
 
1221
        if not self.bzrdir_format.is_initializable():
1427
1222
            # unsupported formats are not loopback testable
1428
1223
            # because the default open will not open them and
1429
1224
            # they may not be initializable.
1430
 
            return
1431
 
        t = transport.get_transport(self.get_url())
 
1225
            raise TestNotApplicable("format is not initializable")
 
1226
        t = self.get_transport()
1432
1227
        made_control = self.bzrdir_format.initialize(t.base)
1433
1228
        made_repo = made_control.create_repository()
1434
1229
        made_branch = made_control.create_branch()
1435
1230
        opened_branch = made_control.open_branch()
1436
1231
        self.assertEqual(made_control, opened_branch.bzrdir)
1437
 
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1438
 
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
 
1232
        self.assertIsInstance(opened_branch, made_branch.__class__)
 
1233
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1439
1234
 
1440
1235
    def test_list_branches(self):
1441
 
        if not self.bzrdir_format.is_supported():
1442
 
            # unsupported formats are not loopback testable
1443
 
            # because the default open will not open them and
1444
 
            # they may not be initializable.
1445
 
            return
1446
 
        t = transport.get_transport(self.get_url())
 
1236
        if not self.bzrdir_format.is_initializable():
 
1237
            raise TestNotApplicable("format is not initializable")
 
1238
        t = self.get_transport()
1447
1239
        made_control = self.bzrdir_format.initialize(t.base)
1448
1240
        made_repo = made_control.create_repository()
1449
1241
        made_branch = made_control.create_branch()
1457
1249
        else:
1458
1250
            self.assertEquals([], made_control.list_branches())
1459
1251
 
 
1252
    def test_get_branches(self):
 
1253
        repo = self.make_repository('branch-1')
 
1254
        target_branch = repo.bzrdir.create_branch()
 
1255
        self.assertEqual([""], repo.bzrdir.get_branches().keys())
 
1256
 
1460
1257
    def test_create_repository(self):
1461
1258
        # a bzrdir can construct a repository for itself.
1462
 
        if not self.bzrdir_format.is_supported():
 
1259
        if not self.bzrdir_format.is_initializable():
1463
1260
            # unsupported formats are not loopback testable
1464
1261
            # because the default open will not open them and
1465
1262
            # they may not be initializable.
1466
 
            return
1467
 
        t = transport.get_transport(self.get_url())
 
1263
            raise TestNotApplicable("format is not initializable")
 
1264
        t = self.get_transport()
1468
1265
        made_control = self.bzrdir_format.initialize(t.base)
1469
1266
        made_repo = made_control.create_repository()
1470
1267
        # Check that we have a repository object.
1474
1271
    def test_create_repository_shared(self):
1475
1272
        # a bzrdir can create a shared repository or
1476
1273
        # fail appropriately
1477
 
        if not self.bzrdir_format.is_supported():
 
1274
        if not self.bzrdir_format.is_initializable():
1478
1275
            # unsupported formats are not loopback testable
1479
1276
            # because the default open will not open them and
1480
1277
            # they may not be initializable.
1481
 
            return
1482
 
        t = transport.get_transport(self.get_url())
 
1278
            raise TestNotApplicable("format is not initializable")
 
1279
        t = self.get_transport()
1483
1280
        made_control = self.bzrdir_format.initialize(t.base)
1484
1281
        try:
1485
1282
            made_repo = made_control.create_repository(shared=True)
1486
1283
        except errors.IncompatibleFormat:
1487
1284
            # Old bzrdir formats don't support shared repositories
1488
1285
            # and should raise IncompatibleFormat
1489
 
            return
 
1286
            raise TestNotApplicable("format does not support shared "
 
1287
                "repositories")
1490
1288
        self.assertTrue(made_repo.is_shared())
1491
1289
 
1492
1290
    def test_create_repository_nonshared(self):
1493
1291
        # a bzrdir can create a non-shared repository
1494
 
        if not self.bzrdir_format.is_supported():
 
1292
        if not self.bzrdir_format.is_initializable():
1495
1293
            # unsupported formats are not loopback testable
1496
1294
            # because the default open will not open them and
1497
1295
            # they may not be initializable.
1498
 
            return
1499
 
        t = transport.get_transport(self.get_url())
 
1296
            raise TestNotApplicable("format is not initializable")
 
1297
        t = self.get_transport()
1500
1298
        made_control = self.bzrdir_format.initialize(t.base)
1501
 
        made_repo = made_control.create_repository(shared=False)
 
1299
        try:
 
1300
            made_repo = made_control.create_repository(shared=False)
 
1301
        except errors.IncompatibleFormat:
 
1302
            # Some control dir formats don't support non-shared repositories
 
1303
            # and should raise IncompatibleFormat
 
1304
            raise TestNotApplicable("format does not support shared "
 
1305
                "repositories")
1502
1306
        self.assertFalse(made_repo.is_shared())
1503
1307
 
1504
1308
    def test_open_repository(self):
1505
 
        if not self.bzrdir_format.is_supported():
 
1309
        if not self.bzrdir_format.is_initializable():
1506
1310
            # unsupported formats are not loopback testable
1507
1311
            # because the default open will not open them and
1508
1312
            # they may not be initializable.
1509
 
            return
1510
 
        t = transport.get_transport(self.get_url())
 
1313
            raise TestNotApplicable("format is not initializable")
 
1314
        t = self.get_transport()
1511
1315
        made_control = self.bzrdir_format.initialize(t.base)
1512
1316
        made_repo = made_control.create_repository()
1513
1317
        opened_repo = made_control.open_repository()
1514
1318
        self.assertEqual(made_control, opened_repo.bzrdir)
1515
 
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1516
 
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
 
1319
        self.assertIsInstance(opened_repo, made_repo.__class__)
 
1320
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1517
1321
 
1518
1322
    def test_create_workingtree(self):
1519
1323
        # a bzrdir can construct a working tree for itself.
1520
 
        if not self.bzrdir_format.is_supported():
 
1324
        if not self.bzrdir_format.is_initializable():
1521
1325
            # unsupported formats are not loopback testable
1522
1326
            # because the default open will not open them and
1523
1327
            # they may not be initializable.
1524
 
            return
 
1328
            raise TestNotApplicable("format is not initializable")
1525
1329
        t = self.get_transport()
1526
1330
        made_control = self.bzrdir_format.initialize(t.base)
1527
1331
        made_repo = made_control.create_repository()
1528
1332
        made_branch = made_control.create_branch()
1529
1333
        made_tree = self.createWorkingTreeOrSkip(made_control)
1530
 
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
 
1334
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
1531
1335
        self.assertEqual(made_control, made_tree.bzrdir)
1532
1336
 
1533
1337
    def test_create_workingtree_revision(self):
1534
1338
        # a bzrdir can construct a working tree for itself @ a specific revision.
 
1339
        if not self.bzrdir_format.is_initializable():
 
1340
            raise TestNotApplicable("format is not initializable")
1535
1341
        t = self.get_transport()
1536
1342
        source = self.make_branch_and_tree('source')
1537
1343
        source.commit('a', rev_id='a', allow_pointless=True)
1543
1349
        source.branch.clone(made_control)
1544
1350
        try:
1545
1351
            made_tree = made_control.create_workingtree(revision_id='a')
1546
 
        except errors.NotLocalUrl:
 
1352
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1547
1353
            raise TestSkipped("Can't make working tree on transport %r" % t)
1548
1354
        self.assertEqual(['a'], made_tree.get_parent_ids())
1549
1355
 
1550
1356
    def test_open_workingtree(self):
1551
 
        if not self.bzrdir_format.is_supported():
1552
 
            # unsupported formats are not loopback testable
1553
 
            # because the default open will not open them and
1554
 
            # they may not be initializable.
1555
 
            return
 
1357
        if not self.bzrdir_format.is_initializable():
 
1358
            raise TestNotApplicable("format is not initializable")
1556
1359
        # this has to be tested with local access as we still support creating
1557
1360
        # format 6 bzrdirs
1558
1361
        t = self.get_transport()
1561
1364
            made_repo = made_control.create_repository()
1562
1365
            made_branch = made_control.create_branch()
1563
1366
            made_tree = made_control.create_workingtree()
1564
 
        except errors.NotLocalUrl:
 
1367
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1565
1368
            raise TestSkipped("Can't initialize %r on transport %r"
1566
1369
                              % (self.bzrdir_format, t))
1567
1370
        opened_tree = made_control.open_workingtree()
1568
1371
        self.assertEqual(made_control, opened_tree.bzrdir)
1569
 
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1570
 
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1571
 
 
1572
 
    def test_get_branch_transport(self):
1573
 
        dir = self.make_bzrdir('.')
1574
 
        # without a format, get_branch_transport gives use a transport
1575
 
        # which -may- point to an existing dir.
1576
 
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1577
 
                                   transport.Transport))
1578
 
        # with a given format, either the bzr dir supports identifiable
1579
 
        # branches, or it supports anonymous  branch formats, but not both.
1580
 
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1581
 
        identifiable_format = bzrlib.branch.BzrBranchFormat5()
1582
 
        try:
1583
 
            found_transport = dir.get_branch_transport(anonymous_format)
1584
 
            self.assertRaises(errors.IncompatibleFormat,
1585
 
                              dir.get_branch_transport,
1586
 
                              identifiable_format)
1587
 
        except errors.IncompatibleFormat:
1588
 
            found_transport = dir.get_branch_transport(identifiable_format)
1589
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1590
 
        # and the dir which has been initialized for us must exist.
1591
 
        found_transport.list_dir('.')
1592
 
 
1593
 
    def test_get_repository_transport(self):
1594
 
        dir = self.make_bzrdir('.')
1595
 
        # without a format, get_repository_transport gives use a transport
1596
 
        # which -may- point to an existing dir.
1597
 
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1598
 
                                   transport.Transport))
1599
 
        # with a given format, either the bzr dir supports identifiable
1600
 
        # repositories, or it supports anonymous  repository formats, but not both.
1601
 
        anonymous_format = weaverepo.RepositoryFormat6()
1602
 
        identifiable_format = weaverepo.RepositoryFormat7()
1603
 
        try:
1604
 
            found_transport = dir.get_repository_transport(anonymous_format)
1605
 
            self.assertRaises(errors.IncompatibleFormat,
1606
 
                              dir.get_repository_transport,
1607
 
                              identifiable_format)
1608
 
        except errors.IncompatibleFormat:
1609
 
            found_transport = dir.get_repository_transport(identifiable_format)
1610
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1611
 
        # and the dir which has been initialized for us must exist.
1612
 
        found_transport.list_dir('.')
1613
 
 
1614
 
    def test_get_workingtree_transport(self):
1615
 
        dir = self.make_bzrdir('.')
1616
 
        # without a format, get_workingtree_transport gives use a transport
1617
 
        # which -may- point to an existing dir.
1618
 
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1619
 
                                   transport.Transport))
1620
 
        # with a given format, either the bzr dir supports identifiable
1621
 
        # trees, or it supports anonymous tree formats, but not both.
1622
 
        anonymous_format = workingtree.WorkingTreeFormat2()
1623
 
        identifiable_format = workingtree.WorkingTreeFormat3()
1624
 
        try:
1625
 
            found_transport = dir.get_workingtree_transport(anonymous_format)
1626
 
            self.assertRaises(errors.IncompatibleFormat,
1627
 
                              dir.get_workingtree_transport,
1628
 
                              identifiable_format)
1629
 
        except errors.IncompatibleFormat:
1630
 
            found_transport = dir.get_workingtree_transport(identifiable_format)
1631
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1632
 
        # and the dir which has been initialized for us must exist.
1633
 
        found_transport.list_dir('.')
 
1372
        self.assertIsInstance(opened_tree, made_tree.__class__)
 
1373
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
 
1374
 
 
1375
    def test_get_selected_branch(self):
 
1376
        # The segment parameters are accessible from the root transport
 
1377
        # if a URL with segment parameters is opened.
 
1378
        if not self.bzrdir_format.is_initializable():
 
1379
            raise TestNotApplicable("format is not initializable")
 
1380
        t = self.get_transport()
 
1381
        try:
 
1382
            made_control = self.bzrdir_format.initialize(t.base)
 
1383
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
 
1384
            raise TestSkipped("Can't initialize %r on transport %r"
 
1385
                              % (self.bzrdir_format, t))
 
1386
        dir = controldir.ControlDir.open(t.base+",branch=foo")
 
1387
        self.assertEquals({"branch": "foo"},
 
1388
            dir.user_transport.get_segment_parameters())
 
1389
        self.assertEquals("foo", dir._get_selected_branch())
 
1390
 
 
1391
    def test_get_selected_branch_none_selected(self):
 
1392
        # _get_selected_branch defaults to None
 
1393
        if not self.bzrdir_format.is_initializable():
 
1394
            raise TestNotApplicable("format is not initializable")
 
1395
        t = self.get_transport()
 
1396
        try:
 
1397
            made_control = self.bzrdir_format.initialize(t.base)
 
1398
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
 
1399
            raise TestSkipped("Can't initialize %r on transport %r"
 
1400
                              % (self.bzrdir_format, t))
 
1401
        dir = controldir.ControlDir.open(t.base)
 
1402
        self.assertEqual(u"", dir._get_selected_branch())
1634
1403
 
1635
1404
    def test_root_transport(self):
1636
1405
        dir = self.make_bzrdir('.')
1637
1406
        self.assertEqual(dir.root_transport.base,
1638
 
                         transport.get_transport(self.get_url('.')).base)
 
1407
                         self.get_transport().base)
1639
1408
 
1640
1409
    def test_find_repository_no_repo_under_standalone_branch(self):
1641
1410
        # finding a repo stops at standalone branches even if there is a
1644
1413
            repo = self.make_repository('.', shared=True)
1645
1414
        except errors.IncompatibleFormat:
1646
1415
            # need a shared repository to test this.
1647
 
            return
 
1416
            raise TestNotApplicable("requires shared repository support")
 
1417
        if not repo._format.supports_nesting_repositories:
 
1418
            raise TestNotApplicable("requires nesting repositories")
1648
1419
        url = self.get_url('intermediate')
1649
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1650
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1420
        t = self.get_transport()
 
1421
        t.mkdir('intermediate')
 
1422
        t.mkdir('intermediate/child')
1651
1423
        made_control = self.bzrdir_format.initialize(url)
1652
1424
        made_control.create_repository()
1653
1425
        innermost_control = self.bzrdir_format.initialize(
1669
1441
            repo = self.make_repository('.', shared=True)
1670
1442
        except errors.IncompatibleFormat:
1671
1443
            # need a shared repository to test this.
1672
 
            return
 
1444
            raise TestNotApplicable("requires format with shared repository "
 
1445
                "support")
 
1446
        if not repo._format.supports_nesting_repositories:
 
1447
            raise TestNotApplicable("requires support for nesting "
 
1448
                "repositories")
1673
1449
        url = self.get_url('childbzrdir')
1674
 
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
 
1450
        self.get_transport().mkdir('childbzrdir')
1675
1451
        made_control = self.bzrdir_format.initialize(url)
1676
1452
        try:
1677
1453
            child_repo = made_control.open_repository()
1685
1461
                         found_repo.bzrdir.root_transport.base)
1686
1462
 
1687
1463
    def test_find_repository_standalone_with_containing_shared_repository(self):
1688
 
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
 
1464
        # find repo inside a standalone repo inside a shared repo finds the
 
1465
        # standalone repo
1689
1466
        try:
1690
1467
            containing_repo = self.make_repository('.', shared=True)
1691
1468
        except errors.IncompatibleFormat:
1692
1469
            # need a shared repository to test this.
1693
 
            return
 
1470
            raise TestNotApplicable("requires support for shared "
 
1471
                "repositories")
 
1472
        if not containing_repo._format.supports_nesting_repositories:
 
1473
            raise TestNotApplicable("format does not support "
 
1474
                "nesting repositories")
1694
1475
        child_repo = self.make_repository('childrepo')
1695
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1476
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1696
1477
        found_repo = opened_control.find_repository()
1697
1478
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1698
1479
                         found_repo.bzrdir.root_transport.base)
1703
1484
            containing_repo = self.make_repository('.', shared=True)
1704
1485
        except errors.IncompatibleFormat:
1705
1486
            # need a shared repository to test this.
1706
 
            return
 
1487
            raise TestNotApplicable("requires support for shared "
 
1488
                "repositories")
 
1489
        if not containing_repo._format.supports_nesting_repositories:
 
1490
            raise TestNotApplicable("requires support for nesting "
 
1491
                "repositories")
1707
1492
        url = self.get_url('childrepo')
1708
 
        transport.get_transport(self.get_url()).mkdir('childrepo')
 
1493
        self.get_transport().mkdir('childrepo')
1709
1494
        child_control = self.bzrdir_format.initialize(url)
1710
1495
        child_repo = child_control.create_repository(shared=True)
1711
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1496
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1712
1497
        found_repo = opened_control.find_repository()
1713
1498
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1714
1499
                         found_repo.bzrdir.root_transport.base)
1722
1507
            repo = self.make_repository('.', shared=True)
1723
1508
        except errors.IncompatibleFormat:
1724
1509
            # need a shared repository to test this.
1725
 
            return
 
1510
            raise TestNotApplicable("requires support for shared "
 
1511
                "repositories")
 
1512
        if not repo._format.supports_nesting_repositories:
 
1513
            raise TestNotApplicable("requires support for nesting "
 
1514
                "repositories")
1726
1515
        url = self.get_url('intermediate')
1727
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1728
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1516
        t = self.get_transport()
 
1517
        t.mkdir('intermediate')
 
1518
        t.mkdir('intermediate/child')
1729
1519
        made_control = self.bzrdir_format.initialize(url)
1730
1520
        try:
1731
1521
            child_repo = made_control.open_repository()
1755
1545
            # (we force the latest known format as downgrades may not be
1756
1546
            # available
1757
1547
            self.assertTrue(isinstance(dir._format.get_converter(
1758
 
                format=dir._format), bzrdir.Converter))
 
1548
                format=dir._format), controldir.Converter))
1759
1549
        dir.needs_format_conversion(
1760
1550
            controldir.ControlDirFormat.get_default_format())
1761
1551
 
1767
1557
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1768
1558
        old_path = urlutils.local_path_from_url(old_url)
1769
1559
        new_path = urlutils.local_path_from_url(new_url)
1770
 
        self.failUnlessExists(old_path)
1771
 
        self.failUnlessExists(new_path)
 
1560
        self.assertPathExists(old_path)
 
1561
        self.assertPathExists(new_path)
1772
1562
        for (((dir_relpath1, _), entries1),
1773
1563
             ((dir_relpath2, _), entries2)) in izip(
1774
1564
                osutils.walkdirs(old_path),
1802
1592
    def test_format_description(self):
1803
1593
        dir = self.make_bzrdir('.')
1804
1594
        text = dir._format.get_format_description()
1805
 
        self.failUnless(len(text))
1806
 
 
1807
 
    def test_retire_bzrdir(self):
1808
 
        bd = self.make_bzrdir('.')
1809
 
        transport = bd.root_transport
1810
 
        # must not overwrite existing directories
1811
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1812
 
            transport=transport)
1813
 
        self.failUnless(transport.has('.bzr'))
1814
 
        bd.retire_bzrdir()
1815
 
        self.failIf(transport.has('.bzr'))
1816
 
        self.failUnless(transport.has('.bzr.retired.1'))
1817
 
 
1818
 
    def test_retire_bzrdir_limited(self):
1819
 
        bd = self.make_bzrdir('.')
1820
 
        transport = bd.root_transport
1821
 
        # must not overwrite existing directories
1822
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1823
 
            transport=transport)
1824
 
        self.failUnless(transport.has('.bzr'))
1825
 
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1826
 
            bd.retire_bzrdir, limit=0)
 
1595
        self.assertTrue(len(text))
1827
1596
 
1828
1597
 
1829
1598
class TestBreakLock(TestCaseWithControlDir):
1846
1615
            # and thus this interaction cannot be tested at the interface
1847
1616
            # level.
1848
1617
            repo.unlock()
1849
 
            return
 
1618
            raise TestNotApplicable("format does not physically lock")
1850
1619
        # only one yes needed here: it should only be unlocking
1851
1620
        # the repo
1852
1621
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1855
1624
        except NotImplementedError:
1856
1625
            # this bzrdir does not implement break_lock - so we cant test it.
1857
1626
            repo.unlock()
1858
 
            return
 
1627
            raise TestNotApplicable("format does not support breaking locks")
1859
1628
        lock_repo.lock_write()
1860
1629
        lock_repo.unlock()
1861
1630
        self.assertRaises(errors.LockBroken, repo.unlock)
1869
1638
        master = self.make_branch('branch')
1870
1639
        thisdir = self.make_bzrdir('this')
1871
1640
        try:
1872
 
            bzrlib.branch.BranchReferenceFormat().initialize(
1873
 
                thisdir, target_branch=master)
 
1641
            thisdir.set_branch_reference(master)
1874
1642
        except errors.IncompatibleFormat:
1875
 
            return
 
1643
            raise TestNotApplicable("format does not support "
 
1644
                "branch references")
1876
1645
        unused_repo = thisdir.create_repository()
1877
1646
        master.lock_write()
1878
1647
        unused_repo.lock_write()
1925
1694
            # raised a LockActive because we do still have a live locked
1926
1695
            # object.
1927
1696
            tree.unlock()
1928
 
            return
 
1697
            raise TestNotApplicable("format does not support breaking locks")
1929
1698
        self.assertEqual([True],
1930
1699
                bzrlib.ui.ui_factory.responses)
1931
1700
        lock_tree = tree.bzrdir.open_workingtree()
1944
1713
        except errors.BzrError, e:
1945
1714
            if 'Cannot set config' in str(e):
1946
1715
                self.assertFalse(
1947
 
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
 
1716
                    isinstance(my_dir, (_mod_bzrdir.BzrDirMeta1, RemoteBzrDir)),
1948
1717
                    "%r should support configs" % my_dir)
1949
1718
                raise TestNotApplicable(
1950
1719
                    'This BzrDir format does not support configs.')
1951
1720
            else:
1952
1721
                raise
1953
1722
        self.assertEqual('http://example.com', config.get_default_stack_on())
1954
 
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
 
1723
        my_dir2 = controldir.ControlDir.open(self.get_url('.'))
1955
1724
        config2 = my_dir2.get_config()
1956
1725
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1957
1726
 
1961
1730
    def test_find_repository_no_repository(self):
1962
1731
        # loopback test to check the current format fails to find a
1963
1732
        # share repository correctly.
1964
 
        if not self.bzrdir_format.is_supported():
 
1733
        if not self.bzrdir_format.is_initializable():
1965
1734
            # unsupported formats are not loopback testable
1966
1735
            # because the default open will not open them and
1967
1736
            # they may not be initializable.
1968
 
            return
 
1737
            raise TestNotApplicable("format is not initializable")
1969
1738
        # supported formats must be able to init and open
1970
1739
        # - do the vfs initialisation over the basic vfs transport
1971
1740
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1972
1741
        url = self.get_vfs_only_url('subdir')
1973
 
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1742
        transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
1974
1743
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1975
1744
        try:
1976
1745
            repo = made_control.open_repository()
1979
1748
            return
1980
1749
        except errors.NoRepositoryPresent:
1981
1750
            pass
1982
 
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1751
        made_control = controldir.ControlDir.open(self.get_readonly_url('subdir'))
1983
1752
        self.assertRaises(errors.NoRepositoryPresent,
1984
1753
                          made_control.find_repository)
1985
1754