~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
20
20
 
21
21
import bzrlib.branch
22
22
from bzrlib import (
23
 
    bzrdir,
 
23
    bzrdir as _mod_bzrdir,
24
24
    check,
25
25
    controldir,
26
26
    errors,
27
27
    gpg,
28
28
    osutils,
 
29
    revision as _mod_revision,
29
30
    transport,
30
31
    ui,
31
32
    urlutils,
32
33
    workingtree,
33
34
    )
34
 
import bzrlib.revision
35
35
from bzrlib.tests import (
36
36
    fixtures,
37
37
    ChrootedTestCase,
101
101
                                    create_tree_if_local=create_tree_if_local)
102
102
        return target
103
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
 
104
122
    def test_create_null_workingtree(self):
105
123
        dir = self.make_bzrdir('dir1')
106
124
        dir.create_repository()
107
125
        dir.create_branch()
108
126
        try:
109
 
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
127
            wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
110
128
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
111
129
            raise TestSkipped("cannot make working tree with transport %r"
112
130
                              % dir.transport)
141
159
        bzrdir.create_branch()
142
160
        bzrdir.open_branch()
143
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
 
144
170
    def test_destroy_repository(self):
145
171
        repo = self.make_repository('repository')
146
172
        bzrdir = repo.bzrdir
149
175
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
150
176
            raise TestNotApplicable('Format does not support destroying'
151
177
                                    ' repository')
 
178
        self.assertRaises(errors.NoRepositoryPresent,
 
179
            bzrdir.destroy_repository)
152
180
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
153
181
        bzrdir.create_repository()
154
182
        bzrdir.open_repository()
158
186
        e.g. NotLocalUrl) if there is no working tree.
