~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
17
17
"""Tests for control directory implementations - tests a controldir format."""
18
18
 
19
19
from itertools import izip
 
20
import os
20
21
 
21
22
import bzrlib.branch
22
23
from bzrlib import (
23
 
    bzrdir as _mod_bzrdir,
 
24
    bzrdir,
24
25
    check,
25
26
    controldir,
26
27
    errors,
27
28
    gpg,
28
29
    osutils,
29
 
    revision as _mod_revision,
30
30
    transport,
31
31
    ui,
32
32
    urlutils,
33
33
    workingtree,
34
34
    )
 
35
import bzrlib.revision
35
36
from bzrlib.tests import (
36
 
    fixtures,
37
 
    ChrootedTestCase,
38
 
    TestNotApplicable,
39
 
    TestSkipped,
40
 
    )
 
37
                          ChrootedTestCase,
 
38
                          TestNotApplicable,
 
39
                          TestSkipped,
 
40
                          )
41
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
42
42
from bzrlib.transport.local import LocalTransport
43
43
from bzrlib.ui import (
44
44
    CannedInputUIFactory,
45
45
    )
46
 
from bzrlib.remote import (
47
 
    RemoteBzrDir,
48
 
    RemoteBzrDirFormat,
49
 
    RemoteRepository,
50
 
    )
 
46
from bzrlib.remote import RemoteBzrDir, RemoteRepository
 
47
from bzrlib.repofmt import weaverepo
51
48
 
52
49
 
53
50
class TestControlDir(TestCaseWithControlDir):
101
98
                                    create_tree_if_local=create_tree_if_local)
102
99
        return target
103
100
 
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
 
 
122
101
    def test_create_null_workingtree(self):
123
102
        dir = self.make_bzrdir('dir1')
124
103
        dir.create_repository()
125
104
        dir.create_branch()
126
105
        try:
127
 
            wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
 
106
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
128
107
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
129
108
            raise TestSkipped("cannot make working tree with transport %r"
130
109
                              % dir.transport)
140
119
            bzrdir.destroy_workingtree()
141
120
        except errors.UnsupportedOperation:
142
121
            raise TestSkipped('Format does not support destroying tree')
143
 
        self.assertPathDoesNotExist('tree/file')
 
122
        self.failIfExists('tree/file')
144
123
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
145
124
        bzrdir.create_workingtree()
146
 
        self.assertPathExists('tree/file')
 
125
        self.failUnlessExists('tree/file')
147
126
        bzrdir.destroy_workingtree_metadata()
148
 
        self.assertPathExists('tree/file')
 
127
        self.failUnlessExists('tree/file')
149
128
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
150
129
 
151
130
    def test_destroy_branch(self):
159
138
        bzrdir.create_branch()
160
139
        bzrdir.open_branch()
161
140
 
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
 
 
170
141
    def test_destroy_repository(self):
171
142
        repo = self.make_repository('repository')
172
143
        bzrdir = repo.bzrdir
175
146
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
176
147
            raise TestNotApplicable('Format does not support destroying'
177
148
                                    ' repository')
178
 
        self.assertRaises(errors.NoRepositoryPresent,
179
 
            bzrdir.destroy_repository)
180
149
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
181
150
        bzrdir.create_repository()
182
151
        bzrdir.open_repository()
186
155
        e.g. NotLocalUrl) if there is no working tree.
