~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
104
111
    def test_create_null_workingtree(self):
105
112
        dir = self.make_bzrdir('dir1')
106
113
        dir.create_repository()
149
156
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
150
157
            raise TestNotApplicable('Format does not support destroying'
151
158
                                    ' repository')
 
159
        self.assertRaises(errors.NoRepositoryPresent,
 
160
            bzrdir.destroy_repository)
152
161
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
153
162
        bzrdir.create_repository()
154
163
        bzrdir.open_repository()
162
171
        if vfs_dir.has_workingtree():
163
172
            # This ControlDir format doesn't support ControlDirs without
164
173
            # working trees, so this test is irrelevant.
165
 
            return
 
174
            raise TestNotApplicable("format does not support "
 
175
                "control directories without working tree")
166
176
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
167
177
 
168
178
    def test_clone_bzrdir_repository_under_shared(self):
172
182
        tree.commit('revision 1', rev_id='1')
173
183
        dir = self.make_bzrdir('source')
174
184
        repo = dir.create_repository()
 
185
        if not repo._format.supports_nesting_repositories:
 
186
            raise TestNotApplicable("repository format does not support "
 
187
                "nesting")
175
188
        repo.fetch(tree.branch.repository)
176
189
        self.assertTrue(repo.has_revision('1'))
177
190
        try:
178
191
            self.make_repository('target', shared=True)
179
192
        except errors.IncompatibleFormat:
180
 
            return
 
193
            raise TestNotApplicable("repository format does not support "
 
194
                "shared repositories")
181
195
        target = dir.clone(self.get_url('target/child'))
182
196
        self.assertNotEqual(dir.transport.base, target.transport.base)
183
197
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
187
201
        try:
188
202
            shared_repo = self.make_repository('shared', shared=True)
189
203
        except errors.IncompatibleFormat:
190
 
            return
 
204
            raise TestNotApplicable("repository format does not support "
 
205
                "shared repositories")
 
206
        if not shared_repo._format.supports_nesting_repositories:
 
207
            raise TestNotApplicable("format does not support nesting "
 
208
                "repositories")
191
209
        # Make a branch, 'commit_tree', and working tree outside of the shared
192
210
        # repository, and commit some revisions to it.
193
211
        tree = self.make_branch_and_tree('commit_tree')
218
236
        try:
219
237
            shared_repo = self.make_repository('shared', shared=True)
220
238
        except errors.IncompatibleFormat:
221
 
            return
 
239
            raise TestNotApplicable("repository format does not support "
 
240
                "shared repositories")
 
241
        if not shared_repo._format.supports_nesting_repositories:
 
242
            raise TestNotApplicable("format does not support nesting "
 
243
                "repositories")
222
244
        tree = self.make_branch_and_tree('commit_tree')
223
245
        self.build_tree(['commit_tree/foo'])
224
246
        tree.add('foo')
292
314
        tree.branch.repository.copy_content_into(source.repository)
293
315
        tree.branch.copy_content_into(source)
294
316
        try:
295
 
            self.make_repository('target', shared=True)
 
317
            shared_repo = self.make_repository('target', shared=True)
296
318
        except errors.IncompatibleFormat:
297
 
            return
 
319
            raise TestNotApplicable("repository format does not support "
 
320
                "shared repositories")
 
321
        if not shared_repo._format.supports_nesting_repositories:
 
322
            raise TestNotApplicable("format does not support nesting "
 
323
                "repositories")
298
324
        dir = source.bzrdir
299
325
        target = dir.clone(self.get_url('target/child'))
300
326
        self.assertNotEqual(dir.transport.base, target.transport.base)
301
327
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
302
 
        self.assertEqual(source.revision_history(),
303
 
                         target.open_branch().revision_history())
 
328
        self.assertEqual(source.last_revision(),
 
329
                         target.open_branch().last_revision())
304
330
 
305
331
    def test_clone_bzrdir_branch_revision(self):
306
332
        # test for revision limiting, [smoke test, not corner case checks].
369
395
            repo.set_make_working_trees(False)
370
396
            self.assertFalse(repo.make_working_trees())
371
397
 
372
 
        dir = tree.bzrdir
373
 
        a_dir = dir.clone(self.get_url('repo/a'))
374
 
        a_dir.open_branch()
 
398
        a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
 
399
        a_branch = a_dir.open_branch()
 
400
        # If the new control dir actually uses the repository, it should
 
401
        # not have a working tree.
 
402
        if not a_branch.repository.has_same_location(repo):
 
403
            raise TestNotApplicable('new control dir does not use repository')
375
404
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
376
405
 
377
406
    def test_clone_respects_stacked(self):
378
407
        branch = self.make_branch('parent')
379
408
        child_transport = self.get_transport('child')