159
187
        """
160
188
        dir = self.make_bzrdir('source')
161
 
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
 
189
        vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
162
190
        if vfs_dir.has_workingtree():
163
191
            # This ControlDir format doesn't support ControlDirs without
164
192
            # working trees, so this test is irrelevant.
165
 
            return
 
193
            raise TestNotApplicable("format does not support "
 
194
                "control directories without working tree")
166
195
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
167
196
 
168
197
    def test_clone_bzrdir_repository_under_shared(self):
172
201
        tree.commit('revision 1', rev_id='1')
173
202
        dir = self.make_bzrdir('source')
174
203
        repo = dir.create_repository()
 
204
        if not repo._format.supports_nesting_repositories:
 
205
            raise TestNotApplicable("repository format does not support "
 
206
                "nesting")
175
207
        repo.fetch(tree.branch.repository)
176
208
        self.assertTrue(repo.has_revision('1'))
177
209
        try:
178
210
            self.make_repository('target', shared=True)
179
211
        except errors.IncompatibleFormat:
180
 
            return
 
212
            raise TestNotApplicable("repository format does not support "
 
213
                "shared repositories")
181
214
        target = dir.clone(self.get_url('target/child'))
182
215
        self.assertNotEqual(dir.transport.base, target.transport.base)
183
216
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
187
220
        try:
188
221
            shared_repo = self.make_repository('shared', shared=True)
189
222
        except errors.IncompatibleFormat:
190
 
            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")
191
228
        # Make a branch, 'commit_tree', and working tree outside of the shared
192
229
        # repository, and commit some revisions to it.
193
230
        tree = self.make_branch_and_tree('commit_tree')
195
232
        tree.add('foo')
196
233
        tree.commit('revision 1', rev_id='1')
197
234
        tree.bzrdir.open_branch().generate_revision_history(
198
 
            bzrlib.revision.NULL_REVISION)
 
235
            _mod_revision.NULL_REVISION)
199
236
        tree.set_parent_trees([])
200
237
        tree.commit('revision 2', rev_id='2')
201
238
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
218
255
        try:
219
256
            shared_repo = self.make_repository('shared', shared=True)
220
257
        except errors.IncompatibleFormat:
221
 
            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")
222
263
        tree = self.make_branch_and_tree('commit_tree')
223
264
        self.build_tree(['commit_tree/foo'])
224
265
        tree.add('foo')
225
266
        tree.commit('revision 1', rev_id='1')
226
267
        tree.branch.bzrdir.open_branch().generate_revision_history(
227
 
            bzrlib.revision.NULL_REVISION)
 
268
            _mod_revision.NULL_REVISION)
228
269
        tree.set_parent_trees([])
229
270
        tree.commit('revision 2', rev_id='2')
230
271
        tree.branch.repository.copy_content_into(shared_repo)
252
293
        tree.add('foo')
253
294
        tree.commit('revision 1', rev_id='1')
254
295
        tree.branch.bzrdir.open_branch().generate_revision_history(
255
 
            bzrlib.revision.NULL_REVISION)
 
296
            _mod_revision.NULL_REVISION)
256
297
        tree.set_parent_trees([])
257
298
        tree.commit('revision 2', rev_id='2')
258
299
        source = self.make_repository('source')
292
333
        tree.branch.repository.copy_content_into(source.repository)
293
334
        tree.branch.copy_content_into(source)
294
335
        try:
295
 
            self.make_repository('target', shared=True)
 
336
            shared_repo = self.make_repository('target', shared=True)
296
337
        except errors.IncompatibleFormat:
297
 
            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")
298
343
        dir = source.bzrdir
299
344
        target = dir.clone(self.get_url('target/child'))
300
345
        self.assertNotEqual(dir.transport.base, target.transport.base)
301
346
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
302
 
        self.assertEqual(source.revision_history(),
303
 
                         target.open_branch().revision_history())
 
347
        self.assertEqual(source.last_revision(),
 
348
                         target.open_branch().last_revision())
304
349
 
305
350
    def test_clone_bzrdir_branch_revision(self):
306
351
        # test for revision limiting, [smoke test, not corner case checks].
320
365
        self.assertEqual('1', target.open_branch().last_revision())
321
366
 
322
367
    def test_clone_on_transport_preserves_repo_format(self):
323
 
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
 
368
        if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
324
369
            format = 'knit'
325
370
        else:
326
371
            format = None
369
414
            repo.set_make_working_trees(False)
370
415
            self.assertFalse(repo.make_working_trees())
371
416
 
372
 
        dir = tree.bzrdir
373
 
        a_dir = dir.clone(self.get_url('repo/a'))
374
 
        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')
375
423
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
376
424
 
377
425
    def test_clone_respects_stacked(self):
378
426
        branch = self.make_branch('parent')
379
427
        child_transport = self.get_transport('child')
380
 
        child = branch.bzrdir.clone_on_transport(child_transport,
381
 
                                                 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")
382
435
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
383
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
 
384
481
    def test_get_branch_reference_on_reference(self):
385
482
        """get_branch_reference should return the right url."""
386
483
        referenced_branch = self.make_branch('referenced')
387
484
        dir = self.make_bzrdir('source')
388
485
        try:
389
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
390
 
                target_branch=referenced_branch)
 
486
            dir.set_branch_reference(referenced_branch)
391
487
        except errors.IncompatibleFormat:
392
488
            # this is ok too, not all formats have to support references.
393
 
            return
 
489
            raise TestNotApplicable("control directory does not "
 
490
                "support branch references")
394
491
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
395
492
            dir.get_branch_reference())
396
493
 
404
501
        dir = self.make_bzrdir('source')
405
502
        if dir.has_branch():
406
503
            # this format does not support branchless bzrdirs.
407
 
            return
 
504
            raise TestNotApplicable("format does not support "
 
505
                "branchless control directories")
408
506
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
409
507
 
410
508
    def test_sprout_bzrdir_empty(self):
411
509
        dir = self.make_bzrdir('source')
412
510
        target = dir.sprout(self.get_url('target'))
413
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
511
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
414
512
        # creates a new repository branch and tree
415
513
        target.open_repository()
416
514
        target.open_branch()
422
520
        try:
423
521
            self.make_repository('target', shared=True)
424
522
        except errors.IncompatibleFormat:
425
 
            return
 
523
            raise TestNotApplicable("format does not support shared "
 
524
                "repositories")
426
525
        target = dir.sprout(self.get_url('target/child'))
427
526
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
428
527
        target.open_branch()
430
529
            target.open_workingtree()
431
530
        except errors.NoWorkingTree:
432
531
            # Some bzrdirs can never have working trees.
433
 
            self.assertFalse(target._format.supports_workingtrees)
 
532
            repo = target.find_repository()
 
533
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
434
534
 
435
535
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
436
536
        # the force_new_repo parameter should force use of a new repo in an empty
439
539
        try:
440
540
            self.make_repository('target', shared=True)
441
541
        except errors.IncompatibleFormat:
442
 
            return
 
542
            raise TestNotApplicable("format does not support shared "
 
543
                "repositories")
443
544
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
444
545
        target.open_repository()
445
546
        target.open_branch()
451
552
        tree.add('foo')
452
553
        tree.commit('revision 1', rev_id='1')
453
554
        tree.bzrdir.open_branch().generate_revision_history(
454
 
            bzrlib.revision.NULL_REVISION)
 
555
            _mod_revision.NULL_REVISION)
455
556
        tree.set_parent_trees([])
456
557
        tree.commit('revision 2', rev_id='2')
457
558
        source = self.make_repository('source')
460
561
        try:
461
562
            shared_repo = self.make_repository('target', shared=True)
462
563
        except errors.IncompatibleFormat:
463
 
            return
 
564
            raise TestNotApplicable("format does not support "
 
565
                "shared repositories")
464
566
        target = dir.sprout(self.get_url('target/child'))
465
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
567
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
466
568
        self.assertTrue(shared_repo.has_revision('1'))
467
569
 
468
570
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
469
571
        try:
470
572
            shared_repo = self.make_repository('shared', shared=True)
471
573
        except errors.IncompatibleFormat:
472
 
            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")
473
579
        tree = self.make_branch_and_tree('commit_tree')
474
580
        self.build_tree(['commit_tree/foo'])
475
581
        tree.add('foo')
476
582
        tree.commit('revision 1', rev_id='1')
477
583
        tree.bzrdir.open_branch().generate_revision_history(
478
 
            bzrlib.revision.NULL_REVISION)
 
584
            _mod_revision.NULL_REVISION)
479
585
        tree.set_parent_trees([])
480
586
        tree.commit('revision 2', rev_id='2')
481
587
        tree.branch.repository.copy_content_into(shared_repo)
490
596
        try:
491
597
            shared_repo = self.make_repository('shared', shared=True)
492
598
        except errors.IncompatibleFormat:
493
 
            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")
494
604
        tree = self.make_branch_and_tree('commit_tree')
495
605
        self.build_tree(['commit_tree/foo'])
496
606
        tree.add('foo')
497
607
        tree.commit('revision 1', rev_id='1')
498
608
        tree.bzrdir.open_branch().generate_revision_history(
499
 
            bzrlib.revision.NULL_REVISION)
 
609
            _mod_revision.NULL_REVISION)
500
610
        tree.set_parent_trees([])
501
611
        tree.commit('revision 2', rev_id='2')
502
612
        tree.branch.repository.copy_content_into(shared_repo)
524
634
        tree.add('foo')
525
635
        tree.commit('revision 1', rev_id='1')
526
636
        tree.bzrdir.open_branch().generate_revision_history(
527
 
            bzrlib.revision.NULL_REVISION)
 
637
            _mod_revision.NULL_REVISION)
528
638
        tree.set_parent_trees([])
529
639
        tree.commit('revision 2', rev_id='2')
530
640
        source = self.make_repository('source')
533
643
        try:
534
644
            shared_repo = self.make_repository('target', shared=True)
535
645
        except errors.IncompatibleFormat:
536
 
            return
 
646
            raise TestNotApplicable("format does not support shared "
 
647
                "repositories")
537
648
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
538
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
649
        self.assertNotEqual(
 
650
            dir.control_transport.base,
 
651
            target.control_transport.base)
539
652
        self.assertFalse(shared_repo.has_revision('1'))
540
653
 
541
654
    def test_sprout_bzrdir_repository_revision(self):
548
661
        tree.add('foo')
549
662
        tree.commit('revision 1', rev_id='1')
550
663
        br = tree.bzrdir.open_branch()
551
 
        br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
 
664
        br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
552
665
        tree.set_parent_trees([])
553
666
        tree.commit('revision 2', rev_id='2')
554
667
        source = self.make_repository('source')
571
684
        try:
572
685
            shared_repo = self.make_repository('target', shared=True)
573
686
        except errors.IncompatibleFormat:
574
 
            return
 
687
            raise TestNotApplicable("format does not support shared "
 
688
                "repositories")
575
689
        target = dir.sprout(self.get_url('target/child'))
576
690
        self.assertTrue(shared_repo.has_revision('1'))
577
691
 
589
703
        try:
590
704
            shared_repo = self.make_repository('target', shared=True)
591
705
        except errors.IncompatibleFormat:
592
 
            return
 
706
            raise TestNotApplicable("format does not support shared "
 
707
                "repositories")
593
708
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
594
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
709
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
595
710
        self.assertFalse(shared_repo.has_revision('1'))
596
711
 
597
712
    def test_sprout_bzrdir_branch_reference(self):
599
714
        referenced_branch = self.make_branch('referenced')
600
715
        dir = self.make_bzrdir('source')
601
716
        try:
602
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
603
 
                target_branch=referenced_branch)
 
717
            dir.set_branch_reference(referenced_branch)
604
718
        except errors.IncompatibleFormat:
605
 
            # this is ok too, not all formats have to support references.
606
 
            return
 
719
            raise TestNotApplicable("format does not support branch "
 
720
                "references")
607
721
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
608
722
        target = dir.sprout(self.get_url('target'))
609
723
        self.assertNotEqual(dir.transport.base, target.transport.base)
619
733
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
620
734
        dir = self.make_bzrdir('source')
621
735
        try:
622
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
623
 
                target_branch=referenced_tree.branch)
 
736
            dir.set_branch_reference(referenced_tree.branch)
624
737
        except errors.IncompatibleFormat:
625
 
            # this is ok too, not all formats have to support references.
626
 
            return
 
738
            raise TestNotApplicable("format does not support branch "
 
739
                "references")
627
740
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
628
741
        try:
629
742
            shared_repo = self.make_repository('target', shared=True)
630
743
        except errors.IncompatibleFormat:
631
 
            return
 
744
            raise TestNotApplicable("format does not support "
 
745
                "shared repositories")
632
746
        target = dir.sprout(self.get_url('target/child'))
633
747
        self.assertNotEqual(dir.transport.base, target.transport.base)
634
748
        # we want target to have a branch that is in-place.
645
759
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
646
760
        dir = self.make_bzrdir('source')
647
761
        try:
648
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
649
 
                target_branch=referenced_tree.branch)
 
762
            dir.set_branch_reference(referenced_tree.branch)
650
763
        except errors.IncompatibleFormat:
651
764
            # this is ok too, not all formats have to support references.
652
 
            return
 
765
            raise TestNotApplicable("format does not support "
 
766
                "branch references")
653
767
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
654
768
        try:
655
769
            shared_repo = self.make_repository('target', shared=True)
656
770
        except errors.IncompatibleFormat:
657
 
            return
 
771
            raise TestNotApplicable("format does not support shared "
 
772
                "repositories")
658
773
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
659
774
        self.assertNotEqual(dir.transport.base, target.transport.base)
660
775
        # we want target to have a branch that is in-place.
690
805
            source.tags.set_tag('tag-a', 'rev-2')
691
806
        except errors.TagsNotSupported:
692
807
            raise TestNotApplicable('Branch format does not support tags.')
 
808
        source.get_config_stack().set('branch.fetch_tags', True)
693
809
        # Now source has a tag not in its ancestry.  Sprout its controldir.
694
810
        dir = source.bzrdir
695
811
        target = dir.sprout(self.get_url('target'))
706
822
        source = builder.get_branch()
707
823
        try:
708
824
            source.tags.set_tag('tag-a', 'missing-rev')
709
 
        except errors.TagsNotSupported:
710
 
            raise TestNotApplicable('Branch format does not support tags.')
 
825
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
826
            raise TestNotApplicable('Branch format does not support tags '
 
827
                'or tags referencing ghost revisions.')
711
828
        # Now source has a tag pointing to an absent revision.  Sprout its
712
829
        # controldir.
713
830
        dir = source.bzrdir
724
841
        source = builder.get_branch()
725
842
        try:
726
843
            source.tags.set_tag('tag-a', 'missing-rev')
727
 
        except errors.TagsNotSupported:
728
 
            raise TestNotApplicable('Branch format does not support tags.')
 
844
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
845
            raise TestNotApplicable('Branch format does not support tags '
 
846
                'or tags referencing missing revisions.')
729
847
        # Now source has a tag pointing to an absent revision.  Sprout its
730
848
        # controldir.
731
849
        dir = source.bzrdir
758
876
        try:
759
877
            # Create a tag for B2, and for an absent rev
760
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:
761
882
            source.tags.set_tag('tag-absent', 'absent-rev')
762
 
        except errors.TagsNotSupported:
763
 
            raise TestNotApplicable('Branch format does not support tags.')
 
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)
764
888
        # And ask sprout for C2
765
889
        dir = source.bzrdir
766
890
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
767
891
        # The tags are present
768
892
        new_branch = target.open_branch()
769
 
        self.assertEqual(
770
 
            {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
771
 
            new_branch.tags.get_tag_dict())
 
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())
772
901
        # And the revs for A2, B2 and C2's ancestries are present, but no
773
902
        # others.
774
903
        self.assertEqual(
781
910
        referenced_branch = self.make_branch('referencced')
782
911
        dir = self.make_bzrdir('source')
783
912
        try:
784
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
785
 
                target_branch=referenced_branch)
 
913
            dir.set_branch_reference(referenced_branch)
786
914
        except errors.IncompatibleFormat:
787
915
            # this is ok too, not all formats have to support references.
788
 
            return
 
916
            raise TestNotApplicable("format does not support "
 
917
                "branch references")
789
918
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
790
919
        tree = self.createWorkingTreeOrSkip(dir)
791
920
        self.build_tree(['source/subdir/'])
807
936
        referenced_branch = self.make_branch('referencced')
808
937
        dir = self.make_bzrdir('source')
809
938
        try:
810
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
811
 
                target_branch=referenced_branch)
 
939
            dir.set_branch_reference(referenced_branch)
812
940
        except errors.IncompatibleFormat:
813
941
            # this is ok too, not all formats have to support references.
814
 
            return
 
942
            raise TestNotApplicable("format does not support "
 
943
                "branch references")
815
944
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
816
945
        tree = self.createWorkingTreeOrSkip(dir)
817
946
        self.build_tree(['source/foo'])
897
1026
 
898
1027
    def test_format_initialize_find_open(self):
899
1028
        # loopback test to check the current format initializes to itself.
900
 
        if not self.bzrdir_format.is_supported():
 
1029
        if not self.bzrdir_format.is_initializable():
901
1030
            # unsupported formats are not loopback testable
902
1031
            # because the default open will not open them and
903
1032
            # they may not be initializable.
904
 
            return
 
1033
            raise TestNotApplicable("format is not initializable")
905
1034
        # for remote formats, there must be no prior assumption about the
906
1035
        # network name to use - it's possible that this may somehow have got
907
1036
        # in through an unisolated test though - see
908
1037
        # <https://bugs.launchpad.net/bzr/+bug/504102>
909
 
        self.assertEquals(getattr(self.bzrdir_format,
 
1038
        self.assertEqual(getattr(self.bzrdir_format,
910
1039
            '_network_name', None),
911
1040
            None)
912
1041
        # supported formats must be able to init and open
919
1048
        self.assertEqual(self.bzrdir_format,
920
1049
                         controldir.ControlDirFormat.find_format(readonly_t))
921
1050
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
922
 
        opened_dir = bzrdir.BzrDir.open(t.base)
 
1051
        opened_dir = controldir.ControlDir.open(t.base)
923
1052
        self.assertEqual(made_control._format,
924
1053
                         opened_dir._format)
925
1054
        self.assertEqual(direct_opened_dir._format,
936
1065
        self.assertInitializeEx(t, use_existing_dir=True)
937
1066
 
938
1067
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
939
 
        if not self.bzrdir_format.is_supported():
940
 
            # Not initializable - not a failure either.
941
 
            return
 
1068
        if not self.bzrdir_format.is_initializable():
 
1069
            raise TestNotApplicable("format is not initializable")
942
1070
        t = self.get_transport('dir')
943
1071
        t.ensure_base()
944
1072
        self.assertRaises(errors.FileExists,
950
1078
        self.assertInitializeEx(t, create_prefix=True)
951
1079
 
952
1080
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
953
 
        if not self.bzrdir_format.is_supported():
954
 
            # Not initializable - not a failure either.
955
 
            return
 
1081
        if not self.bzrdir_format.is_initializable():
 
1082
            raise TestNotApplicable("format is not initializable")
956
1083
        t = self.get_transport('missing/dir')
957
1084
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
958
1085
            create_prefix=False)
959
1086
 
960
1087
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
961
1088
        t = self.get_transport('repo')
962
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1089
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
963
1090
        repo_name = repo_fmt.repository_format.network_name()
964
1091
        repo = repo_fmt.initialize_on_transport_ex(t,
965
1092
            repo_format_name=repo_name, shared_repo=True)[0]
966
1093
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
967
1094
            force_new_repo=True, repo_format_name=repo_name)
968
 
        if control is None:
969
 
            # uninitialisable format
970
 
            return
971
1095
        self.assertNotEqual(repo.bzrdir.root_transport.base,
972
1096
            made_repo.bzrdir.root_transport.base)
973
1097
 
974
1098
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
975
1099
        t = self.get_transport('repo')
976
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1100
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
977
1101
        repo_name = repo_fmt.repository_format.network_name()
978
1102
        repo = repo_fmt.initialize_on_transport_ex(t,
979
1103
            repo_format_name=repo_name, shared_repo=True)[0]
980
1104
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
981
1105
            force_new_repo=False, repo_format_name=repo_name)
982
 
        if control is None:
983
 
            # uninitialisable format
984
 
            return
985
1106
        if not control._format.fixed_components:
986
1107
            self.assertEqual(repo.bzrdir.root_transport.base,
987
1108
                made_repo.bzrdir.root_transport.base)
988
1109
 
989
 
    def test_format_initialize_on_transport_ex_stacked_on(self):
990
 
        # trunk is a stackable format.  Note that its in the same server area
991
 
        # which is what launchpad does, but not sufficient to exercise the
992
 
        # general case.
993
 
        trunk = self.make_branch('trunk', format='1.9')
994
 
        t = self.get_transport('stacked')
995
 
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
996
 
        repo_name = old_fmt.repository_format.network_name()
997
 
        # Should end up with a 1.9 format (stackable)
998
 
        repo, control = self.assertInitializeEx(t, need_meta=True,
999
 
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
1000
 
        if control is None:
1001
 
            # uninitialisable format
1002
 
            return
1003
 
        self.assertLength(1, repo._fallback_repositories)
1004
 
 
1005
 
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1006
 
        # When initialize_on_transport_ex uses a stacked-on branch because of
1007
 
        # a stacking policy on the target, the location of the fallback
1008
 
        # repository is the same as the external location of the stacked-on
1009
 
        # branch.
1010
 
        balloon = self.make_bzrdir('balloon')
1011
 
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1012
 
            stack_on = self.make_branch('stack-on', format='1.9')
1013
 
        else:
1014
 
            stack_on = self.make_branch('stack-on')
1015
 
        config = self.make_bzrdir('.').get_config()
1016
 
        try:
1017
 
            config.set_default_stack_on('stack-on')
1018
 
        except errors.BzrError:
1019
 
            raise TestNotApplicable('Only relevant for stackable formats.')
1020
 
        # Initialize a bzrdir subject to the policy.
1021
 
        t = self.get_transport('stacked')
1022
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1023
 
        repo_name = repo_fmt.repository_format.network_name()
1024
 
        repo, control = self.assertInitializeEx(
1025
 
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1026
 
        # self.addCleanup(repo.unlock)
1027
 
        if control is None:
1028
 
            # uninitialisable format
1029
 
            return
1030
 
        # There's one fallback repo, with a public location.
1031
 
        self.assertLength(1, repo._fallback_repositories)
1032
 
        fallback_repo = repo._fallback_repositories[0]
1033
 
        self.assertEqual(
1034
 
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
1035
 
        # The bzrdir creates a branch in stacking-capable format.
1036
 
        new_branch = control.create_branch()
1037
 
        self.assertTrue(new_branch._format.supports_stacking())
1038
 
 
1039
1110
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1040
1111
        t = self.get_transport('dir')
1041
1112
        repo, control = self.assertInitializeEx(t)
1044
1115
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1045
1116
        t = self.get_transport('dir')
1046
1117
        # 1.6 is likely to never be default
1047
 
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
 
1118
        fmt = controldir.format_registry.make_bzrdir('1.6')
1048
1119
        repo_name = fmt.repository_format.network_name()
1049
1120
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1050
 
        if control is None:
1051
 
            # uninitialisable format
1052
 
            return
1053
1121
        if self.bzrdir_format.fixed_components:
1054
1122
            # must stay with the all-in-one-format.
1055
1123
            repo_name = self.bzrdir_format.network_name()
1056
1124
        self.assertEqual(repo_name, repo._format.network_name())
1057
1125
 
1058
 
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
1126
    def assertInitializeEx(self, t, **kwargs):
1059
1127
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1060
1128
 
1061
1129
        This involves checking that the disk objects were created, open with
1066
1134
            initialize_on_transport_ex.
1067
1135
        :return: the resulting repo, control dir tuple.
1068
1136
        """