187
156
        """
188
157
        dir = self.make_bzrdir('source')
189
 
        vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
 
158
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
190
159
        if vfs_dir.has_workingtree():
191
160
            # This ControlDir format doesn't support ControlDirs without
192
161
            # working trees, so this test is irrelevant.
193
 
            raise TestNotApplicable("format does not support "
194
 
                "control directories without working tree")
 
162
            return
195
163
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
196
164
 
197
165
    def test_clone_bzrdir_repository_under_shared(self):
201
169
        tree.commit('revision 1', rev_id='1')
202
170
        dir = self.make_bzrdir('source')
203
171
        repo = dir.create_repository()
204
 
        if not repo._format.supports_nesting_repositories:
205
 
            raise TestNotApplicable("repository format does not support "
206
 
                "nesting")
207
172
        repo.fetch(tree.branch.repository)
208
173
        self.assertTrue(repo.has_revision('1'))
209
174
        try:
210
175
            self.make_repository('target', shared=True)
211
176
        except errors.IncompatibleFormat:
212
 
            raise TestNotApplicable("repository format does not support "
213
 
                "shared repositories")
 
177
            return
214
178
        target = dir.clone(self.get_url('target/child'))
215
179
        self.assertNotEqual(dir.transport.base, target.transport.base)
216
180
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
220
184
        try:
221
185
            shared_repo = self.make_repository('shared', shared=True)
222
186
        except errors.IncompatibleFormat:
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")
 
187
            return
228
188
        # Make a branch, 'commit_tree', and working tree outside of the shared
229
189
        # repository, and commit some revisions to it.
230
190
        tree = self.make_branch_and_tree('commit_tree')
231
191
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
232
192
        tree.add('foo')
233
193
        tree.commit('revision 1', rev_id='1')
234
 
        tree.bzrdir.open_branch().generate_revision_history(
235
 
            _mod_revision.NULL_REVISION)
 
194
        tree.bzrdir.open_branch().set_revision_history([])
236
195
        tree.set_parent_trees([])
237
196
        tree.commit('revision 2', rev_id='2')
238
197
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
255
214
        try:
256
215
            shared_repo = self.make_repository('shared', shared=True)
257
216
        except errors.IncompatibleFormat:
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")
 
217
            return
263
218
        tree = self.make_branch_and_tree('commit_tree')
264
219
        self.build_tree(['commit_tree/foo'])
265
220
        tree.add('foo')
266
221
        tree.commit('revision 1', rev_id='1')
267
 
        tree.branch.bzrdir.open_branch().generate_revision_history(
268
 
            _mod_revision.NULL_REVISION)
 
222
        tree.branch.bzrdir.open_branch().set_revision_history([])
269
223
        tree.set_parent_trees([])
270
224
        tree.commit('revision 2', rev_id='2')
271
225
        tree.branch.repository.copy_content_into(shared_repo)
292
246
        self.build_tree(['commit_tree/foo'])
293
247
        tree.add('foo')
294
248
        tree.commit('revision 1', rev_id='1')
295
 
        tree.branch.bzrdir.open_branch().generate_revision_history(
296
 
            _mod_revision.NULL_REVISION)
 
249
        tree.branch.bzrdir.open_branch().set_revision_history([])
297
250
        tree.set_parent_trees([])
298
251
        tree.commit('revision 2', rev_id='2')
299
252
        source = self.make_repository('source')
304
257
 
305
258
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
306
259
        # Bug #430868 is about an email containing '.sig'
307
 
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
 
260
        os.environ['BZR_EMAIL'] = 'murphy@host.sighup.org'
308
261
        tree = self.make_branch_and_tree('commit_tree')
309
262
        self.build_tree(['commit_tree/foo'])
310
263
        tree.add('foo')
333
286
        tree.branch.repository.copy_content_into(source.repository)
334
287
        tree.branch.copy_content_into(source)
335
288
        try:
336
 
            shared_repo = self.make_repository('target', shared=True)
 
289
            self.make_repository('target', shared=True)
337
290
        except errors.IncompatibleFormat:
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")
 
291
            return
343
292
        dir = source.bzrdir
344
293
        target = dir.clone(self.get_url('target/child'))
345
294
        self.assertNotEqual(dir.transport.base, target.transport.base)
346
295
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
347
 
        self.assertEqual(source.last_revision(),
348
 
                         target.open_branch().last_revision())
 
296
        self.assertEqual(source.revision_history(),
 
297
                         target.open_branch().revision_history())
349
298
 
350
299
    def test_clone_bzrdir_branch_revision(self):
351
300
        # test for revision limiting, [smoke test, not corner case checks].
365
314
        self.assertEqual('1', target.open_branch().last_revision())
366
315
 
367
316
    def test_clone_on_transport_preserves_repo_format(self):
368
 
        if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
 
317
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
369
318
            format = 'knit'
370
319
        else:
371
320
            format = None
414
363
            repo.set_make_working_trees(False)
415
364
            self.assertFalse(repo.make_working_trees())
416
365
 
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')
 
366
        dir = tree.bzrdir
 
367
        a_dir = dir.clone(self.get_url('repo/a'))
 
368
        a_dir.open_branch()
423
369
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
424
370
 
425
371
    def test_clone_respects_stacked(self):
426
372
        branch = self.make_branch('parent')
427
373
        child_transport = self.get_transport('child')
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")
 
374
        child = branch.bzrdir.clone_on_transport(child_transport,
 
375
                                                 stacked_on=branch.base)
435
376
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
436
377
 
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
 
 
481
378
    def test_get_branch_reference_on_reference(self):
482
379
        """get_branch_reference should return the right url."""
483
380
        referenced_branch = self.make_branch('referenced')
484
381
        dir = self.make_bzrdir('source')
485
382
        try:
486
 
            dir.set_branch_reference(referenced_branch)
 
383
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
384
                target_branch=referenced_branch)
487
385
        except errors.IncompatibleFormat:
488
386
            # this is ok too, not all formats have to support references.
489
 
            raise TestNotApplicable("control directory does not "
490
 
                "support branch references")
 
387
            return
491
388
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
492
389
            dir.get_branch_reference())
493
390
 
501
398
        dir = self.make_bzrdir('source')
502
399
        if dir.has_branch():
503
400
            # this format does not support branchless bzrdirs.
504
 
            raise TestNotApplicable("format does not support "
505
 
                "branchless control directories")
 
401
            return
506
402
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
507
403
 
508
404
    def test_sprout_bzrdir_empty(self):
509
405
        dir = self.make_bzrdir('source')
510
406
        target = dir.sprout(self.get_url('target'))
511
 
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
 
407
        self.assertNotEqual(dir.transport.base, target.transport.base)
512
408
        # creates a new repository branch and tree
513
409
        target.open_repository()
514
410
        target.open_branch()
520
416
        try:
521
417
            self.make_repository('target', shared=True)
522
418
        except errors.IncompatibleFormat:
523
 
            raise TestNotApplicable("format does not support shared "
524
 
                "repositories")
 
419
            return
525
420
        target = dir.sprout(self.get_url('target/child'))
526
421
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
527
422
        target.open_branch()
529
424
            target.open_workingtree()
530
425
        except errors.NoWorkingTree:
531
426
            # Some bzrdirs can never have working trees.
532
 
            repo = target.find_repository()
533
 
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
 
427
            self.assertFalse(target._format.supports_workingtrees)
534
428
 
535
429
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
536
430
        # the force_new_repo parameter should force use of a new repo in an empty
539
433
        try:
540
434
            self.make_repository('target', shared=True)
541
435
        except errors.IncompatibleFormat:
542
 
            raise TestNotApplicable("format does not support shared "
543
 
                "repositories")
 
436
            return
544
437
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
545
438
        target.open_repository()
546
439
        target.open_branch()
551
444
        self.build_tree(['commit_tree/foo'])
552
445
        tree.add('foo')
553
446
        tree.commit('revision 1', rev_id='1')
554
 
        tree.bzrdir.open_branch().generate_revision_history(
555
 
            _mod_revision.NULL_REVISION)
 
447
        tree.bzrdir.open_branch().set_revision_history([])
556
448
        tree.set_parent_trees([])
557
449
        tree.commit('revision 2', rev_id='2')
558
450
        source = self.make_repository('source')
561
453
        try:
562
454
            shared_repo = self.make_repository('target', shared=True)
563
455
        except errors.IncompatibleFormat:
564
 
            raise TestNotApplicable("format does not support "
565
 
                "shared repositories")
 
456
            return
566
457
        target = dir.sprout(self.get_url('target/child'))
567
 
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
 
458
        self.assertNotEqual(dir.transport.base, target.transport.base)
568
459
        self.assertTrue(shared_repo.has_revision('1'))
569
460
 
570
461
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
571
462
        try:
572
463
            shared_repo = self.make_repository('shared', shared=True)
573
464
        except errors.IncompatibleFormat:
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")
 
465
            return
579
466
        tree = self.make_branch_and_tree('commit_tree')
580
467
        self.build_tree(['commit_tree/foo'])
581
468
        tree.add('foo')
582
469
        tree.commit('revision 1', rev_id='1')
583
 
        tree.bzrdir.open_branch().generate_revision_history(
584
 
            _mod_revision.NULL_REVISION)
 
470
        tree.bzrdir.open_branch().set_revision_history([])
585
471
        tree.set_parent_trees([])
586
472
        tree.commit('revision 2', rev_id='2')
587
473
        tree.branch.repository.copy_content_into(shared_repo)
596
482
        try:
597
483
            shared_repo = self.make_repository('shared', shared=True)
598
484
        except errors.IncompatibleFormat:
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")
 
485
            return
604
486
        tree = self.make_branch_and_tree('commit_tree')
605
487
        self.build_tree(['commit_tree/foo'])
606
488
        tree.add('foo')
607
489
        tree.commit('revision 1', rev_id='1')
608
 
        tree.bzrdir.open_branch().generate_revision_history(
609
 
            _mod_revision.NULL_REVISION)
 
490
        tree.bzrdir.open_branch().set_revision_history([])
610
491
        tree.set_parent_trees([])
611
492
        tree.commit('revision 2', rev_id='2')
612
493
        tree.branch.repository.copy_content_into(shared_repo)
620
501
        self.assertNotEqual(dir.transport.base, target.transport.base)
621
502
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
622
503
        branch = target.open_branch()
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())
 
504
        self.assertTrue(branch.repository.has_revision('1'))
627
505
        if branch.bzrdir._format.supports_workingtrees:
628
506
            self.assertTrue(branch.repository.make_working_trees())
629
507
        self.assertFalse(branch.repository.is_shared())
633
511
        self.build_tree(['commit_tree/foo'])
634
512
        tree.add('foo')
635
513
        tree.commit('revision 1', rev_id='1')
636
 
        tree.bzrdir.open_branch().generate_revision_history(
637
 
            _mod_revision.NULL_REVISION)
 
514
        tree.bzrdir.open_branch().set_revision_history([])
638
515
        tree.set_parent_trees([])
639
516
        tree.commit('revision 2', rev_id='2')
640
517
        source = self.make_repository('source')
643
520
        try:
644
521
            shared_repo = self.make_repository('target', shared=True)
645
522
        except errors.IncompatibleFormat:
646
 
            raise TestNotApplicable("format does not support shared "
647
 
                "repositories")
 
523
            return
648
524
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
649
 
        self.assertNotEqual(
650
 
            dir.control_transport.base,
651
 
            target.control_transport.base)
 
525
        self.assertNotEqual(dir.transport.base, target.transport.base)
652
526
        self.assertFalse(shared_repo.has_revision('1'))
653
527
 
654
528
    def test_sprout_bzrdir_repository_revision(self):
660
534
        self.build_tree(['commit_tree/foo'])
661
535
        tree.add('foo')
662
536
        tree.commit('revision 1', rev_id='1')
663
 
        br = tree.bzrdir.open_branch()
664
 
        br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
 
537
        tree.bzrdir.open_branch().set_revision_history([])
665
538
        tree.set_parent_trees([])
666
539
        tree.commit('revision 2', rev_id='2')
667
540
        source = self.make_repository('source')
684
557
        try:
685
558
            shared_repo = self.make_repository('target', shared=True)
686
559
        except errors.IncompatibleFormat:
687
 
            raise TestNotApplicable("format does not support shared "
688
 
                "repositories")
 
560
            return
689
561
        target = dir.sprout(self.get_url('target/child'))
690
562
        self.assertTrue(shared_repo.has_revision('1'))
691
563
 
703
575
        try:
704
576
            shared_repo = self.make_repository('target', shared=True)
705
577
        except errors.IncompatibleFormat:
706
 
            raise TestNotApplicable("format does not support shared "
707
 
                "repositories")
 
578
            return
708
579
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
709
 
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
 
580
        self.assertNotEqual(dir.transport.base, target.transport.base)
710
581
        self.assertFalse(shared_repo.has_revision('1'))
711
582
 
712
583
    def test_sprout_bzrdir_branch_reference(self):
714
585
        referenced_branch = self.make_branch('referenced')
715
586
        dir = self.make_bzrdir('source')
716
587
        try:
717
 
            dir.set_branch_reference(referenced_branch)
 
588
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
589
                target_branch=referenced_branch)
718
590
        except errors.IncompatibleFormat:
719
 
            raise TestNotApplicable("format does not support branch "
720
 
                "references")
 
591
            # this is ok too, not all formats have to support references.
 
592
            return
721
593
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
722
594
        target = dir.sprout(self.get_url('target'))
723
595
        self.assertNotEqual(dir.transport.base, target.transport.base)
733
605
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
734
606
        dir = self.make_bzrdir('source')
735
607
        try:
736
 
            dir.set_branch_reference(referenced_tree.branch)
 
608
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
609
                target_branch=referenced_tree.branch)
737
610
        except errors.IncompatibleFormat:
738
 
            raise TestNotApplicable("format does not support branch "
739
 
                "references")
 
611
            # this is ok too, not all formats have to support references.
 
612
            return
740
613
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
741
614
        try:
742
615
            shared_repo = self.make_repository('target', shared=True)
743
616
        except errors.IncompatibleFormat:
744
 
            raise TestNotApplicable("format does not support "
745
 
                "shared repositories")
 
617
            return
746
618
        target = dir.sprout(self.get_url('target/child'))
747
619
        self.assertNotEqual(dir.transport.base, target.transport.base)
748
620
        # we want target to have a branch that is in-place.
759
631
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
760
632
        dir = self.make_bzrdir('source')
761
633
        try:
762
 
            dir.set_branch_reference(referenced_tree.branch)
 
634
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
635
                target_branch=referenced_tree.branch)
763
636
        except errors.IncompatibleFormat:
764
637
            # this is ok too, not all formats have to support references.
765
 
            raise TestNotApplicable("format does not support "
766
 
                "branch references")
 
638
            return
767
639
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
768
640
        try:
769
641
            shared_repo = self.make_repository('target', shared=True)
770
642
        except errors.IncompatibleFormat:
771
 
            raise TestNotApplicable("format does not support shared "
772
 
                "repositories")
 
643
            return
773
644
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
774
645
        self.assertNotEqual(dir.transport.base, target.transport.base)
775
646
        # we want target to have a branch that is in-place.
796
667
        target = dir.sprout(self.get_url('target'), revision_id='1')
797
668
        self.assertEqual('1', target.open_branch().last_revision())
798
669
 
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()))
906
 
 
907
670
    def test_sprout_bzrdir_tree_branch_reference(self):
908
671
        # sprouting should create a repository if needed and a sprouted branch.
909
672
        # the tree state should not be copied.
910
673
        referenced_branch = self.make_branch('referencced')
911
674
        dir = self.make_bzrdir('source')
912
675
        try:
913
 
            dir.set_branch_reference(referenced_branch)
 
676
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
677
                target_branch=referenced_branch)
914
678
        except errors.IncompatibleFormat:
915
679
            # this is ok too, not all formats have to support references.
916
 
            raise TestNotApplicable("format does not support "
917
 
                "branch references")
 
680
            return
918
681
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
919
682
        tree = self.createWorkingTreeOrSkip(dir)
920
683
        self.build_tree(['source/subdir/'])
936
699
        referenced_branch = self.make_branch('referencced')
937
700
        dir = self.make_bzrdir('source')
938
701
        try:
939
 
            dir.set_branch_reference(referenced_branch)
 
702
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
703
                target_branch=referenced_branch)
940
704
        except errors.IncompatibleFormat:
941
705
            # this is ok too, not all formats have to support references.
942
 
            raise TestNotApplicable("format does not support "
943
 
                "branch references")
 
706
            return
944
707
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
945
708
        tree = self.createWorkingTreeOrSkip(dir)
946
709
        self.build_tree(['source/foo'])
992
755
        tree.commit('revision 1', rev_id='1')
993
756
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
994
757
        dir = tree.bzrdir
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')
 
758
        if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
 
759
            self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
 
760
                              self.get_url('target'),
 
761
                              create_tree_if_local=False)
 
762
            return
 
763
        target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
 
764
        self.failIfExists('target/foo')
1001
765
        self.assertEqual(tree.branch.last_revision(),
1002
766
                         target.open_branch().last_revision())
1003
767
 
1026
790
 
1027
791
    def test_format_initialize_find_open(self):
1028
792
        # loopback test to check the current format initializes to itself.
1029
 
        if not self.bzrdir_format.is_initializable():
 
793
        if not self.bzrdir_format.is_supported():
1030
794
            # unsupported formats are not loopback testable
1031
795
            # because the default open will not open them and
1032
796
            # they may not be initializable.
1033
 
            raise TestNotApplicable("format is not initializable")
 
797
            return
1034
798
        # for remote formats, there must be no prior assumption about the
1035
799
        # network name to use - it's possible that this may somehow have got
1036
800
        # in through an unisolated test though - see
1037
801
        # <https://bugs.launchpad.net/bzr/+bug/504102>
1038
 
        self.assertEqual(getattr(self.bzrdir_format,
 
802
        self.assertEquals(getattr(self.bzrdir_format,
1039
803
            '_network_name', None),
1040
804
            None)
1041
805
        # supported formats must be able to init and open
1042
 
        t = self.get_transport()
1043
 
        readonly_t = self.get_readonly_transport()
 
806
        t = transport.get_transport(self.get_url())
 
807
        readonly_t = transport.get_transport(self.get_readonly_url())
1044
808
        made_control = self.bzrdir_format.initialize(t.base)
1045
 
        self.assertIsInstance(made_control, controldir.ControlDir)
1046
 
        if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
1047
 
            return
 
809
        self.failUnless(isinstance(made_control, controldir.ControlDir))
1048
810
        self.assertEqual(self.bzrdir_format,
1049
811
                         controldir.ControlDirFormat.find_format(readonly_t))
1050
812
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1051
 
        opened_dir = controldir.ControlDir.open(t.base)
 
813
        opened_dir = bzrdir.BzrDir.open(t.base)
1052
814
        self.assertEqual(made_control._format,
1053
815
                         opened_dir._format)
1054
816
        self.assertEqual(direct_opened_dir._format,
1055
817
                         opened_dir._format)
1056
 
        self.assertIsInstance(opened_dir, controldir.ControlDir)
 
818
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
1057
819
 
1058
820
    def test_format_initialize_on_transport_ex(self):
1059
821
        t = self.get_transport('dir')
1065
827
        self.assertInitializeEx(t, use_existing_dir=True)
1066
828
 
1067
829
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
1068
 
        if not self.bzrdir_format.is_initializable():
1069
 
            raise TestNotApplicable("format is not initializable")
 
830
        if not self.bzrdir_format.is_supported():
 
831
            # Not initializable - not a failure either.
 
832
            return
1070
833
        t = self.get_transport('dir')
1071
834
        t.ensure_base()
1072
835
        self.assertRaises(errors.FileExists,
1078
841
        self.assertInitializeEx(t, create_prefix=True)
1079
842
 
1080
843
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
1081
 
        if not self.bzrdir_format.is_initializable():
1082
 
            raise TestNotApplicable("format is not initializable")
 
844
        if not self.bzrdir_format.is_supported():
 
845
            # Not initializable - not a failure either.
 
846
            return
1083
847
        t = self.get_transport('missing/dir')
1084
848
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1085
849
            create_prefix=False)
1086
850
 
1087
851
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1088
852
        t = self.get_transport('repo')
1089
 
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
 
853
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1090
854
        repo_name = repo_fmt.repository_format.network_name()
1091
855
        repo = repo_fmt.initialize_on_transport_ex(t,
1092
856
            repo_format_name=repo_name, shared_repo=True)[0]
1093
857
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1094
858
            force_new_repo=True, repo_format_name=repo_name)
 
859
        if control is None:
 
860
            # uninitialisable format
 
861
            return
1095
862
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1096
863
            made_repo.bzrdir.root_transport.base)
1097
864
 
1098
865
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1099
866
        t = self.get_transport('repo')
1100
 
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
 
867
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1101
868
        repo_name = repo_fmt.repository_format.network_name()
1102
869
        repo = repo_fmt.initialize_on_transport_ex(t,
1103
870
            repo_format_name=repo_name, shared_repo=True)[0]
1104
871
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1105
872
            force_new_repo=False, repo_format_name=repo_name)
1106
 
        if not control._format.fixed_components:
 
873
        if control is None:
 
874
            # uninitialisable format
 
875
            return
 
876
        if not isinstance(control._format, (bzrdir.BzrDirFormat5,
 
877
            bzrdir.BzrDirFormat6,)):
1107
878
            self.assertEqual(repo.bzrdir.root_transport.base,
1108
879
                made_repo.bzrdir.root_transport.base)
1109
880
 
 
881
    def test_format_initialize_on_transport_ex_stacked_on(self):
 
882
        # trunk is a stackable format.  Note that its in the same server area
 
883
        # which is what launchpad does, but not sufficient to exercise the
 
884
        # general case.
 
885
        trunk = self.make_branch('trunk', format='1.9')
 
886
        t = self.get_transport('stacked')
 
887
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
 
888
        repo_name = old_fmt.repository_format.network_name()
 
889
        # Should end up with a 1.9 format (stackable)
 
890
        repo, control = self.assertInitializeEx(t, need_meta=True,
 
891
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
 
892
        if control is None:
 
893
            # uninitialisable format
 
894
            return
 
895
        self.assertLength(1, repo._fallback_repositories)
 
896
 
 
897
    def test_format_initialize_on_transport_ex_default_stack_on(self):
 
898
        # When initialize_on_transport_ex uses a stacked-on branch because of
 
899
        # a stacking policy on the target, the location of the fallback
 
900
        # repository is the same as the external location of the stacked-on
 
901
        # branch.
 
902
        balloon = self.make_bzrdir('balloon')
 
903
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
 
904
            stack_on = self.make_branch('stack-on', format='1.9')
 
905
        else:
 
906
            stack_on = self.make_branch('stack-on')
 
907
        config = self.make_bzrdir('.').get_config()
 
908
        try:
 
909
            config.set_default_stack_on('stack-on')
 
910
        except errors.BzrError:
 
911
            raise TestNotApplicable('Only relevant for stackable formats.')
 
912
        # Initialize a bzrdir subject to the policy.
 
913
        t = self.get_transport('stacked')
 
914
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
915
        repo_name = repo_fmt.repository_format.network_name()
 
916
        repo, control = self.assertInitializeEx(
 
917
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
 
918
        # self.addCleanup(repo.unlock)
 
919
        if control is None:
 
920
            # uninitialisable format
 
921
            return
 
922
        # There's one fallback repo, with a public location.
 
923
        self.assertLength(1, repo._fallback_repositories)
 
924
        fallback_repo = repo._fallback_repositories[0]
 
925
        self.assertEqual(
 
926
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
 
927
        # The bzrdir creates a branch in stacking-capable format.
 
928
        new_branch = control.create_branch()
 
929
        self.assertTrue(new_branch._format.supports_stacking())
 
930
 
1110
931
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1111
932
        t = self.get_transport('dir')
1112
933
        repo, control = self.assertInitializeEx(t)
1115
936
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1116
937
        t = self.get_transport('dir')
1117
938
        # 1.6 is likely to never be default
1118
 
        fmt = controldir.format_registry.make_bzrdir('1.6')
 
939
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1119
940
        repo_name = fmt.repository_format.network_name()
1120
941
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1121
 
        if self.bzrdir_format.fixed_components:
 
942
        if control is None:
 
943
            # uninitialisable format
 
944
            return
 
945
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
 
946
            bzrdir.BzrDirFormat6)):
1122
947
            # must stay with the all-in-one-format.
1123
948
            repo_name = self.bzrdir_format.network_name()
1124
949
        self.assertEqual(repo_name, repo._format.network_name())
1125
950
 
1126
 
    def assertInitializeEx(self, t, **kwargs):
 
951
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
1127
952
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1128
953
 
1129
954
        This involves checking that the disk objects were created, open with
1134
959
            initialize_on_transport_ex.
1135
960
        :return: the resulting repo, control dir tuple.
1136
961
        """