380
 
        child = branch.bzrdir.clone_on_transport(child_transport,
381
 
                                                 stacked_on=branch.base)
 
409
        try:
 
410
            child = branch.bzrdir.clone_on_transport(child_transport,
 
411
                                                     stacked_on=branch.base)
 
412
        except (errors.UnstackableBranchFormat,
 
413
                errors.UnstackableRepositoryFormat):
 
414
            raise TestNotApplicable("branch or repository format does "
 
415
                "not support stacking")
382
416
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
383
417
 
384
418
    def test_get_branch_reference_on_reference(self):
390
424
                target_branch=referenced_branch)
391
425
        except errors.IncompatibleFormat:
392
426
            # this is ok too, not all formats have to support references.
393
 
            return
 
427
            raise TestNotApplicable("control directory does not "
 
428
                "support branch references")
394
429
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
395
430
            dir.get_branch_reference())
396
431
 
404
439
        dir = self.make_bzrdir('source')
405
440
        if dir.has_branch():
406
441
            # this format does not support branchless bzrdirs.
407
 
            return
 
442
            raise TestNotApplicable("format does not support "
 
443
                "branchless control directories")
408
444
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
409
445
 
410
446
    def test_sprout_bzrdir_empty(self):
411
447
        dir = self.make_bzrdir('source')
412
448
        target = dir.sprout(self.get_url('target'))
413
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
449
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
414
450
        # creates a new repository branch and tree
415
451
        target.open_repository()
416
452
        target.open_branch()
422
458
        try:
423
459
            self.make_repository('target', shared=True)
424
460
        except errors.IncompatibleFormat:
425
 
            return
 
461
            raise TestNotApplicable("format does not support shared "
 
462
                "repositories")
426
463
        target = dir.sprout(self.get_url('target/child'))
427
464
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
428
465
        target.open_branch()
430
467
            target.open_workingtree()
431
468
        except errors.NoWorkingTree:
432
469
            # Some bzrdirs can never have working trees.
433
 
            self.assertFalse(target._format.supports_workingtrees)
 
470
            repo = target.find_repository()
 
471
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
434
472
 
435
473
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
436
474
        # the force_new_repo parameter should force use of a new repo in an empty
439
477
        try:
440
478
            self.make_repository('target', shared=True)
441
479
        except errors.IncompatibleFormat:
442
 
            return
 
480
            raise TestNotApplicable("format does not support shared "
 
481
                "repositories")
443
482
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
444
483
        target.open_repository()
445
484
        target.open_branch()
460
499
        try:
461
500
            shared_repo = self.make_repository('target', shared=True)
462
501
        except errors.IncompatibleFormat:
463
 
            return
 
502
            raise TestNotApplicable("format does not support "
 
503
                "shared repositories")
464
504
        target = dir.sprout(self.get_url('target/child'))
465
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
505
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
466
506
        self.assertTrue(shared_repo.has_revision('1'))
467
507
 
468
508
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
469
509
        try:
470
510
            shared_repo = self.make_repository('shared', shared=True)
471
511
        except errors.IncompatibleFormat:
472
 
            return
 
512
            raise TestNotApplicable("format does not support shared "
 
513
                "repositories")
 
514
        if not shared_repo._format.supports_nesting_repositories:
 
515
            raise TestNotApplicable("format does not support nesting "
 
516
                "repositories")
473
517
        tree = self.make_branch_and_tree('commit_tree')
474
518
        self.build_tree(['commit_tree/foo'])
475
519
        tree.add('foo')
490
534
        try:
491
535
            shared_repo = self.make_repository('shared', shared=True)
492
536
        except errors.IncompatibleFormat:
493
 
            return
 
537
            raise TestNotApplicable("format does not support shared "
 
538
                "repositories")
 
539
        if not shared_repo._format.supports_nesting_repositories:
 
540
            raise TestNotApplicable("format does not support nesting "
 
541
                "repositories")
494
542
        tree = self.make_branch_and_tree('commit_tree')
495
543
        self.build_tree(['commit_tree/foo'])
496
544
        tree.add('foo')
533
581
        try:
534
582
            shared_repo = self.make_repository('target', shared=True)
535
583
        except errors.IncompatibleFormat:
536
 
            return
 
584
            raise TestNotApplicable("format does not support shared "
 
585
                "repositories")
537
586
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
538
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
587
        self.assertNotEqual(
 
588
            dir.control_transport.base,
 
589
            target.control_transport.base)
539
590
        self.assertFalse(shared_repo.has_revision('1'))
540
591
 
541
592
    def test_sprout_bzrdir_repository_revision(self):
571
622
        try:
572
623
            shared_repo = self.make_repository('target', shared=True)
573
624
        except errors.IncompatibleFormat:
574
 
            return
 
625
            raise TestNotApplicable("format does not support shared "
 
626
                "repositories")
575
627
        target = dir.sprout(self.get_url('target/child'))
576
628
        self.assertTrue(shared_repo.has_revision('1'))
577
629
 
589
641
        try:
590
642
            shared_repo = self.make_repository('target', shared=True)
591
643
        except errors.IncompatibleFormat:
592
 
            return
 
644
            raise TestNotApplicable("format does not support shared "
 
645
                "repositories")
593
646
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
594
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
647
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
595
648
        self.assertFalse(shared_repo.has_revision('1'))
596
649
 
597
650
    def test_sprout_bzrdir_branch_reference(self):
602
655
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
603
656
                target_branch=referenced_branch)
604
657
        except errors.IncompatibleFormat:
605
 
            # this is ok too, not all formats have to support references.
606
 
            return
 
658
            raise TestNotApplicable("format does not support branch "
 
659
                "references")
607
660
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
608
661
        target = dir.sprout(self.get_url('target'))
609
662
        self.assertNotEqual(dir.transport.base, target.transport.base)
622
675
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
623
676
                target_branch=referenced_tree.branch)
624
677
        except errors.IncompatibleFormat:
625
 
            # this is ok too, not all formats have to support references.
626
 
            return
 
678
            raise TestNotApplicable("format does not support branch "
 
679
                "references")
627
680
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
628
681
        try:
629
682
            shared_repo = self.make_repository('target', shared=True)
630
683
        except errors.IncompatibleFormat:
631
 
            return
 
684
            raise TestNotApplicable("format does not support "
 
685
                "shared repositories")
632
686
        target = dir.sprout(self.get_url('target/child'))
633
687
        self.assertNotEqual(dir.transport.base, target.transport.base)
634
688
        # we want target to have a branch that is in-place.
649
703
                target_branch=referenced_tree.branch)
650
704
        except errors.IncompatibleFormat:
651
705
            # this is ok too, not all formats have to support references.
652
 
            return
 
706
            raise TestNotApplicable("format does not support "
 
707
                "branch references")
653
708
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
654
709
        try:
655
710
            shared_repo = self.make_repository('target', shared=True)
656
711
        except errors.IncompatibleFormat:
657
 
            return
 
712
            raise TestNotApplicable("format does not support shared "
 
713
                "repositories")
658
714
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
659
715
        self.assertNotEqual(dir.transport.base, target.transport.base)
660
716
        # we want target to have a branch that is in-place.
690
746
            source.tags.set_tag('tag-a', 'rev-2')
691
747
        except errors.TagsNotSupported:
692
748
            raise TestNotApplicable('Branch format does not support tags.')
693
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
749
        source.get_config_stack().set('branch.fetch_tags', True)
694
750
        # Now source has a tag not in its ancestry.  Sprout its controldir.
695
751
        dir = source.bzrdir
696
752
        target = dir.sprout(self.get_url('target'))
707
763
        source = builder.get_branch()
708
764
        try:
709
765
            source.tags.set_tag('tag-a', 'missing-rev')
710
 
        except errors.TagsNotSupported:
711
 
            raise TestNotApplicable('Branch format does not support tags.')
 
766
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
767
            raise TestNotApplicable('Branch format does not support tags '
 
768
                'or tags referencing ghost revisions.')
712
769
        # Now source has a tag pointing to an absent revision.  Sprout its
713
770
        # controldir.
714
771
        dir = source.bzrdir
725
782
        source = builder.get_branch()
726
783
        try:
727
784
            source.tags.set_tag('tag-a', 'missing-rev')
728
 
        except errors.TagsNotSupported:
729
 
            raise TestNotApplicable('Branch format does not support tags.')
 
785
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
786
            raise TestNotApplicable('Branch format does not support tags '
 
787
                'or tags referencing missing revisions.')
730
788
        # Now source has a tag pointing to an absent revision.  Sprout its
731
789
        # controldir.
732
790
        dir = source.bzrdir
759
817
        try:
760
818
            # Create a tag for B2, and for an absent rev
761
819
            source.tags.set_tag('tag-non-ancestry', 'rev-b2')
 
820
        except errors.TagsNotSupported:
 
821
            raise TestNotApplicable('Branch format does not support tags ')
 
822
        try:
762
823
            source.tags.set_tag('tag-absent', 'absent-rev')
763
 
        except errors.TagsNotSupported:
764
 
            raise TestNotApplicable('Branch format does not support tags.')
765
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
824
        except errors.GhostTagsNotSupported:
 
825
            has_ghost_tag = False
 
826
        else:
 
827
            has_ghost_tag = True
 
828
        source.get_config_stack().set('branch.fetch_tags', True)
766
829
        # And ask sprout for C2