1069
 
        if not self.bzrdir_format.is_supported():
1070
 
            # Not initializable - not a failure either.
1071
 
            return None, None
 
1137
        if not self.bzrdir_format.is_initializable():
 
1138
            raise TestNotApplicable("control dir format is not "
 
1139
                "initializable")
1072
1140
        repo, control, require_stacking, repo_policy = \
1073
1141
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1074
1142
        if repo is not None:
1076
1144
            self.assertTrue(repo.is_write_locked())
1077
1145
            self.addCleanup(repo.unlock)
1078
1146
        self.assertIsInstance(control, controldir.ControlDir)
1079
 
        opened = bzrdir.BzrDir.open(t.base)
 
1147
        opened = controldir.ControlDir.open(t.base)
1080
1148
        expected_format = self.bzrdir_format
1081
 
        if need_meta and expected_format.fixed_components:
1082
 
            # Pre-metadir formats change when we are making something that
1083
 
            # needs a metaformat, because clone is used for push.
1084
 
            expected_format = bzrdir.BzrDirMetaFormat1()
1085
1149
        if not isinstance(expected_format, RemoteBzrDirFormat):
1086
1150
            self.assertEqual(control._format.network_name(),
1087
1151
                expected_format.network_name())
1117
1181
        # test the formats specific behaviour for no-content or similar dirs.