1137
 
        if not self.bzrdir_format.is_initializable():
1138
 
            raise TestNotApplicable("control dir format is not "
1139
 
                "initializable")
 
962
        if not self.bzrdir_format.is_supported():
 
963
            # Not initializable - not a failure either.
 
964
            return None, None
1140
965
        repo, control, require_stacking, repo_policy = \
1141
966
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1142
967
        if repo is not None:
1143
968
            # Repositories are open write-locked
1144
969
            self.assertTrue(repo.is_write_locked())
1145
970
            self.addCleanup(repo.unlock)
1146
 
        self.assertIsInstance(control, controldir.ControlDir)
1147
 
        opened = controldir.ControlDir.open(t.base)
 
971
        self.assertIsInstance(control, bzrdir.BzrDir)
 
972
        opened = bzrdir.BzrDir.open(t.base)
1148
973
        expected_format = self.bzrdir_format
1149
 
        if not isinstance(expected_format, RemoteBzrDirFormat):
 
974
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
 
975
            # Current RemoteBzrDirFormat's do not reliably get network_name
 
976
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
 
977
            self.assertIsInstance(control, RemoteBzrDir)
 
978
        else:
 
979
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
 
980
                bzrdir.BzrDirFormat6)):
 
981
                # Pre-metadir formats change when we are making something that
 