767
830
        dir = source.bzrdir
768
831
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
769
832
        # The tags are present
770
833
        new_branch = target.open_branch()
771
 
        self.assertEqual(
772
 
            {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
773
 
            new_branch.tags.get_tag_dict())
 
834
        if has_ghost_tag:
 
835
            self.assertEqual(
 
836
                {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
 
837
                new_branch.tags.get_tag_dict())
 
838
        else:
 
839
            self.assertEqual(
 
840
                {'tag-non-ancestry': 'rev-b2'},
 
841
                new_branch.tags.get_tag_dict())
774
842
        # And the revs for A2, B2 and C2's ancestries are present, but no
775
843
        # others.
776
844
        self.assertEqual(
787
855
                target_branch=referenced_branch)
788
856
        except errors.IncompatibleFormat:
789
857
            # this is ok too, not all formats have to support references.
790
 
            return
 
858
            raise TestNotApplicable("format does not support "
 
859
                "branch references")
791
860
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
792
861
        tree = self.createWorkingTreeOrSkip(dir)
793
862
        self.build_tree(['source/subdir/'])
813
882
                target_branch=referenced_branch)
814
883
        except errors.IncompatibleFormat:
815
884
            # this is ok too, not all formats have to support references.
816
 
            return
 
885
            raise TestNotApplicable("format does not support "
 
886
                "branch references")
817
887
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
818
888
        tree = self.createWorkingTreeOrSkip(dir)
819
889
        self.build_tree(['source/foo'])
899
969
 
900
970
    def test_format_initialize_find_open(self):
901
971
        # loopback test to check the current format initializes to itself.
902
 
        if not self.bzrdir_format.is_supported():
 
972
        if not self.bzrdir_format.is_initializable():
903
973
            # unsupported formats are not loopback testable
904
974
            # because the default open will not open them and
905
975
            # they may not be initializable.
906
 
            return
 
976
            raise TestNotApplicable("format is not initializable")
907
977
        # for remote formats, there must be no prior assumption about the
908
978
        # network name to use - it's possible that this may somehow have got
909
979
        # in through an unisolated test though - see
938
1008
        self.assertInitializeEx(t, use_existing_dir=True)
939
1009
 
940
1010
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
941
 
        if not self.bzrdir_format.is_supported():
942
 
            # Not initializable - not a failure either.
943
 
            return
 
1011
        if not self.bzrdir_format.is_initializable():
 
1012
            raise TestNotApplicable("format is not initializable")
944
1013
        t = self.get_transport('dir')
945
1014
        t.ensure_base()
946
1015
        self.assertRaises(errors.FileExists,
952
1021
        self.assertInitializeEx(t, create_prefix=True)
953
1022
 
954
1023
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
955
 
        if not self.bzrdir_format.is_supported():
956
 
            # Not initializable - not a failure either.
957
 
            return
 
1024
        if not self.bzrdir_format.is_initializable():
 
1025
            raise TestNotApplicable("format is not initializable")
958
1026
        t = self.get_transport('missing/dir')
959
1027
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
960
1028
            create_prefix=False)
967
1035
            repo_format_name=repo_name, shared_repo=True)[0]
968
1036
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
969
1037
            force_new_repo=True, repo_format_name=repo_name)
970
 
        if control is None:
971
 
            # uninitialisable format
972
 
            return
973
1038
        self.assertNotEqual(repo.bzrdir.root_transport.base,
974
1039
            made_repo.bzrdir.root_transport.base)
975
1040
 
981
1046
            repo_format_name=repo_name, shared_repo=True)[0]
982
1047
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
983
1048
            force_new_repo=False, repo_format_name=repo_name)
984
 
        if control is None:
985
 
            # uninitialisable format
986
 
            return
987
1049
        if not control._format.fixed_components:
988
1050
            self.assertEqual(repo.bzrdir.root_transport.base,
989
1051
                made_repo.bzrdir.root_transport.base)
990
1052
 
991
 
    def test_format_initialize_on_transport_ex_stacked_on(self):
992
 
        # trunk is a stackable format.  Note that its in the same server area
993
 
        # which is what launchpad does, but not sufficient to exercise the
994
 
        # general case.
995
 
        trunk = self.make_branch('trunk', format='1.9')
996
 
        t = self.get_transport('stacked')
997
 
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
998
 
        repo_name = old_fmt.repository_format.network_name()
999
 
        # Should end up with a 1.9 format (stackable)
1000
 
        repo, control = self.assertInitializeEx(t, need_meta=True,
1001
 
            repo_format_name=repo_name, stacked_on='../trunk',
1002
 
            stack_on_pwd=t.base)
1003
 
        if control is None:
1004
 
            # uninitialisable format
1005
 
            return