1118
1182
        self.assertRaises(errors.NotBranchError,
1119
1183
                          self.bzrdir_format.open,
1120
 
                          transport.get_transport(self.get_readonly_url()))
 
1184
                          transport.get_transport_from_url(self.get_readonly_url()))
1121
1185
 
1122
1186
    def test_create_branch(self):
1123
1187
        # a bzrdir can construct a branch and repository for itself.
1124
 
        if not self.bzrdir_format.is_supported():
 
1188
        if not self.bzrdir_format.is_initializable():
1125
1189
            # unsupported formats are not loopback testable
1126
1190
            # because the default open will not open them and
1127
1191
            # they may not be initializable.
1128
 
            return
 
1192
            raise TestNotApplicable("format is not initializable")
1129
1193
        t = self.get_transport()
1130
1194
        made_control = self.bzrdir_format.initialize(t.base)
1131
1195
        made_repo = made_control.create_repository()
1133
1197
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1134
1198
        self.assertEqual(made_control, made_branch.bzrdir)
1135
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())
 
1218
        self.assertEqual(made_control, made_branch.bzrdir)
 
1219
 
1136
1220
    def test_open_branch(self):
1137
 
        if not self.bzrdir_format.is_supported():
 
1221
        if not self.bzrdir_format.is_initializable():