982
                # needs a metaformat, because clone is used for push.
 
983
                expected_format = bzrdir.BzrDirMetaFormat1()
1150
984
            self.assertEqual(control._format.network_name(),
1151
985
                expected_format.network_name())
1152
986
            self.assertEqual(control._format.network_name(),
1163
997
        # key in the registry gives back the same format. For remote obects
1164
998
        # we check that the network_name of the RemoteBzrDirFormat we have
1165
999
        # locally matches the actual format present on disk.
1166
 
        if isinstance(format, RemoteBzrDirFormat):
 
1000
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
1167
1001
            dir._ensure_real()
1168
1002
            real_dir = dir._real_bzrdir
1169
1003
            network_name = format.network_name()
1181
1015
        # test the formats specific behaviour for no-content or similar dirs.
1182
1016
        self.assertRaises(errors.NotBranchError,
1183
1017
                          self.bzrdir_format.open,
1184
 
                          transport.get_transport_from_url(self.get_readonly_url()))
 
1018
                          transport.get_transport(self.get_readonly_url()))
1185
1019
 
1186
1020
    def test_create_branch(self):
1187
1021
        # a bzrdir can construct a branch and repository for itself.
1188
 
        if not self.bzrdir_format.is_initializable():
 
1022
        if not self.bzrdir_format.is_supported():