1006
 
        self.assertLength(1, repo._fallback_repositories)
1007
 
 
1008
 
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1009
 
        # When initialize_on_transport_ex uses a stacked-on branch because of
1010
 
        # a stacking policy on the target, the location of the fallback
1011
 
        # repository is the same as the external location of the stacked-on
1012
 
        # branch.
1013
 
        balloon = self.make_bzrdir('balloon')
1014
 
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1015
 
            stack_on = self.make_branch('stack-on', format='1.9')
1016
 
        else:
1017
 
            stack_on = self.make_branch('stack-on')
1018
 
        config = self.make_bzrdir('.').get_config()
1019
 
        try:
1020
 
            config.set_default_stack_on('stack-on')
1021
 
        except errors.BzrError:
1022
 
            raise TestNotApplicable('Only relevant for stackable formats.')
1023
 
        # Initialize a bzrdir subject to the policy.
1024
 
        t = self.get_transport('stacked')
1025
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1026
 
        repo_name = repo_fmt.repository_format.network_name()
1027
 
        repo, control = self.assertInitializeEx(
1028
 
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1029
 
        # self.addCleanup(repo.unlock)
1030
 
        if control is None:
1031
 
            # uninitialisable format
1032
 
            return
1033
 
        # There's one fallback repo, with a public location.
1034
 
        self.assertLength(1, repo._fallback_repositories)
1035
 
        fallback_repo = repo._fallback_repositories[0]
1036
 
        self.assertEqual(
1037
 
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
1038
 
        # The bzrdir creates a branch in stacking-capable format.
1039
 
        new_branch = control.create_branch()
1040
 
        self.assertTrue(new_branch._format.supports_stacking())
1041
 
 
1042
1053
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1043
1054
        t = self.get_transport('dir')
1044
1055
        repo, control = self.assertInitializeEx(t)
1050
1061
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1051
1062
        repo_name = fmt.repository_format.network_name()
1052
1063
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1053
 
        if control is None:
1054
 
            # uninitialisable format
1055
 
            return
1056
1064
        if self.bzrdir_format.fixed_components:
1057
1065
            # must stay with the all-in-one-format.
1058
1066
            repo_name = self.bzrdir_format.network_name()
1059
1067
        self.assertEqual(repo_name, repo._format.network_name())
1060
1068
 
1061
 
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
1069
    def assertInitializeEx(self, t, **kwargs):
1062
1070
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1063
1071
 
1064
1072
        This involves checking that the disk objects were created, open with
1069
1077
            initialize_on_transport_ex.
1070
1078
        :return: the resulting repo, control dir tuple.
1071
1079
        """
1072
 
        if not self.bzrdir_format.is_supported():
1073
 
            # Not initializable - not a failure either.
1074
 
            return None, None
 
1080
        if not self.bzrdir_format.is_initializable():
 
1081
            raise TestNotApplicable("control dir format is not "
 
1082
                "initializable")
1075
1083
        repo, control, require_stacking, repo_policy = \
1076
1084
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1077
1085
        if repo is not None:
1081
1089
        self.assertIsInstance(control, controldir.ControlDir)
1082
1090
        opened = bzrdir.BzrDir.open(t.base)
1083
1091
        expected_format = self.bzrdir_format
1084
 
        if need_meta and expected_format.fixed_components:
1085
 
            # Pre-metadir formats change when we are making something that
1086
 
            # needs a metaformat, because clone is used for push.
1087
 
            expected_format = bzrdir.BzrDirMetaFormat1()
1088
1092
        if not isinstance(expected_format, RemoteBzrDirFormat):
1089
1093
            self.assertEqual(control._format.network_name(),
1090
1094
                expected_format.network_name())
1124
1128
 
1125
1129
    def test_create_branch(self):
1126
1130
        # a bzrdir can construct a branch and repository for itself.
1127
 
        if not self.bzrdir_format.is_supported():
 
1131
        if not self.bzrdir_format.is_initializable():
1128
1132
            # unsupported formats are not loopback testable
1129
1133
            # because the default open will not open them and
1130
1134
            # they may not be initializable.
1131
 
            return
 
1135
            raise TestNotApplicable("format is not initializable")
1132
1136
        t = self.get_transport()
1133
1137
        made_control = self.bzrdir_format.initialize(t.base)
1134
1138
        made_repo = made_control.create_repository()
1136
1140
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1137
1141
        self.assertEqual(made_control, made_branch.bzrdir)
1138
1142
 
 
1143
    def test_create_branch_append_revisions_only(self):
 
1144
        # a bzrdir can construct a branch and repository for itself.
 
1145
        if not self.bzrdir_format.is_initializable():
 
1146
            # unsupported formats are not loopback testable
 
1147
            # because the default open will not open them and
 
1148
            # they may not be initializable.
 
1149
            raise TestNotApplicable("format is not initializable")
 
1150
        t = self.get_transport()
 
1151
        made_control = self.bzrdir_format.initialize(t.base)
 
1152
        made_repo = made_control.create_repository()
 
1153
        try:
 
1154
            made_branch = made_control.create_branch(
 
1155
                append_revisions_only=True)
 
1156
        except errors.UpgradeRequired:
 
1157
            raise TestNotApplicable("format does not support "
 
1158
                "append_revisions_only setting")
 
1159
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
 
1160
        self.assertEquals(True, made_branch.get_append_revisions_only())
 
1161
        self.assertEqual(made_control, made_branch.bzrdir)
 
1162
 
1139
1163
    def test_open_branch(self):
1140
 
        if not self.bzrdir_format.is_supported():
 
1164
        if not self.bzrdir_format.is_initializable():
1141
1165
            # unsupported formats are not loopback testable
1142
1166
            # because the default open will not open them and
1143
1167
            # they may not be initializable.
1144
 
            return
 
1168
            raise TestNotApplicable("format is not initializable")
1145
1169
        t = self.get_transport()
1146
1170
        made_control = self.bzrdir_format.initialize(t.base)
1147
1171
        made_repo = made_control.create_repository()
1152
1176
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1153
1177
 
1154
1178
    def test_list_branches(self):
1155
 
        if not self.bzrdir_format.is_supported():
1156
 
            # unsupported formats are not loopback testable
1157
 
            # because the default open will not open them and
1158
 
            # they may not be initializable.
1159
 
            return
 
1179
        if not self.bzrdir_format.is_initializable():
 
1180
            raise TestNotApplicable("format is not initializable")
1160
1181
        t = self.get_transport()
1161
1182
        made_control = self.bzrdir_format.initialize(t.base)
1162
1183
        made_repo = made_control.create_repository()
1171
1192
        else:
1172
1193
            self.assertEquals([], made_control.list_branches())
1173
1194
 
 
1195
    def test_get_branches(self):
 
1196
        repo = self.make_repository('branch-1')
 
1197
        target_branch = repo.bzrdir.create_branch()
 
1198
        self.assertEqual([None], repo.bzrdir.get_branches().keys())
 
1199
 
1174
1200
    def test_create_repository(self):
1175
1201
        # a bzrdir can construct a repository for itself.
1176
 
        if not self.bzrdir_format.is_supported():
 
1202
        if not self.bzrdir_format.is_initializable():
1177
1203
            # unsupported formats are not loopback testable
1178
1204
            # because the default open will not open them and
1179
1205
            # they may not be initializable.
1180
 
            return
 
1206
            raise TestNotApplicable("format is not initializable")
1181
1207
        t = self.get_transport()
1182
1208
        made_control = self.bzrdir_format.initialize(t.base)
1183
1209
        made_repo = made_control.create_repository()
1188
1214
    def test_create_repository_shared(self):
1189
1215
        # a bzrdir can create a shared repository or
1190
1216
        # fail appropriately
1191
 
        if not self.bzrdir_format.is_supported():
 
1217
        if not self.bzrdir_format.is_initializable():
1192
1218
            # unsupported formats are not loopback testable
1193
1219
            # because the default open will not open them and
1194
1220
            # they may not be initializable.
1195
 
            return
 
1221
            raise TestNotApplicable("format is not initializable")
1196
1222
        t = self.get_transport()
1197
1223
        made_control = self.bzrdir_format.initialize(t.base)
1198
1224
        try:
1200
1226
        except errors.IncompatibleFormat:
1201
1227
            # Old bzrdir formats don't support shared repositories
1202
1228
            # and should raise IncompatibleFormat
1203
 
            return
 
1229
            raise TestNotApplicable("format does not support shared "
 
1230
                "repositories")
1204
1231
        self.assertTrue(made_repo.is_shared())
1205
1232
 
1206
1233
    def test_create_repository_nonshared(self):
1207
1234
        # a bzrdir can create a non-shared repository
1208
 
        if not self.bzrdir_format.is_supported():
 
1235
        if not self.bzrdir_format.is_initializable():
1209
1236
            # unsupported formats are not loopback testable
1210
1237
            # because the default open will not open them and
1211
1238
            # they may not be initializable.
1212
 
            return
 
1239
            raise TestNotApplicable("format is not initializable")
1213
1240
        t = self.get_transport()
1214
1241
        made_control = self.bzrdir_format.initialize(t.base)
1215
 
        made_repo = made_control.create_repository(shared=False)
 
1242
        try:
 
1243
            made_repo = made_control.create_repository(shared=False)
 
1244
        except errors.IncompatibleFormat:
 
1245
            # Some control dir formats don't support non-shared repositories
 
1246
            # and should raise IncompatibleFormat
 
1247
            raise TestNotApplicable("format does not support shared "
 
1248
                "repositories")
1216
1249
        self.assertFalse(made_repo.is_shared())
1217
1250
 
1218
1251
    def test_open_repository(self):
1219
 
        if not self.bzrdir_format.is_supported():
 
1252
        if not self.bzrdir_format.is_initializable():
1220
1253
            # unsupported formats are not loopback testable
1221
1254
            # because the default open will not open them and
1222
1255
            # they may not be initializable.
1223
 
            return
 
1256
            raise TestNotApplicable("format is not initializable")
1224
1257
        t = self.get_transport()
1225
1258
        made_control = self.bzrdir_format.initialize(t.base)
1226
1259
        made_repo = made_control.create_repository()
1231
1264
 
1232
1265
    def test_create_workingtree(self):
1233
1266
        # a bzrdir can construct a working tree for itself.
1234
 
        if not self.bzrdir_format.is_supported():
 
1267
        if not self.bzrdir_format.is_initializable():
1235
1268
            # unsupported formats are not loopback testable
1236
1269
            # because the default open will not open them and
1237
1270
            # they may not be initializable.
1238
 
            return
 
1271
            raise TestNotApplicable("format is not initializable")
1239
1272
        t = self.get_transport()
1240
1273
        made_control = self.bzrdir_format.initialize(t.base)
1241
1274
        made_repo = made_control.create_repository()
1246
1279
 
1247
1280
    def test_create_workingtree_revision(self):
1248
1281
        # a bzrdir can construct a working tree for itself @ a specific revision.
 
1282
        if not self.bzrdir_format.is_initializable():
 
1283
            raise TestNotApplicable("format is not initializable")
1249
1284
        t = self.get_transport()
1250
1285
        source = self.make_branch_and_tree('source')
1251
1286
        source.commit('a', rev_id='a', allow_pointless=True)
1262
1297
        self.assertEqual(['a'], made_tree.get_parent_ids())
1263
1298
 
1264
1299
    def test_open_workingtree(self):
1265
 
        if not self.bzrdir_format.is_supported():
1266
 
            # unsupported formats are not loopback testable
1267
 
            # because the default open will not open them and
1268
 
            # they may not be initializable.
1269
 
            return
 
1300
        if not self.bzrdir_format.is_initializable():
 
1301
            raise TestNotApplicable("format is not initializable")
1270
1302
        # this has to be tested with local access as we still support creating
1271
1303
        # format 6 bzrdirs
1272
1304
        t = self.get_transport()
1286
1318
    def test_get_selected_branch(self):
1287
1319
        # The segment parameters are accessible from the root transport
1288
1320
        # if a URL with segment parameters is opened.
1289
 
        if not self.bzrdir_format.is_supported():
1290
 
            # unsupported formats are not loopback testable
1291
 
            # because the default open will not open them and
1292
 
            # they may not be initializable.
1293
 
            return
 
1321
        if not self.bzrdir_format.is_initializable():
 
1322
            raise TestNotApplicable("format is not initializable")
1294
1323
        t = self.get_transport()
1295
1324
        try:
1296
1325
            made_control = self.bzrdir_format.initialize(t.base)
1304
1333
 
1305
1334
    def test_get_selected_branch_none_selected(self):
1306
1335
        # _get_selected_branch defaults to None
1307
 
        if not self.bzrdir_format.is_supported():
1308
 
            # unsupported formats are not loopback testable
1309
 
            # because the default open will not open them and
1310
 
            # they may not be initializable.
1311
 
            return
 
1336
        if not self.bzrdir_format.is_initializable():
 
1337
            raise TestNotApplicable("format is not initializable")
1312
1338
        t = self.get_transport()
1313
1339
        try:
1314
1340
            made_control = self.bzrdir_format.initialize(t.base)
1330
1356
            repo = self.make_repository('.', shared=True)
1331
1357
        except errors.IncompatibleFormat:
1332
1358
            # need a shared repository to test this.
1333
 
            return
 
1359
            raise TestNotApplicable("requires shared repository support")
 
1360
        if not repo._format.supports_nesting_repositories:
 
1361
            raise TestNotApplicable("requires nesting repositories")
1334
1362
        url = self.get_url('intermediate')
1335
1363
        t = self.get_transport()
1336
1364
        t.mkdir('intermediate')
1356
1384
            repo = self.make_repository('.', shared=True)
1357
1385
        except errors.IncompatibleFormat:
1358
1386
            # need a shared repository to test this.
1359
 
            return
 
1387
            raise TestNotApplicable("requires format with shared repository "
 
1388
                "support")
 
1389
        if not repo._format.supports_nesting_repositories:
 
1390
            raise TestNotApplicable("requires support for nesting "
 
1391
                "repositories")
1360
1392
        url = self.get_url('childbzrdir')
1361
1393
        self.get_transport().mkdir('childbzrdir')
1362
1394
        made_control = self.bzrdir_format.initialize(url)
1372
1404
                         found_repo.bzrdir.root_transport.base)
1373
1405
 
1374
1406
    def test_find_repository_standalone_with_containing_shared_repository(self):
1375
 
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
 
1407
        # find repo inside a standalone repo inside a shared repo finds the
 
1408
        # standalone repo
1376
1409
        try:
1377
1410
            containing_repo = self.make_repository('.', shared=True)
1378
1411
        except errors.IncompatibleFormat:
1379
1412
            # need a shared repository to test this.
1380
 
            return
 
1413
            raise TestNotApplicable("requires support for shared "
 
1414
                "repositories")
 
1415
        if not containing_repo._format.supports_nesting_repositories:
 
1416
            raise TestNotApplicable("format does not support "
 
1417
                "nesting repositories")
1381
1418
        child_repo = self.make_repository('childrepo')
1382
1419
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1383
1420
        found_repo = opened_control.find_repository()
1390
1427
            containing_repo = self.make_repository('.', shared=True)
1391
1428
        except errors.IncompatibleFormat:
1392
1429
            # need a shared repository to test this.
1393
 
            return
 
1430
            raise TestNotApplicable("requires support for shared "
 
1431
                "repositories")
 
1432
        if not containing_repo._format.supports_nesting_repositories:
 
1433
            raise TestNotApplicable("requires support for nesting "
 
1434
                "repositories")
1394
1435
        url = self.get_url('childrepo')
1395
1436
        self.get_transport().mkdir('childrepo')
1396
1437
        child_control = self.bzrdir_format.initialize(url)
1409
1450
            repo = self.make_repository('.', shared=True)
1410
1451
        except errors.IncompatibleFormat:
1411
1452
            # need a shared repository to test this.
1412
 
            return
 
1453
            raise TestNotApplicable("requires support for shared "
 
1454
                "repositories")
 
1455
        if not repo._format.supports_nesting_repositories:
 
1456
            raise TestNotApplicable("requires support for nesting "
 
1457
                "repositories")
1413
1458
        url = self.get_url('intermediate')
1414
1459
        t = self.get_transport()
1415
1460
        t.mkdir('intermediate')
1513
1558
            # and thus this interaction cannot be tested at the interface
1514
1559
            # level.
1515
1560
            repo.unlock()
1516
 
            return
 
1561
            raise TestNotApplicable("format does not physically lock")
1517
1562
        # only one yes needed here: it should only be unlocking
1518
1563
        # the repo
1519
1564
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1522
1567
        except NotImplementedError:
1523
1568
            # this bzrdir does not implement break_lock - so we cant test it.
1524
1569
            repo.unlock()
1525
 
            return
 
1570
            raise TestNotApplicable("format does not support breaking locks")
1526
1571
        lock_repo.lock_write()
1527
1572
        lock_repo.unlock()
1528
1573
        self.assertRaises(errors.LockBroken, repo.unlock)
1539
1584
            bzrlib.branch.BranchReferenceFormat().initialize(
1540
1585
                thisdir, target_branch=master)
1541
1586
        except errors.IncompatibleFormat:
1542
 
            return
 
1587
            raise TestNotApplicable("format does not support "
 
1588
                "branch references")
1543
1589
        unused_repo = thisdir.create_repository()
1544
1590
        master.lock_write()
1545
1591
        unused_repo.lock_write()
1592
1638
            # raised a LockActive because we do still have a live locked
1593
1639
            # object.
1594
1640
            tree.unlock()
1595
 
            return
 
1641
            raise TestNotApplicable("format does not support breaking locks")
1596
1642
        self.assertEqual([True],
1597
1643
                bzrlib.ui.ui_factory.responses)
1598
1644
        lock_tree = tree.bzrdir.open_workingtree()
1628
1674
    def test_find_repository_no_repository(self):
1629
1675
        # loopback test to check the current format fails to find a
1630
1676
        # share repository correctly.
1631
 
        if not self.bzrdir_format.is_supported():
 
1677
        if not self.bzrdir_format.is_initializable():
1632
1678
            # unsupported formats are not loopback testable
1633
1679
            # because the default open will not open them and
1634
1680
            # they may not be initializable.
1635
 
            return
 
1681
            raise TestNotApplicable("format is not initializable")
1636
1682
        # supported formats must be able to init and open
1637
1683
        # - do the vfs initialisation over the basic vfs transport
1638
1684
        # XXX: TODO this should become a 'bzrdirlocation' api call.