1138
1222
            # unsupported formats are not loopback testable
1139
1223
            # because the default open will not open them and
1140
1224
            # they may not be initializable.
1141
 
            return
 
1225
            raise TestNotApplicable("format is not initializable")
1142
1226
        t = self.get_transport()
1143
1227
        made_control = self.bzrdir_format.initialize(t.base)
1144
1228
        made_repo = made_control.create_repository()
1149
1233
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1150
1234
 
1151
1235
    def test_list_branches(self):
1152
 
        if not self.bzrdir_format.is_supported():
1153
 
            # unsupported formats are not loopback testable
1154
 
            # because the default open will not open them and
1155
 
            # they may not be initializable.
1156
 
            return
 
1236
        if not self.bzrdir_format.is_initializable():
 
1237
            raise TestNotApplicable("format is not initializable")
1157
1238
        t = self.get_transport()
1158
1239
        made_control = self.bzrdir_format.initialize(t.base)
1159
1240
        made_repo = made_control.create_repository()
1160
1241
        made_branch = made_control.create_branch()
1161
1242
        branches = made_control.list_branches()
1162
 
        self.assertEquals(1, len(branches))
1163
 
        self.assertEquals(made_branch.base, branches[0].base)
 
1243
        self.assertEqual(1, len(branches))
 