1189
1023
            # unsupported formats are not loopback testable
1190
1024
            # because the default open will not open them and
1191
1025
            # they may not be initializable.
1192
 
            raise TestNotApplicable("format is not initializable")
1193
 
        t = self.get_transport()
 
1026
            return
 
1027
        t = transport.get_transport(self.get_url())
1194
1028
        made_control = self.bzrdir_format.initialize(t.base)
1195
1029
        made_repo = made_control.create_repository()
1196
1030
        made_branch = made_control.create_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.assertEqual(True, made_branch.get_append_revisions_only())
 
1031
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1218
1032
        self.assertEqual(made_control, made_branch.bzrdir)
1219
1033
 
1220
1034
    def test_open_branch(self):
1221
 
        if not self.bzrdir_format.is_initializable():
 
1035
        if not self.bzrdir_format.is_supported():
1222
1036
            # unsupported formats are not loopback testable
1223
1037
            # because the default open will not open them and
1224
1038
            # they may not be initializable.
1225
 
            raise TestNotApplicable("format is not initializable")
1226
 
        t = self.get_transport()
 
1039
            return
 
1040
        t = transport.get_transport(self.get_url())
1227
1041
        made_control = self.bzrdir_format.initialize(t.base)
1228
1042
        made_repo = made_control.create_repository()
1229
1043
        made_branch = made_control.create_branch()
1230
1044
        opened_branch = made_control.open_branch()
1231
1045
        self.assertEqual(made_control, opened_branch.bzrdir)
1232
 
        self.assertIsInstance(opened_branch, made_branch.__class__)
1233
 
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
 
1046
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
 
1047
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1234
1048
 
1235
1049
    def test_list_branches(self):
1236
 
        if not self.bzrdir_format.is_initializable():