1244
        self.assertEqual(made_branch.base, branches[0].base)
1164
1245
        try:
1165
1246
            made_control.destroy_branch()
1166
1247
        except errors.UnsupportedOperation:
1167
1248
            pass # Not all bzrdirs support destroying directories
1168
1249
        else:
1169
 
            self.assertEquals([], made_control.list_branches())
 
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())
1170
1256
 
1171
1257
    def test_create_repository(self):
1172
1258
        # a bzrdir can construct a repository for itself.
1173
 
        if not self.bzrdir_format.is_supported():
 
1259
        if not self.bzrdir_format.is_initializable():
1174
1260
            # unsupported formats are not loopback testable
1175
1261
            # because the default open will not open them and
1176
1262
            # they may not be initializable.
1177
 
            return
 
1263
            raise TestNotApplicable("format is not initializable")
1178
1264
        t = self.get_transport()
1179
1265
        made_control = self.bzrdir_format.initialize(t.base)
1180
1266
        made_repo = made_control.create_repository()
1185
1271
    def test_create_repository_shared(self):
1186
1272
        # a bzrdir can create a shared repository or
1187
1273
        # fail appropriately
1188
 
        if not self.bzrdir_format.is_supported():
 
1274
        if not self.bzrdir_format.is_initializable():
1189
1275
            # unsupported formats are not loopback testable
1190
1276
            # because the default open will not open them and
1191
1277
            # they may not be initializable.
1192
 
            return
 
1278
            raise TestNotApplicable("format is not initializable")
1193
1279
        t = self.get_transport()