1237
 
            raise TestNotApplicable("format is not initializable")
1238
 
        t = self.get_transport()
 
1050
        if not self.bzrdir_format.is_supported():
 
1051
            # unsupported formats are not loopback testable
 
1052
            # because the default open will not open them and
 
1053
            # they may not be initializable.
 
1054
            return
 
1055
        t = transport.get_transport(self.get_url())
1239
1056
        made_control = self.bzrdir_format.initialize(t.base)
1240
1057
        made_repo = made_control.create_repository()
1241
1058
        made_branch = made_control.create_branch()
1242
1059
        branches = made_control.list_branches()
1243
 
        self.assertEqual(1, len(branches))
1244
 
        self.assertEqual(made_branch.base, branches[0].base)
 
1060
        self.assertEquals(1, len(branches))
 
1061
        self.assertEquals(made_branch.base, branches[0].base)
1245
1062
        try:
1246
1063
            made_control.destroy_branch()
1247
1064
        except errors.UnsupportedOperation:
1248
1065
            pass # Not all bzrdirs support destroying directories
1249
1066
        else:
1250
 
            self.assertEqual([], made_control.list_branches())
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())
 
1067
            self.assertEquals([], made_control.list_branches())
1256
1068
 
1257
1069
    def test_create_repository(self):
1258
1070
        # a bzrdir can construct a repository for itself.
1259
 
        if not self.bzrdir_format.is_initializable():
 
1071
        if not self.bzrdir_format.is_supported():
1260
1072
            # unsupported formats are not loopback testable
1261
1073
            # because the default open will not open them and
1262
1074
            # they may not be initializable.
1263
 
            raise TestNotApplicable("format is not initializable")
1264
 
        t = self.get_transport()
 
1075
            return
 
1076
        t = transport.get_transport(self.get_url())
1265
1077
        made_control = self.bzrdir_format.initialize(t.base)
1266
1078
        made_repo = made_control.create_repository()
1267
1079
        # Check that we have a repository object.
1271
1083
    def test_create_repository_shared(self):
1272
1084
        # a bzrdir can create a shared repository or
1273
1085
        # fail appropriately
1274
 
        if not self.bzrdir_format.is_initializable():
 
1086
        if not self.bzrdir_format.is_supported():
1275
1087
            # unsupported formats are not loopback testable
1276
1088
            # because the default open will not open them and
1277
1089
            # they may not be initializable.
1278
 
            raise TestNotApplicable("format is not initializable")
1279
 
        t = self.get_transport()
 
1090
            return
 
1091
        t = transport.get_transport(self.get_url())
1280
1092
        made_control = self.bzrdir_format.initialize(t.base)
1281
1093
        try:
1282
1094
            made_repo = made_control.create_repository(shared=True)
1283
1095
        except errors.IncompatibleFormat:
1284
1096
            # Old bzrdir formats don't support shared repositories
1285
1097
            # and should raise IncompatibleFormat
1286
 
            raise TestNotApplicable("format does not support shared "
1287
 
                "repositories")
 
1098
            return
1288
1099
        self.assertTrue(made_repo.is_shared())
1289
1100
 
1290
1101
    def test_create_repository_nonshared(self):
1291
1102
        # a bzrdir can create a non-shared repository
1292
 
        if not self.bzrdir_format.is_initializable():
 
1103
        if not self.bzrdir_format.is_supported():
1293
1104
            # unsupported formats are not loopback testable
1294
1105
            # because the default open will not open them and
1295
1106
            # they may not be initializable.
1296
 
            raise TestNotApplicable("format is not initializable")
1297
 
        t = self.get_transport()
 
1107
            return
 
1108
        t = transport.get_transport(self.get_url())
1298
1109
        made_control = self.bzrdir_format.initialize(t.base)
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")
 
1110
        made_repo = made_control.create_repository(shared=False)
1306
1111
        self.assertFalse(made_repo.is_shared())
1307
1112
 
1308
1113
    def test_open_repository(self):
1309
 
        if not self.bzrdir_format.is_initializable():
 
1114
        if not self.bzrdir_format.is_supported():
1310
1115
            # unsupported formats are not loopback testable
1311
1116
            # because the default open will not open them and
1312
1117
            # they may not be initializable.
1313
 
            raise TestNotApplicable("format is not initializable")
1314
 
        t = self.get_transport()
 
1118
            return
 
1119
        t = transport.get_transport(self.get_url())
1315
1120
        made_control = self.bzrdir_format.initialize(t.base)
1316
1121
        made_repo = made_control.create_repository()
1317
1122
        opened_repo = made_control.open_repository()
1318
1123
        self.assertEqual(made_control, opened_repo.bzrdir)
1319
 
        self.assertIsInstance(opened_repo, made_repo.__class__)
1320
 
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
 
1124
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
 
1125
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1321
1126
 
1322
1127
    def test_create_workingtree(self):
1323
1128
        # a bzrdir can construct a working tree for itself.
1324
 
        if not self.bzrdir_format.is_initializable():
 
1129
        if not self.bzrdir_format.is_supported():
1325
1130
            # unsupported formats are not loopback testable
1326
1131
            # because the default open will not open them and
1327
1132
            # they may not be initializable.
1328
 
            raise TestNotApplicable("format is not initializable")
 
1133
            return
1329
1134
        t = self.get_transport()
1330
1135
        made_control = self.bzrdir_format.initialize(t.base)
1331
1136
        made_repo = made_control.create_repository()
1332
1137
        made_branch = made_control.create_branch()
1333
1138
        made_tree = self.createWorkingTreeOrSkip(made_control)
1334
 
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
 
1139
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1335
1140
        self.assertEqual(made_control, made_tree.bzrdir)
1336
1141
 
1337
1142
    def test_create_workingtree_revision(self):
1338
1143
        # 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")
1341
1144
        t = self.get_transport()
1342
1145
        source = self.make_branch_and_tree('source')
1343
1146
        source.commit('a', rev_id='a', allow_pointless=True)
1354
1157
        self.assertEqual(['a'], made_tree.get_parent_ids())
1355
1158
 
1356
1159
    def test_open_workingtree(self):
1357
 
        if not self.bzrdir_format.is_initializable():
1358
 
            raise TestNotApplicable("format is not initializable")
 
1160
        if not self.bzrdir_format.is_supported():
 
1161
            # unsupported formats are not loopback testable
 
1162
            # because the default open will not open them and
 
1163
            # they may not be initializable.
 
1164
            return
1359
1165
        # this has to be tested with local access as we still support creating
1360
1166
        # format 6 bzrdirs
1361
1167
        t = self.get_transport()
1369
1175
                              % (self.bzrdir_format, t))
1370
1176
        opened_tree = made_control.open_workingtree()
1371
1177
        self.assertEqual(made_control, opened_tree.bzrdir)
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.assertEqual({"branch": "foo"},
1388
 
            dir.user_transport.get_segment_parameters())
1389
 
        self.assertEqual("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())
 
1178
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
 
1179
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
 
1180
 
 
1181
    def test_get_branch_transport(self):
 
1182
        dir = self.make_bzrdir('.')
 
1183
        # without a format, get_branch_transport gives use a transport
 
1184
        # which -may- point to an existing dir.
 
1185
        self.assertTrue(isinstance(dir.get_branch_transport(None),
 
1186
                                   transport.Transport))
 
1187
        # with a given format, either the bzr dir supports identifiable
 
1188
        # branches, or it supports anonymous  branch formats, but not both.
 
1189
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
 
1190
        identifiable_format = bzrlib.branch.BzrBranchFormat5()
 
1191
        try:
 
1192
            found_transport = dir.get_branch_transport(anonymous_format)
 
1193
            self.assertRaises(errors.IncompatibleFormat,
 
1194
                              dir.get_branch_transport,
 
1195
                              identifiable_format)
 
1196
        except errors.IncompatibleFormat:
 
1197
            found_transport = dir.get_branch_transport(identifiable_format)
 
1198
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
1199
        # and the dir which has been initialized for us must exist.
 
1200
        found_transport.list_dir('.')
 
1201
 
 
1202
    def test_get_repository_transport(self):
 
1203
        dir = self.make_bzrdir('.')
 
1204
        # without a format, get_repository_transport gives use a transport
 
1205
        # which -may- point to an existing dir.
 
1206
        self.assertTrue(isinstance(dir.get_repository_transport(None),
 
1207
                                   transport.Transport))
 
1208
        # with a given format, either the bzr dir supports identifiable
 
1209
        # repositories, or it supports anonymous  repository formats, but not both.
 
1210
        anonymous_format = weaverepo.RepositoryFormat6()
 
1211
        identifiable_format = weaverepo.RepositoryFormat7()
 
1212
        try:
 
1213
            found_transport = dir.get_repository_transport(anonymous_format)
 
1214
            self.assertRaises(errors.IncompatibleFormat,
 
1215
                              dir.get_repository_transport,
 
1216
                              identifiable_format)
 
1217
        except errors.IncompatibleFormat:
 
1218
            found_transport = dir.get_repository_transport(identifiable_format)
 
1219
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
1220
        # and the dir which has been initialized for us must exist.
 
1221
        found_transport.list_dir('.')
 
1222
 
 
1223
    def test_get_workingtree_transport(self):
 
1224
        dir = self.make_bzrdir('.')
 
1225
        # without a format, get_workingtree_transport gives use a transport
 
1226
        # which -may- point to an existing dir.
 
1227
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
 
1228
                                   transport.Transport))
 
1229
        # with a given format, either the bzr dir supports identifiable
 
1230
        # trees, or it supports anonymous tree formats, but not both.
 
1231
        anonymous_format = workingtree.WorkingTreeFormat2()
 
1232
        identifiable_format = workingtree.WorkingTreeFormat3()
 
1233
        try:
 
1234
            found_transport = dir.get_workingtree_transport(anonymous_format)
 
1235
            self.assertRaises(errors.IncompatibleFormat,
 
1236
                              dir.get_workingtree_transport,
 
1237
                              identifiable_format)
 
1238
        except errors.IncompatibleFormat:
 
1239
            found_transport = dir.get_workingtree_transport(identifiable_format)
 
1240
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
1241
        # and the dir which has been initialized for us must exist.
 
1242
        found_transport.list_dir('.')
1403
1243
 
1404
1244
    def test_root_transport(self):
1405
1245
        dir = self.make_bzrdir('.')
1406
1246
        self.assertEqual(dir.root_transport.base,
1407
 
                         self.get_transport().base)
 
1247
                         transport.get_transport(self.get_url('.')).base)
1408
1248
 
1409
1249
    def test_find_repository_no_repo_under_standalone_branch(self):
1410
1250
        # finding a repo stops at standalone branches even if there is a
1413
1253
            repo = self.make_repository('.', shared=True)
1414
1254
        except errors.IncompatibleFormat:
1415
1255
            # need a shared repository to test this.
1416
 
            raise TestNotApplicable("requires shared repository support")
1417
 
        if not repo._format.supports_nesting_repositories:
1418
 
            raise TestNotApplicable("requires nesting repositories")
 
1256
            return
1419
1257
        url = self.get_url('intermediate')
1420
 
        t = self.get_transport()
1421
 
        t.mkdir('intermediate')
1422
 
        t.mkdir('intermediate/child')
 
1258
        transport.get_transport(self.get_url()).mkdir('intermediate')
 
1259
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
1423
1260
        made_control = self.bzrdir_format.initialize(url)
1424
1261
        made_control.create_repository()
1425
1262
        innermost_control = self.bzrdir_format.initialize(
1441
1278
            repo = self.make_repository('.', shared=True)
1442
1279
        except errors.IncompatibleFormat:
1443
1280
            # need a shared repository to test this.
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")
 
1281
            return
1449
1282
        url = self.get_url('childbzrdir')
1450
 
        self.get_transport().mkdir('childbzrdir')
 
1283
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
1451
1284
        made_control = self.bzrdir_format.initialize(url)
1452
1285
        try:
1453
1286
            child_repo = made_control.open_repository()
1461
1294
                         found_repo.bzrdir.root_transport.base)
1462
1295
 
1463
1296
    def test_find_repository_standalone_with_containing_shared_repository(self):
1464
 
        # find repo inside a standalone repo inside a shared repo finds the
1465
 
        # standalone repo
 
1297
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1466
1298
        try:
1467
1299
            containing_repo = self.make_repository('.', shared=True)
1468
1300
        except errors.IncompatibleFormat:
1469
1301
            # need a shared repository to test this.
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")
 
1302
            return
1475
1303
        child_repo = self.make_repository('childrepo')
1476
 
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
 
1304
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1477
1305
        found_repo = opened_control.find_repository()
1478
1306
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1479
1307
                         found_repo.bzrdir.root_transport.base)
1484
1312
            containing_repo = self.make_repository('.', shared=True)
1485
1313
        except errors.IncompatibleFormat:
1486
1314
            # need a shared repository to test this.
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")
 
1315
            return
1492
1316
        url = self.get_url('childrepo')
1493
 
        self.get_transport().mkdir('childrepo')
 
1317
        transport.get_transport(self.get_url()).mkdir('childrepo')