1194
1280
        made_control = self.bzrdir_format.initialize(t.base)
1195
1281
        try:
1197
1283
        except errors.IncompatibleFormat:
1198
1284
            # Old bzrdir formats don't support shared repositories
1199
1285
            # and should raise IncompatibleFormat
1200
 
            return
 
1286
            raise TestNotApplicable("format does not support shared "
 
1287
                "repositories")
1201
1288
        self.assertTrue(made_repo.is_shared())
1202
1289
 
1203
1290
    def test_create_repository_nonshared(self):
1204
1291
        # a bzrdir can create a non-shared repository
1205
 
        if not self.bzrdir_format.is_supported():
 
1292
        if not self.bzrdir_format.is_initializable():
1206
1293
            # unsupported formats are not loopback testable
1207
1294
            # because the default open will not open them and
1208
1295
            # they may not be initializable.
1209
 
            return
 
1296
            raise TestNotApplicable("format is not initializable")
1210
1297
        t = self.get_transport()
1211
1298
        made_control = self.bzrdir_format.initialize(t.base)
1212
 
        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")
1213
1306
        self.assertFalse(made_repo.is_shared())
1214
1307
 
1215
1308
    def test_open_repository(self):
1216
 
        if not self.bzrdir_format.is_supported():
 
1309
        if not self.bzrdir_format.is_initializable():
1217
1310
            # unsupported formats are not loopback testable
1218
1311
            # because the default open will not open them and
1219
1312
            # they may not be initializable.
1220
 
            return
 
1313
            raise TestNotApplicable("format is not initializable")
1221
1314
        t = self.get_transport()
1222
1315
        made_control = self.bzrdir_format.initialize(t.base)
1223
1316
        made_repo = made_control.create_repository()
1228
1321
 
1229
1322
    def test_create_workingtree(self):
1230
1323
        # a bzrdir can construct a working tree for itself.
1231
 
        if not self.bzrdir_format.is_supported():
 
1324
        if not self.bzrdir_format.is_initializable():
1232
1325
            # unsupported formats are not loopback testable
1233
1326
            # because the default open will not open them and
1234
1327
            # they may not be initializable.
1235
 
            return
 
1328
            raise TestNotApplicable("format is not initializable")
1236
1329
        t = self.get_transport()
1237
1330
        made_control = self.bzrdir_format.initialize(t.base)
1238
1331
        made_repo = made_control.create_repository()
1243
1336
 
1244
1337
    def test_create_workingtree_revision(self):
1245
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")
1246
1341
        t = self.get_transport()
1247
1342
        source = self.make_branch_and_tree('source')
1248
1343
        source.commit('a', rev_id='a', allow_pointless=True)
1259
1354
        self.assertEqual(['a'], made_tree.get_parent_ids())
1260
1355
 
1261
1356
    def test_open_workingtree(self):
1262
 
        if not self.bzrdir_format.is_supported():
1263
 
            # unsupported formats are not loopback testable
1264
 
            # because the default open will not open them and
1265
 
            # they may not be initializable.
1266
 
            return
 
1357
        if not self.bzrdir_format.is_initializable():
 
1358
            raise TestNotApplicable("format is not initializable")
1267
1359
        # this has to be tested with local access as we still support creating
1268
1360
        # format 6 bzrdirs
1269
1361
        t = self.get_transport()
1280
1372
        self.assertIsInstance(opened_tree, made_tree.__class__)
1281
1373
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1282
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())
 
1403
 
1283
1404
    def test_root_transport(self):
1284
1405
        dir = self.make_bzrdir('.')
1285
1406
        self.assertEqual(dir.root_transport.base,
1292
1413
            repo = self.make_repository('.', shared=True)
1293
1414
        except errors.IncompatibleFormat:
1294
1415
            # need a shared repository to test this.
1295
 
            return
 
1416
            raise TestNotApplicable("requires shared repository support")
 
1417
        if not repo._format.supports_nesting_repositories:
 
1418
            raise TestNotApplicable("requires nesting repositories")
1296
1419
        url = self.get_url('intermediate')
1297
1420
        t = self.get_transport()
1298
1421
        t.mkdir('intermediate')
1318
1441
            repo = self.make_repository('.', shared=True)
1319
1442
        except errors.IncompatibleFormat:
1320
1443
            # need a shared repository to test this.
1321
 
            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")
1322
1449
        url = self.get_url('childbzrdir')
1323
1450
        self.get_transport().mkdir('childbzrdir')
1324
1451
        made_control = self.bzrdir_format.initialize(url)
1334
1461
                         found_repo.bzrdir.root_transport.base)
1335
1462
 
1336
1463
    def test_find_repository_standalone_with_containing_shared_repository(self):
1337
 
        # 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
1338
1466
        try:
1339
1467
            containing_repo = self.make_repository('.', shared=True)
1340
1468
        except errors.IncompatibleFormat:
1341
1469
            # need a shared repository to test this.
1342
 
            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")
1343
1475
        child_repo = self.make_repository('childrepo')
1344
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1476
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1345
1477
        found_repo = opened_control.find_repository()
1346
1478
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1347
1479
                         found_repo.bzrdir.root_transport.base)
1352
1484
            containing_repo = self.make_repository('.', shared=True)
1353
1485
        except errors.IncompatibleFormat:
1354
1486
            # need a shared repository to test this.
1355
 
            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")
1356
1492
        url = self.get_url('childrepo')
1357
1493
        self.get_transport().mkdir('childrepo')
1358
1494
        child_control = self.bzrdir_format.initialize(url)
1359
1495
        child_repo = child_control.create_repository(shared=True)
1360
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1496
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1361
1497
        found_repo = opened_control.find_repository()
1362
1498
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1363
1499
                         found_repo.bzrdir.root_transport.base)
1371
1507
            repo = self.make_repository('.', shared=True)
1372
1508
        except errors.IncompatibleFormat:
1373
1509
            # need a shared repository to test this.
1374
 
            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")
1375
1515
        url = self.get_url('intermediate')
1376
1516
        t = self.get_transport()
1377
1517
        t.mkdir('intermediate')
1423
1563
             ((dir_relpath2, _), entries2)) in izip(
1424
1564
                osutils.walkdirs(old_path),
1425
1565
                osutils.walkdirs(new_path)):
1426
 
            self.assertEquals(dir_relpath1, dir_relpath2)
 
1566
            self.assertEqual(dir_relpath1, dir_relpath2)
1427
1567
            for f1, f2 in zip(entries1, entries2):
1428
 
                self.assertEquals(f1[0], f2[0])
1429
 
                self.assertEquals(f1[2], f2[2])
 
1568
                self.assertEqual(f1[0], f2[0])
 
1569
                self.assertEqual(f1[2], f2[2])
1430
1570
                if f1[2] == "file":
1431
1571
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1432
1572
 
1475
1615
            # and thus this interaction cannot be tested at the interface
1476
1616
            # level.
1477
1617
            repo.unlock()
1478
 
            return
 
1618
            raise TestNotApplicable("format does not physically lock")
1479
1619
        # only one yes needed here: it should only be unlocking
1480
1620
        # the repo
1481
1621
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1484
1624
        except NotImplementedError:
1485
1625
            # this bzrdir does not implement break_lock - so we cant test it.
1486
1626
            repo.unlock()
1487
 
            return
 
1627
            raise TestNotApplicable("format does not support breaking locks")
1488
1628
        lock_repo.lock_write()
1489
1629
        lock_repo.unlock()
1490
1630
        self.assertRaises(errors.LockBroken, repo.unlock)
1498
1638
        master = self.make_branch('branch')
1499
1639
        thisdir = self.make_bzrdir('this')
1500
1640
        try:
1501
 
            bzrlib.branch.BranchReferenceFormat().initialize(
1502
 
                thisdir, target_branch=master)
 
1641
            thisdir.set_branch_reference(master)
1503
1642
        except errors.IncompatibleFormat:
1504
 
            return
 
1643
            raise TestNotApplicable("format does not support "
 
1644
                "branch references")
1505
1645
        unused_repo = thisdir.create_repository()
1506
1646
        master.lock_write()
1507
1647
        unused_repo.lock_write()
1554
1694
            # raised a LockActive because we do still have a live locked
1555
1695
            # object.
1556
1696
            tree.unlock()
1557
 
            return
 
1697
            raise TestNotApplicable("format does not support breaking locks")
1558
1698
        self.assertEqual([True],
1559
1699
                bzrlib.ui.ui_factory.responses)
1560
1700
        lock_tree = tree.bzrdir.open_workingtree()
1573
1713
        except errors.BzrError, e:
1574
1714
            if 'Cannot set config' in str(e):
1575
1715
                self.assertFalse(
1576
 
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
 
1716
                    isinstance(my_dir, (_mod_bzrdir.BzrDirMeta1, RemoteBzrDir)),
1577
1717
                    "%r should support configs" % my_dir)
1578
1718
                raise TestNotApplicable(
1579
1719
                    'This BzrDir format does not support configs.')
1580
1720
            else:
1581
1721
                raise
1582
1722
        self.assertEqual('http://example.com', config.get_default_stack_on())
1583
 
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
 
1723
        my_dir2 = controldir.ControlDir.open(self.get_url('.'))
1584
1724
        config2 = my_dir2.get_config()
1585
1725
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1586
1726
 
1590
1730
    def test_find_repository_no_repository(self):
1591
1731
        # loopback test to check the current format fails to find a
1592
1732
        # share repository correctly.
1593
 
        if not self.bzrdir_format.is_supported():
 
1733
        if not self.bzrdir_format.is_initializable():
1594
1734
            # unsupported formats are not loopback testable
1595
1735
            # because the default open will not open them and
1596
1736
            # they may not be initializable.
1597
 
            return
 
1737
            raise TestNotApplicable("format is not initializable")
1598
1738
        # supported formats must be able to init and open
1599
1739
        # - do the vfs initialisation over the basic vfs transport
1600
1740
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1601
1741
        url = self.get_vfs_only_url('subdir')
1602
 
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1742
        transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
1603
1743
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1604
1744
        try:
1605
1745
            repo = made_control.open_repository()
1608
1748
            return
1609
1749
        except errors.NoRepositoryPresent:
1610
1750
            pass
1611
 
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1751
        made_control = controldir.ControlDir.open(self.get_readonly_url('subdir'))
1612
1752
        self.assertRaises(errors.NoRepositoryPresent,
1613
1753
                          made_control.find_repository)
1614
1754