1494
1318
        child_control = self.bzrdir_format.initialize(url)
1495
1319
        child_repo = child_control.create_repository(shared=True)
1496
 
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
 
1320
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1497
1321
        found_repo = opened_control.find_repository()
1498
1322
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1499
1323
                         found_repo.bzrdir.root_transport.base)
1507
1331
            repo = self.make_repository('.', shared=True)
1508
1332
        except errors.IncompatibleFormat:
1509
1333
            # need a shared repository to test this.
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")
 
1334
            return
1515
1335
        url = self.get_url('intermediate')
1516
 
        t = self.get_transport()
1517
 
        t.mkdir('intermediate')
1518
 
        t.mkdir('intermediate/child')
 
1336
        transport.get_transport(self.get_url()).mkdir('intermediate')
 
1337
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
1519
1338
        made_control = self.bzrdir_format.initialize(url)
1520
1339
        try:
1521
1340
            child_repo = made_control.open_repository()
1545
1364
            # (we force the latest known format as downgrades may not be
1546
1365
            # available
1547
1366
            self.assertTrue(isinstance(dir._format.get_converter(
1548
 
                format=dir._format), controldir.Converter))
 
1367
                format=dir._format), bzrdir.Converter))
1549
1368
        dir.needs_format_conversion(
1550
1369
            controldir.ControlDirFormat.get_default_format())
1551
1370
 
1557
1376
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1558
1377
        old_path = urlutils.local_path_from_url(old_url)
1559
1378
        new_path = urlutils.local_path_from_url(new_url)
1560
 
        self.assertPathExists(old_path)
1561
 
        self.assertPathExists(new_path)
 
1379
        self.failUnlessExists(old_path)
 
1380
        self.failUnlessExists(new_path)
1562
1381
        for (((dir_relpath1, _), entries1),
1563
1382
             ((dir_relpath2, _), entries2)) in izip(
1564
1383
                osutils.walkdirs(old_path),
1565
1384
                osutils.walkdirs(new_path)):
1566
 
            self.assertEqual(dir_relpath1, dir_relpath2)
 
1385
            self.assertEquals(dir_relpath1, dir_relpath2)
1567
1386
            for f1, f2 in zip(entries1, entries2):
1568
 
                self.assertEqual(f1[0], f2[0])
1569
 
                self.assertEqual(f1[2], f2[2])
 
1387
                self.assertEquals(f1[0], f2[0])
 
1388
                self.assertEquals(f1[2], f2[2])
1570
1389
                if f1[2] == "file":
1571
1390
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1572
1391
 
1592
1411
    def test_format_description(self):
1593
1412
        dir = self.make_bzrdir('.')
1594
1413
        text = dir._format.get_format_description()
1595
 
        self.assertTrue(len(text))
 
1414
        self.failUnless(len(text))
1596
1415
 
1597
1416
 
1598
1417
class TestBreakLock(TestCaseWithControlDir):
1615
1434
            # and thus this interaction cannot be tested at the interface
1616
1435
            # level.
1617
1436
            repo.unlock()
1618
 
            raise TestNotApplicable("format does not physically lock")
 
1437
            return
1619
1438
        # only one yes needed here: it should only be unlocking
1620
1439
        # the repo
1621
1440
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1624
1443
        except NotImplementedError:
1625
1444
            # this bzrdir does not implement break_lock - so we cant test it.
1626
1445
            repo.unlock()
1627
 
            raise TestNotApplicable("format does not support breaking locks")
 
1446
            return
1628
1447
        lock_repo.lock_write()
1629
1448
        lock_repo.unlock()
1630
1449
        self.assertRaises(errors.LockBroken, repo.unlock)
1638
1457
        master = self.make_branch('branch')
1639
1458
        thisdir = self.make_bzrdir('this')
1640
1459
        try:
1641
 
            thisdir.set_branch_reference(master)
 
1460
            bzrlib.branch.BranchReferenceFormat().initialize(
 
1461
                thisdir, target_branch=master)
1642
1462
        except errors.IncompatibleFormat:
1643
 
            raise TestNotApplicable("format does not support "
1644
 
                "branch references")
 
1463
            return
1645
1464
        unused_repo = thisdir.create_repository()
1646
1465
        master.lock_write()
1647
1466
        unused_repo.lock_write()
1694
1513
            # raised a LockActive because we do still have a live locked
1695
1514
            # object.
1696
1515
            tree.unlock()
1697
 
            raise TestNotApplicable("format does not support breaking locks")
 
1516
            return
1698
1517
        self.assertEqual([True],
1699
1518
                bzrlib.ui.ui_factory.responses)
1700
1519
        lock_tree = tree.bzrdir.open_workingtree()
1713
1532
        except errors.BzrError, e:
1714
1533
            if 'Cannot set config' in str(e):
1715
1534
                self.assertFalse(
1716
 
                    isinstance(my_dir, (_mod_bzrdir.BzrDirMeta1, RemoteBzrDir)),
 
1535
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1717
1536
                    "%r should support configs" % my_dir)
1718
1537
                raise TestNotApplicable(
1719
1538
                    'This BzrDir format does not support configs.')
1720
1539
            else:
1721
1540
                raise
1722
1541
        self.assertEqual('http://example.com', config.get_default_stack_on())
1723
 
        my_dir2 = controldir.ControlDir.open(self.get_url('.'))
 
1542
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
1724
1543
        config2 = my_dir2.get_config()
1725
1544
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1726
1545
 
1730
1549
    def test_find_repository_no_repository(self):
1731
1550
        # loopback test to check the current format fails to find a
1732
1551
        # share repository correctly.
1733
 
        if not self.bzrdir_format.is_initializable():
 
1552
        if not self.bzrdir_format.is_supported():
1734
1553
            # unsupported formats are not loopback testable
1735
1554
            # because the default open will not open them and
1736
1555
            # they may not be initializable.
1737
 
            raise TestNotApplicable("format is not initializable")
 
1556
            return
1738
1557
        # supported formats must be able to init and open
1739
1558
        # - do the vfs initialisation over the basic vfs transport
1740
1559
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1741
1560
        url = self.get_vfs_only_url('subdir')
1742
 
        transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
 
1561
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
1743
1562
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1744
1563
        try:
1745
1564
            repo = made_control.open_repository()
1748
1567
            return
1749
1568
        except errors.NoRepositoryPresent:
1750
1569
            pass
1751
 
        made_control = controldir.ControlDir.open(self.get_readonly_url('subdir'))
 
1570
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1752
1571
        self.assertRaises(errors.NoRepositoryPresent,
1753
1572
                          made_control.find_repository)
1754
1573