~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Tests for control directory implementations - tests a controldir format."""
18
18
 
19
19
from itertools import izip
20
 
import os
21
20
 
22
21
import bzrlib.branch
23
22
from bzrlib import (
34
33
    )
35
34
import bzrlib.revision
36
35
from bzrlib.tests import (
37
 
                          ChrootedTestCase,
38
 
                          TestNotApplicable,
39
 
                          TestSkipped,
40
 
                          )
 
36
    fixtures,
 
37
    ChrootedTestCase,
 
38
    TestNotApplicable,
 
39
    TestSkipped,
 
40
    )
41
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
42
42
from bzrlib.transport.local import LocalTransport
43
43
from bzrlib.ui import (
44
44
    CannedInputUIFactory,
45
45
    )
46
 
from bzrlib.remote import RemoteBzrDir, RemoteRepository
47
 
from bzrlib.repofmt import weaverepo
 
46
from bzrlib.remote import (
 
47
    RemoteBzrDir,
 
48
    RemoteBzrDirFormat,
 
49
    RemoteRepository,
 
50
    )
48
51
 
49
52
 
50
53
class TestControlDir(TestCaseWithControlDir):
98
101
                                    create_tree_if_local=create_tree_if_local)
99
102
        return target
100
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
 
101
111
    def test_create_null_workingtree(self):
102
112
        dir = self.make_bzrdir('dir1')
103
113
        dir.create_repository()
119
129
            bzrdir.destroy_workingtree()
120
130
        except errors.UnsupportedOperation:
121
131
            raise TestSkipped('Format does not support destroying tree')
122
 
        self.failIfExists('tree/file')
 
132
        self.assertPathDoesNotExist('tree/file')
123
133
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
124
134
        bzrdir.create_workingtree()
125
 
        self.failUnlessExists('tree/file')
 
135
        self.assertPathExists('tree/file')
126
136
        bzrdir.destroy_workingtree_metadata()
127
 
        self.failUnlessExists('tree/file')
 
137
        self.assertPathExists('tree/file')
128
138
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
129
139
 
130
140
    def test_destroy_branch(self):
146
156
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
147
157
            raise TestNotApplicable('Format does not support destroying'
148
158
                                    ' repository')
 
159
        self.assertRaises(errors.NoRepositoryPresent,
 
160
            bzrdir.destroy_repository)
149
161
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
150
162
        bzrdir.create_repository()
151
163
        bzrdir.open_repository()
159
171
        if vfs_dir.has_workingtree():
160
172
            # This ControlDir format doesn't support ControlDirs without
161
173
            # working trees, so this test is irrelevant.
162
 
            return
 
174
            raise TestNotApplicable("format does not support "
 
175
                "control directories without working tree")
163
176
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
164
177
 
165
178
    def test_clone_bzrdir_repository_under_shared(self):
169
182
        tree.commit('revision 1', rev_id='1')
170
183
        dir = self.make_bzrdir('source')
171
184
        repo = dir.create_repository()
 
185
        if not repo._format.supports_nesting_repositories:
 
186
            raise TestNotApplicable("repository format does not support "
 
187
                "nesting")
172
188
        repo.fetch(tree.branch.repository)
173
189
        self.assertTrue(repo.has_revision('1'))
174
190
        try:
175
191
            self.make_repository('target', shared=True)
176
192
        except errors.IncompatibleFormat:
177
 
            return
 
193
            raise TestNotApplicable("repository format does not support "
 
194
                "shared repositories")
178
195
        target = dir.clone(self.get_url('target/child'))
179
196
        self.assertNotEqual(dir.transport.base, target.transport.base)
180
197
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
184
201
        try:
185
202
            shared_repo = self.make_repository('shared', shared=True)
186
203
        except errors.IncompatibleFormat:
187
 
            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")
188
209
        # Make a branch, 'commit_tree', and working tree outside of the shared
189
210
        # repository, and commit some revisions to it.
190
211
        tree = self.make_branch_and_tree('commit_tree')
191
212
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
192
213
        tree.add('foo')
193
214
        tree.commit('revision 1', rev_id='1')
194
 
        tree.bzrdir.open_branch().set_revision_history([])
 
215
        tree.bzrdir.open_branch().generate_revision_history(
 
216
            bzrlib.revision.NULL_REVISION)
195
217
        tree.set_parent_trees([])
196
218
        tree.commit('revision 2', rev_id='2')
197
219
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
214
236
        try:
215
237
            shared_repo = self.make_repository('shared', shared=True)
216
238
        except errors.IncompatibleFormat:
217
 
            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")
218
244
        tree = self.make_branch_and_tree('commit_tree')
219
245
        self.build_tree(['commit_tree/foo'])
220
246
        tree.add('foo')
221
247
        tree.commit('revision 1', rev_id='1')
222
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
248
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
249
            bzrlib.revision.NULL_REVISION)
223
250
        tree.set_parent_trees([])
224
251
        tree.commit('revision 2', rev_id='2')
225
252
        tree.branch.repository.copy_content_into(shared_repo)
246
273
        self.build_tree(['commit_tree/foo'])
247
274
        tree.add('foo')
248
275
        tree.commit('revision 1', rev_id='1')
249
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
276
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
277
            bzrlib.revision.NULL_REVISION)
250
278
        tree.set_parent_trees([])
251
279
        tree.commit('revision 2', rev_id='2')
252
280
        source = self.make_repository('source')
257
285
 
258
286
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
259
287
        # Bug #430868 is about an email containing '.sig'
260
 
        os.environ['BZR_EMAIL'] = 'murphy@host.sighup.org'
 
288
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
261
289
        tree = self.make_branch_and_tree('commit_tree')
262
290
        self.build_tree(['commit_tree/foo'])
263
291
        tree.add('foo')
286
314
        tree.branch.repository.copy_content_into(source.repository)
287
315
        tree.branch.copy_content_into(source)
288
316
        try:
289
 
            self.make_repository('target', shared=True)
 
317
            shared_repo = self.make_repository('target', shared=True)
290
318
        except errors.IncompatibleFormat:
291
 
            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")
292
324
        dir = source.bzrdir
293
325
        target = dir.clone(self.get_url('target/child'))
294
326
        self.assertNotEqual(dir.transport.base, target.transport.base)
295
327
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
296
 
        self.assertEqual(source.revision_history(),
297
 
                         target.open_branch().revision_history())
 
328
        self.assertEqual(source.last_revision(),
 
329
                         target.open_branch().last_revision())
298
330
 
299
331
    def test_clone_bzrdir_branch_revision(self):
300
332
        # test for revision limiting, [smoke test, not corner case checks].
363
395
            repo.set_make_working_trees(False)
364
396
            self.assertFalse(repo.make_working_trees())
365
397
 
366
 
        dir = tree.bzrdir
367
 
        a_dir = dir.clone(self.get_url('repo/a'))
368
 
        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')
369
404
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
370
405
 
371
406
    def test_clone_respects_stacked(self):
372
407
        branch = self.make_branch('parent')
373
408
        child_transport = self.get_transport('child')
374
 
        child = branch.bzrdir.clone_on_transport(child_transport,
375
 
                                                 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")
376
416
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
377
417
 
378
418
    def test_get_branch_reference_on_reference(self):
384
424
                target_branch=referenced_branch)
385
425
        except errors.IncompatibleFormat:
386
426
            # this is ok too, not all formats have to support references.
387
 
            return
 
427
            raise TestNotApplicable("control directory does not "
 
428
                "support branch references")
388
429
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
389
430
            dir.get_branch_reference())
390
431
 
398
439
        dir = self.make_bzrdir('source')
399
440
        if dir.has_branch():
400
441
            # this format does not support branchless bzrdirs.
401
 
            return
 
442
            raise TestNotApplicable("format does not support "
 
443
                "branchless control directories")
402
444
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
403
445
 
404
446
    def test_sprout_bzrdir_empty(self):
405
447
        dir = self.make_bzrdir('source')
406
448
        target = dir.sprout(self.get_url('target'))
407
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
449
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
408
450
        # creates a new repository branch and tree
409
451
        target.open_repository()
410
452
        target.open_branch()
416
458
        try:
417
459
            self.make_repository('target', shared=True)
418
460
        except errors.IncompatibleFormat:
419
 
            return
 
461
            raise TestNotApplicable("format does not support shared "
 
462
                "repositories")
420
463
        target = dir.sprout(self.get_url('target/child'))
421
464
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
422
465
        target.open_branch()
424
467
            target.open_workingtree()
425
468
        except errors.NoWorkingTree:
426
469
            # Some bzrdirs can never have working trees.
427
 
            self.assertFalse(target._format.supports_workingtrees)
 
470
            repo = target.find_repository()
 
471
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
428
472
 
429
473
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
430
474
        # the force_new_repo parameter should force use of a new repo in an empty
433
477
        try:
434
478
            self.make_repository('target', shared=True)
435
479
        except errors.IncompatibleFormat:
436
 
            return
 
480
            raise TestNotApplicable("format does not support shared "
 
481
                "repositories")
437
482
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
438
483
        target.open_repository()
439
484
        target.open_branch()
444
489
        self.build_tree(['commit_tree/foo'])
445
490
        tree.add('foo')
446
491
        tree.commit('revision 1', rev_id='1')
447
 
        tree.bzrdir.open_branch().set_revision_history([])
 
492
        tree.bzrdir.open_branch().generate_revision_history(
 
493
            bzrlib.revision.NULL_REVISION)
448
494
        tree.set_parent_trees([])
449
495
        tree.commit('revision 2', rev_id='2')
450
496
        source = self.make_repository('source')
453
499
        try:
454
500
            shared_repo = self.make_repository('target', shared=True)
455
501
        except errors.IncompatibleFormat:
456
 
            return
 
502
            raise TestNotApplicable("format does not support "
 
503
                "shared repositories")
457
504
        target = dir.sprout(self.get_url('target/child'))
458
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
505
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
459
506
        self.assertTrue(shared_repo.has_revision('1'))
460
507
 
461
508
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
462
509
        try:
463
510
            shared_repo = self.make_repository('shared', shared=True)
464
511
        except errors.IncompatibleFormat:
465
 
            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")
466
517
        tree = self.make_branch_and_tree('commit_tree')
467
518
        self.build_tree(['commit_tree/foo'])
468
519
        tree.add('foo')
469
520
        tree.commit('revision 1', rev_id='1')
470
 
        tree.bzrdir.open_branch().set_revision_history([])
 
521
        tree.bzrdir.open_branch().generate_revision_history(
 
522
            bzrlib.revision.NULL_REVISION)
471
523
        tree.set_parent_trees([])
472
524
        tree.commit('revision 2', rev_id='2')
473
525
        tree.branch.repository.copy_content_into(shared_repo)
482
534
        try:
483
535
            shared_repo = self.make_repository('shared', shared=True)
484
536
        except errors.IncompatibleFormat:
485
 
            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")
486
542
        tree = self.make_branch_and_tree('commit_tree')
487
543
        self.build_tree(['commit_tree/foo'])
488
544
        tree.add('foo')
489
545
        tree.commit('revision 1', rev_id='1')
490
 
        tree.bzrdir.open_branch().set_revision_history([])
 
546
        tree.bzrdir.open_branch().generate_revision_history(
 
547
            bzrlib.revision.NULL_REVISION)
491
548
        tree.set_parent_trees([])
492
549
        tree.commit('revision 2', rev_id='2')
493
550
        tree.branch.repository.copy_content_into(shared_repo)
501
558
        self.assertNotEqual(dir.transport.base, target.transport.base)
502
559
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
503
560
        branch = target.open_branch()
504
 
        self.assertTrue(branch.repository.has_revision('1'))
 
561
        # The sprouted bzrdir has a branch, so only revisions referenced by
 
562
        # that branch are copied, rather than the whole repository.  It's an
 
563
        # empty branch, so none are copied.
 
564
        self.assertEqual([], branch.repository.all_revision_ids())
505
565
        if branch.bzrdir._format.supports_workingtrees:
506
566
            self.assertTrue(branch.repository.make_working_trees())
507
567
        self.assertFalse(branch.repository.is_shared())
511
571
        self.build_tree(['commit_tree/foo'])
512
572
        tree.add('foo')
513
573
        tree.commit('revision 1', rev_id='1')
514
 
        tree.bzrdir.open_branch().set_revision_history([])
 
574
        tree.bzrdir.open_branch().generate_revision_history(
 
575
            bzrlib.revision.NULL_REVISION)
515
576
        tree.set_parent_trees([])
516
577
        tree.commit('revision 2', rev_id='2')
517
578
        source = self.make_repository('source')
520
581
        try:
521
582
            shared_repo = self.make_repository('target', shared=True)
522
583
        except errors.IncompatibleFormat:
523
 
            return
 
584
            raise TestNotApplicable("format does not support shared "
 
585
                "repositories")
524
586
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
525
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
587
        self.assertNotEqual(
 
588
            dir.control_transport.base,
 
589
            target.control_transport.base)
526
590
        self.assertFalse(shared_repo.has_revision('1'))
527
591
 
528
592
    def test_sprout_bzrdir_repository_revision(self):
534
598
        self.build_tree(['commit_tree/foo'])
535
599
        tree.add('foo')
536
600
        tree.commit('revision 1', rev_id='1')
537
 
        tree.bzrdir.open_branch().set_revision_history([])
 
601
        br = tree.bzrdir.open_branch()
 
602
        br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
538
603
        tree.set_parent_trees([])
539
604
        tree.commit('revision 2', rev_id='2')
540
605
        source = self.make_repository('source')
557
622
        try:
558
623
            shared_repo = self.make_repository('target', shared=True)
559
624
        except errors.IncompatibleFormat:
560
 
            return
 
625
            raise TestNotApplicable("format does not support shared "
 
626
                "repositories")
561
627
        target = dir.sprout(self.get_url('target/child'))
562
628
        self.assertTrue(shared_repo.has_revision('1'))
563
629
 
575
641
        try:
576
642
            shared_repo = self.make_repository('target', shared=True)
577
643
        except errors.IncompatibleFormat:
578
 
            return
 
644
            raise TestNotApplicable("format does not support shared "
 
645
                "repositories")
579
646
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
580
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
647
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
581
648
        self.assertFalse(shared_repo.has_revision('1'))
582
649
 
583
650
    def test_sprout_bzrdir_branch_reference(self):
588
655
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
589
656
                target_branch=referenced_branch)
590
657
        except errors.IncompatibleFormat:
591
 
            # this is ok too, not all formats have to support references.
592
 
            return
 
658
            raise TestNotApplicable("format does not support branch "
 
659
                "references")
593
660
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
594
661
        target = dir.sprout(self.get_url('target'))
595
662
        self.assertNotEqual(dir.transport.base, target.transport.base)
608
675
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
609
676
                target_branch=referenced_tree.branch)
610
677
        except errors.IncompatibleFormat:
611
 
            # this is ok too, not all formats have to support references.
612
 
            return
 
678
            raise TestNotApplicable("format does not support branch "
 
679
                "references")
613
680
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
614
681
        try:
615
682
            shared_repo = self.make_repository('target', shared=True)
616
683
        except errors.IncompatibleFormat:
617
 
            return
 
684
            raise TestNotApplicable("format does not support "
 
685
                "shared repositories")
618
686
        target = dir.sprout(self.get_url('target/child'))
619
687
        self.assertNotEqual(dir.transport.base, target.transport.base)
620
688
        # we want target to have a branch that is in-place.
635
703
                target_branch=referenced_tree.branch)
636
704
        except errors.IncompatibleFormat:
637
705
            # this is ok too, not all formats have to support references.
638
 
            return
 
706
            raise TestNotApplicable("format does not support "
 
707
                "branch references")
639
708
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
640
709
        try:
641
710
            shared_repo = self.make_repository('target', shared=True)
642
711
        except errors.IncompatibleFormat:
643
 
            return
 
712
            raise TestNotApplicable("format does not support shared "
 
713
                "repositories")
644
714
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
645
715
        self.assertNotEqual(dir.transport.base, target.transport.base)
646
716
        # we want target to have a branch that is in-place.
667
737
        target = dir.sprout(self.get_url('target'), revision_id='1')
668
738
        self.assertEqual('1', target.open_branch().last_revision())
669
739
 
 
740
    def test_sprout_bzrdir_branch_with_tags(self):
 
741
        # when sprouting a branch all revisions named in the tags are copied
 
742
        # too.
 
743
        builder = self.make_branch_builder('source')
 
744
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
745
        try:
 
746
            source.tags.set_tag('tag-a', 'rev-2')
 
747
        except errors.TagsNotSupported:
 
748
            raise TestNotApplicable('Branch format does not support tags.')
 
749
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
750
        # Now source has a tag not in its ancestry.  Sprout its controldir.
 
751
        dir = source.bzrdir
 
752
        target = dir.sprout(self.get_url('target'))
 
753
        # The tag is present, and so is its revision.
 
754
        new_branch = target.open_branch()
 
755
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
756
        new_branch.repository.get_revision('rev-2')
 
757
 
 
758
    def test_sprout_bzrdir_branch_with_absent_tag(self):
 
759
        # tags referencing absent revisions are copied (and those absent
 
760
        # revisions do not prevent the sprout.)
 
761
        builder = self.make_branch_builder('source')
 
762
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
763
        source = builder.get_branch()
 
764
        try:
 
765
            source.tags.set_tag('tag-a', 'missing-rev')
 
766
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
767
            raise TestNotApplicable('Branch format does not support tags '
 
768
                'or tags referencing ghost revisions.')
 
769
        # Now source has a tag pointing to an absent revision.  Sprout its
 
770
        # controldir.
 
771
        dir = source.bzrdir
 
772
        target = dir.sprout(self.get_url('target'))
 
773
        # The tag is present in the target
 
774
        new_branch = target.open_branch()
 
775
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
776
 
 
777
    def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
 
778
        # tags referencing absent revisions are copied (and those absent
 
779
        # revisions do not prevent the sprout.)
 
780
        builder = self.make_branch_builder('source')
 
781
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
782
        source = builder.get_branch()
 
783
        try:
 
784
            source.tags.set_tag('tag-a', 'missing-rev')
 
785
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
 
786
            raise TestNotApplicable('Branch format does not support tags '
 
787
                'or tags referencing missing revisions.')
 
788
        # Now source has a tag pointing to an absent revision.  Sprout its
 
789
        # controldir.
 
790
        dir = source.bzrdir
 
791
        target = dir.sprout(self.get_url('target'), source_branch=source)
 
792
        # The tag is present in the target
 
793
        new_branch = target.open_branch()
 
794
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
795
 
 
796
    def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
 
797
        # dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
 
798
        # the branch at that bzrdir, the ancestry of all of those, but no other
 
799
        # revs (not even the tip of the source branch).
 
800
        builder = self.make_branch_builder('source')
 
801
        builder.build_commit(message="Base", rev_id='base-rev')
 
802
        # Make three parallel lines of ancestry off this base.
 
803
        source = builder.get_branch()
 
804
        builder.build_commit(message="Rev A1", rev_id='rev-a1')
 
805
        builder.build_commit(message="Rev A2", rev_id='rev-a2')
 
806
        builder.build_commit(message="Rev A3", rev_id='rev-a3')
 
807
        source.set_last_revision_info(1, 'base-rev')
 
808
        builder.build_commit(message="Rev B1", rev_id='rev-b1')
 
809
        builder.build_commit(message="Rev B2", rev_id='rev-b2')
 
810
        builder.build_commit(message="Rev B3", rev_id='rev-b3')
 
811
        source.set_last_revision_info(1, 'base-rev')
 
812
        builder.build_commit(message="Rev C1", rev_id='rev-c1')
 
813
        builder.build_commit(message="Rev C2", rev_id='rev-c2')
 
814
        builder.build_commit(message="Rev C3", rev_id='rev-c3')
 
815
        # Set the branch tip to A2
 
816
        source.set_last_revision_info(3, 'rev-a2')
 
817
        try:
 
818
            # Create a tag for B2, and for an absent rev
 
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:
 
823
            source.tags.set_tag('tag-absent', 'absent-rev')
 
824
        except errors.GhostTagsNotSupported:
 
825
            has_ghost_tag = False
 
826
        else:
 
827
            has_ghost_tag = True
 
828
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
829
        # And ask sprout for C2
 
830
        dir = source.bzrdir
 
831
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
 
832
        # The tags are present
 
833
        new_branch = target.open_branch()
 
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())
 
842
        # And the revs for A2, B2 and C2's ancestries are present, but no
 
843
        # others.
 
844
        self.assertEqual(
 
845
            ['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
 
846
            sorted(new_branch.repository.all_revision_ids()))
 
847
 
670
848
    def test_sprout_bzrdir_tree_branch_reference(self):
671
849
        # sprouting should create a repository if needed and a sprouted branch.
672
850
        # the tree state should not be copied.
677
855
                target_branch=referenced_branch)
678
856
        except errors.IncompatibleFormat:
679
857
            # this is ok too, not all formats have to support references.
680
 
            return
 
858
            raise TestNotApplicable("format does not support "
 
859
                "branch references")
681
860
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
682
861
        tree = self.createWorkingTreeOrSkip(dir)
683
862
        self.build_tree(['source/subdir/'])
703
882
                target_branch=referenced_branch)
704
883
        except errors.IncompatibleFormat:
705
884
            # this is ok too, not all formats have to support references.
706
 
            return
 
885
            raise TestNotApplicable("format does not support "
 
886
                "branch references")
707
887
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
708
888
        tree = self.createWorkingTreeOrSkip(dir)
709
889
        self.build_tree(['source/foo'])
755
935
        tree.commit('revision 1', rev_id='1')
756
936
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
757
937
        dir = tree.bzrdir
758
 
        if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
759
 
            self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
760
 
                              self.get_url('target'),
761
 
                              create_tree_if_local=False)
762
 
            return
763
 
        target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
764
 
        self.failIfExists('target/foo')
 
938
        try:
 
939
            target = dir.sprout(self.get_url('target'),
 
940
                create_tree_if_local=False)
 
941
        except errors.MustHaveWorkingTree:
 
942
            raise TestNotApplicable("control dir format requires working tree")
 
943
        self.assertPathDoesNotExist('target/foo')
765
944
        self.assertEqual(tree.branch.last_revision(),
766
945
                         target.open_branch().last_revision())
767
946
 
790
969
 
791
970
    def test_format_initialize_find_open(self):
792
971
        # loopback test to check the current format initializes to itself.
793
 
        if not self.bzrdir_format.is_supported():
 
972
        if not self.bzrdir_format.is_initializable():
794
973
            # unsupported formats are not loopback testable
795
974
            # because the default open will not open them and
796
975
            # they may not be initializable.
797
 
            return
 
976
            raise TestNotApplicable("format is not initializable")
798
977
        # for remote formats, there must be no prior assumption about the
799
978
        # network name to use - it's possible that this may somehow have got
800
979
        # in through an unisolated test though - see
803
982
            '_network_name', None),
804
983
            None)
805
984
        # supported formats must be able to init and open
806
 
        t = transport.get_transport(self.get_url())
807
 
        readonly_t = transport.get_transport(self.get_readonly_url())
 
985
        t = self.get_transport()
 
986
        readonly_t = self.get_readonly_transport()
808
987
        made_control = self.bzrdir_format.initialize(t.base)
809
 
        self.failUnless(isinstance(made_control, controldir.ControlDir))
 
988
        self.assertIsInstance(made_control, controldir.ControlDir)
 
989
        if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
 
990
            return
810
991
        self.assertEqual(self.bzrdir_format,
811
992
                         controldir.ControlDirFormat.find_format(readonly_t))
812
993
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
815
996
                         opened_dir._format)
816
997
        self.assertEqual(direct_opened_dir._format,
817
998
                         opened_dir._format)
818
 
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
 
999
        self.assertIsInstance(opened_dir, controldir.ControlDir)
819
1000
 
820
1001
    def test_format_initialize_on_transport_ex(self):
821
1002
        t = self.get_transport('dir')
827
1008
        self.assertInitializeEx(t, use_existing_dir=True)
828
1009
 
829
1010
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
830
 
        if not self.bzrdir_format.is_supported():
831
 
            # Not initializable - not a failure either.
832
 
            return
 
1011
        if not self.bzrdir_format.is_initializable():
 
1012
            raise TestNotApplicable("format is not initializable")
833
1013
        t = self.get_transport('dir')
834
1014
        t.ensure_base()
835
1015
        self.assertRaises(errors.FileExists,
841
1021
        self.assertInitializeEx(t, create_prefix=True)
842
1022
 
843
1023
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
844
 
        if not self.bzrdir_format.is_supported():
845
 
            # Not initializable - not a failure either.
846
 
            return
 
1024
        if not self.bzrdir_format.is_initializable():
 
1025
            raise TestNotApplicable("format is not initializable")
847
1026
        t = self.get_transport('missing/dir')
848
1027
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
849
1028
            create_prefix=False)
856
1035
            repo_format_name=repo_name, shared_repo=True)[0]
857
1036
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
858
1037
            force_new_repo=True, repo_format_name=repo_name)
859
 
        if control is None:
860
 
            # uninitialisable format
861
 
            return
862
1038
        self.assertNotEqual(repo.bzrdir.root_transport.base,
863
1039
            made_repo.bzrdir.root_transport.base)
864
1040
 
870
1046
            repo_format_name=repo_name, shared_repo=True)[0]
871
1047
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
872
1048
            force_new_repo=False, repo_format_name=repo_name)
873
 
        if control is None:
874
 
            # uninitialisable format
875
 
            return
876
 
        if not isinstance(control._format, (bzrdir.BzrDirFormat5,
877
 
            bzrdir.BzrDirFormat6,)):
 
1049
        if not control._format.fixed_components:
878
1050
            self.assertEqual(repo.bzrdir.root_transport.base,
879
1051
                made_repo.bzrdir.root_transport.base)
880
1052
 
881
 
    def test_format_initialize_on_transport_ex_stacked_on(self):
882
 
        # trunk is a stackable format.  Note that its in the same server area
883
 
        # which is what launchpad does, but not sufficient to exercise the
884
 
        # general case.
885
 
        trunk = self.make_branch('trunk', format='1.9')
886
 
        t = self.get_transport('stacked')
887
 
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
888
 
        repo_name = old_fmt.repository_format.network_name()
889
 
        # Should end up with a 1.9 format (stackable)
890
 
        repo, control = self.assertInitializeEx(t, need_meta=True,
891
 
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
892
 
        if control is None:
893
 
            # uninitialisable format
894
 
            return
895
 
        self.assertLength(1, repo._fallback_repositories)
896
 
 
897
 
    def test_format_initialize_on_transport_ex_default_stack_on(self):
898
 
        # When initialize_on_transport_ex uses a stacked-on branch because of
899
 
        # a stacking policy on the target, the location of the fallback
900
 
        # repository is the same as the external location of the stacked-on
901
 
        # branch.
902
 
        balloon = self.make_bzrdir('balloon')
903
 
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
904
 
            stack_on = self.make_branch('stack-on', format='1.9')
905
 
        else:
906
 
            stack_on = self.make_branch('stack-on')
907
 
        config = self.make_bzrdir('.').get_config()
908
 
        try:
909
 
            config.set_default_stack_on('stack-on')
910
 
        except errors.BzrError:
911
 
            raise TestNotApplicable('Only relevant for stackable formats.')
912
 
        # Initialize a bzrdir subject to the policy.
913
 
        t = self.get_transport('stacked')
914
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
915
 
        repo_name = repo_fmt.repository_format.network_name()
916
 
        repo, control = self.assertInitializeEx(
917
 
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
918
 
        # self.addCleanup(repo.unlock)
919
 
        if control is None:
920
 
            # uninitialisable format
921
 
            return
922
 
        # There's one fallback repo, with a public location.
923
 
        self.assertLength(1, repo._fallback_repositories)
924
 
        fallback_repo = repo._fallback_repositories[0]
925
 
        self.assertEqual(
926
 
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
927
 
        # The bzrdir creates a branch in stacking-capable format.
928
 
        new_branch = control.create_branch()
929
 
        self.assertTrue(new_branch._format.supports_stacking())
930
 
 
931
1053
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
932
1054
        t = self.get_transport('dir')
933
1055
        repo, control = self.assertInitializeEx(t)
939
1061
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
940
1062
        repo_name = fmt.repository_format.network_name()
941
1063
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
942
 
        if control is None:
943
 
            # uninitialisable format
944
 
            return
945
 
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
946
 
            bzrdir.BzrDirFormat6)):
 
1064
        if self.bzrdir_format.fixed_components:
947
1065
            # must stay with the all-in-one-format.
948
1066
            repo_name = self.bzrdir_format.network_name()
949
1067
        self.assertEqual(repo_name, repo._format.network_name())
950
1068
 
951
 
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
1069
    def assertInitializeEx(self, t, **kwargs):
952
1070
        """Execute initialize_on_transport_ex and check it succeeded correctly.
953
1071
 
954
1072
        This involves checking that the disk objects were created, open with
959
1077
            initialize_on_transport_ex.
960
1078
        :return: the resulting repo, control dir tuple.
961
1079
        """
962
 
        if not self.bzrdir_format.is_supported():
963
 
            # Not initializable - not a failure either.
964
 
            return None, None
 
1080
        if not self.bzrdir_format.is_initializable():
 
1081
            raise TestNotApplicable("control dir format is not "
 
1082
                "initializable")
965
1083
        repo, control, require_stacking, repo_policy = \
966
1084
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
967
1085
        if repo is not None:
968
1086
            # Repositories are open write-locked
969
1087
            self.assertTrue(repo.is_write_locked())
970
1088
            self.addCleanup(repo.unlock)
971
 
        self.assertIsInstance(control, bzrdir.BzrDir)
 
1089
        self.assertIsInstance(control, controldir.ControlDir)
972
1090
        opened = bzrdir.BzrDir.open(t.base)
973
1091
        expected_format = self.bzrdir_format
974
 
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
975
 
            # Current RemoteBzrDirFormat's do not reliably get network_name
976
 
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
977
 
            self.assertIsInstance(control, RemoteBzrDir)
978
 
        else:
979
 
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
980
 
                bzrdir.BzrDirFormat6)):
981
 
                # Pre-metadir formats change when we are making something that
982
 
                # needs a metaformat, because clone is used for push.
983
 
                expected_format = bzrdir.BzrDirMetaFormat1()
 
1092
        if not isinstance(expected_format, RemoteBzrDirFormat):
984
1093
            self.assertEqual(control._format.network_name(),
985
1094
                expected_format.network_name())
986
1095
            self.assertEqual(control._format.network_name(),
997
1106
        # key in the registry gives back the same format. For remote obects
998
1107
        # we check that the network_name of the RemoteBzrDirFormat we have
999
1108
        # locally matches the actual format present on disk.
1000
 
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
 
1109
        if isinstance(format, RemoteBzrDirFormat):
1001
1110
            dir._ensure_real()
1002
1111
            real_dir = dir._real_bzrdir
1003
1112
            network_name = format.network_name()
1015
1124
        # test the formats specific behaviour for no-content or similar dirs.
1016
1125
        self.assertRaises(errors.NotBranchError,
1017
1126
                          self.bzrdir_format.open,
1018
 
                          transport.get_transport(self.get_readonly_url()))
 
1127
                          transport.get_transport_from_url(self.get_readonly_url()))
1019
1128
 
1020
1129
    def test_create_branch(self):
1021
1130
        # a bzrdir can construct a branch and repository for itself.
1022
 
        if not self.bzrdir_format.is_supported():
 
1131
        if not self.bzrdir_format.is_initializable():
1023
1132
            # unsupported formats are not loopback testable
1024
1133
            # because the default open will not open them and
1025
1134
            # they may not be initializable.
1026
 
            return
1027
 
        t = transport.get_transport(self.get_url())
 
1135
            raise TestNotApplicable("format is not initializable")
 
1136
        t = self.get_transport()
1028
1137
        made_control = self.bzrdir_format.initialize(t.base)
1029
1138
        made_repo = made_control.create_repository()
1030
1139
        made_branch = made_control.create_branch()
1031
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
1140
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
 
1141
        self.assertEqual(made_control, made_branch.bzrdir)
 
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())
1032
1161
        self.assertEqual(made_control, made_branch.bzrdir)
1033
1162
 
1034
1163
    def test_open_branch(self):
1035
 
        if not self.bzrdir_format.is_supported():
 
1164
        if not self.bzrdir_format.is_initializable():
1036
1165
            # unsupported formats are not loopback testable
1037
1166
            # because the default open will not open them and
1038
1167
            # they may not be initializable.
1039
 
            return
1040
 
        t = transport.get_transport(self.get_url())
 
1168
            raise TestNotApplicable("format is not initializable")
 
1169
        t = self.get_transport()
1041
1170
        made_control = self.bzrdir_format.initialize(t.base)
1042
1171
        made_repo = made_control.create_repository()
1043
1172
        made_branch = made_control.create_branch()
1044
1173
        opened_branch = made_control.open_branch()
1045
1174
        self.assertEqual(made_control, opened_branch.bzrdir)
1046
 
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1047
 
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
 
1175
        self.assertIsInstance(opened_branch, made_branch.__class__)
 
1176
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1048
1177
 
1049
1178
    def test_list_branches(self):
1050
 
        if not self.bzrdir_format.is_supported():
1051
 
            # unsupported formats are not loopback testable
1052
 
            # because the default open will not open them and
1053
 
            # they may not be initializable.
1054
 
            return
1055
 
        t = transport.get_transport(self.get_url())
 
1179
        if not self.bzrdir_format.is_initializable():
 
1180
            raise TestNotApplicable("format is not initializable")
 
1181
        t = self.get_transport()
1056
1182
        made_control = self.bzrdir_format.initialize(t.base)
1057
1183
        made_repo = made_control.create_repository()
1058
1184
        made_branch = made_control.create_branch()
1066
1192
        else:
1067
1193
            self.assertEquals([], made_control.list_branches())
1068
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
 
1069
1200
    def test_create_repository(self):
1070
1201
        # a bzrdir can construct a repository for itself.
1071
 
        if not self.bzrdir_format.is_supported():
 
1202
        if not self.bzrdir_format.is_initializable():
1072
1203
            # unsupported formats are not loopback testable
1073
1204
            # because the default open will not open them and
1074
1205
            # they may not be initializable.
1075
 
            return
1076
 
        t = transport.get_transport(self.get_url())
 
1206
            raise TestNotApplicable("format is not initializable")
 
1207
        t = self.get_transport()
1077
1208
        made_control = self.bzrdir_format.initialize(t.base)
1078
1209
        made_repo = made_control.create_repository()
1079
1210
        # Check that we have a repository object.
1083
1214
    def test_create_repository_shared(self):
1084
1215
        # a bzrdir can create a shared repository or
1085
1216
        # fail appropriately
1086
 
        if not self.bzrdir_format.is_supported():
 
1217
        if not self.bzrdir_format.is_initializable():
1087
1218
            # unsupported formats are not loopback testable
1088
1219
            # because the default open will not open them and
1089
1220
            # they may not be initializable.
1090
 
            return
1091
 
        t = transport.get_transport(self.get_url())
 
1221
            raise TestNotApplicable("format is not initializable")
 
1222
        t = self.get_transport()
1092
1223
        made_control = self.bzrdir_format.initialize(t.base)
1093
1224
        try:
1094
1225
            made_repo = made_control.create_repository(shared=True)
1095
1226
        except errors.IncompatibleFormat:
1096
1227
            # Old bzrdir formats don't support shared repositories
1097
1228
            # and should raise IncompatibleFormat
1098
 
            return
 
1229
            raise TestNotApplicable("format does not support shared "
 
1230
                "repositories")
1099
1231
        self.assertTrue(made_repo.is_shared())
1100
1232
 
1101
1233
    def test_create_repository_nonshared(self):
1102
1234
        # a bzrdir can create a non-shared repository
1103
 
        if not self.bzrdir_format.is_supported():
 
1235
        if not self.bzrdir_format.is_initializable():
1104
1236
            # unsupported formats are not loopback testable
1105
1237
            # because the default open will not open them and
1106
1238
            # they may not be initializable.
1107
 
            return
1108
 
        t = transport.get_transport(self.get_url())
 
1239
            raise TestNotApplicable("format is not initializable")
 
1240
        t = self.get_transport()
1109
1241
        made_control = self.bzrdir_format.initialize(t.base)
1110
 
        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")
1111
1249
        self.assertFalse(made_repo.is_shared())
1112
1250
 
1113
1251
    def test_open_repository(self):
1114
 
        if not self.bzrdir_format.is_supported():
 
1252
        if not self.bzrdir_format.is_initializable():
1115
1253
            # unsupported formats are not loopback testable
1116
1254
            # because the default open will not open them and
1117
1255
            # they may not be initializable.
1118
 
            return
1119
 
        t = transport.get_transport(self.get_url())
 
1256
            raise TestNotApplicable("format is not initializable")
 
1257
        t = self.get_transport()
1120
1258
        made_control = self.bzrdir_format.initialize(t.base)
1121
1259
        made_repo = made_control.create_repository()
1122
1260
        opened_repo = made_control.open_repository()
1123
1261
        self.assertEqual(made_control, opened_repo.bzrdir)
1124
 
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1125
 
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
 
1262
        self.assertIsInstance(opened_repo, made_repo.__class__)
 
1263
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1126
1264
 
1127
1265
    def test_create_workingtree(self):
1128
1266
        # a bzrdir can construct a working tree for itself.
1129
 
        if not self.bzrdir_format.is_supported():
 
1267
        if not self.bzrdir_format.is_initializable():
1130
1268
            # unsupported formats are not loopback testable
1131
1269
            # because the default open will not open them and
1132
1270
            # they may not be initializable.
1133
 
            return
 
1271
            raise TestNotApplicable("format is not initializable")
1134
1272
        t = self.get_transport()
1135
1273
        made_control = self.bzrdir_format.initialize(t.base)
1136
1274
        made_repo = made_control.create_repository()
1137
1275
        made_branch = made_control.create_branch()
1138
1276
        made_tree = self.createWorkingTreeOrSkip(made_control)
1139
 
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
 
1277
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
1140
1278
        self.assertEqual(made_control, made_tree.bzrdir)
1141
1279
 
1142
1280
    def test_create_workingtree_revision(self):
1143
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")
1144
1284
        t = self.get_transport()
1145
1285
        source = self.make_branch_and_tree('source')
1146
1286
        source.commit('a', rev_id='a', allow_pointless=True)
1157
1297
        self.assertEqual(['a'], made_tree.get_parent_ids())
1158
1298
 
1159
1299
    def test_open_workingtree(self):
1160
 
        if not self.bzrdir_format.is_supported():
1161
 
            # unsupported formats are not loopback testable
1162
 
            # because the default open will not open them and
1163
 
            # they may not be initializable.
1164
 
            return
 
1300
        if not self.bzrdir_format.is_initializable():
 
1301
            raise TestNotApplicable("format is not initializable")
1165
1302
        # this has to be tested with local access as we still support creating
1166
1303
        # format 6 bzrdirs
1167
1304
        t = self.get_transport()
1175
1312
                              % (self.bzrdir_format, t))
1176
1313
        opened_tree = made_control.open_workingtree()
1177
1314
        self.assertEqual(made_control, opened_tree.bzrdir)
1178
 
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1179
 
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1180
 
 
1181
 
    def test_get_branch_transport(self):
1182
 
        dir = self.make_bzrdir('.')
1183
 
        # without a format, get_branch_transport gives use a transport
1184
 
        # which -may- point to an existing dir.
1185
 
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1186
 
                                   transport.Transport))
1187
 
        # with a given format, either the bzr dir supports identifiable
1188
 
        # branches, or it supports anonymous  branch formats, but not both.
1189
 
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1190
 
        identifiable_format = bzrlib.branch.BzrBranchFormat5()
1191
 
        try:
1192
 
            found_transport = dir.get_branch_transport(anonymous_format)
1193
 
            self.assertRaises(errors.IncompatibleFormat,
1194
 
                              dir.get_branch_transport,
1195
 
                              identifiable_format)
1196
 
        except errors.IncompatibleFormat:
1197
 
            found_transport = dir.get_branch_transport(identifiable_format)
1198
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1199
 
        # and the dir which has been initialized for us must exist.
1200
 
        found_transport.list_dir('.')
1201
 
 
1202
 
    def test_get_repository_transport(self):
1203
 
        dir = self.make_bzrdir('.')
1204
 
        # without a format, get_repository_transport gives use a transport
1205
 
        # which -may- point to an existing dir.
1206
 
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1207
 
                                   transport.Transport))
1208
 
        # with a given format, either the bzr dir supports identifiable
1209
 
        # repositories, or it supports anonymous  repository formats, but not both.
1210
 
        anonymous_format = weaverepo.RepositoryFormat6()
1211
 
        identifiable_format = weaverepo.RepositoryFormat7()
1212
 
        try:
1213
 
            found_transport = dir.get_repository_transport(anonymous_format)
1214
 
            self.assertRaises(errors.IncompatibleFormat,
1215
 
                              dir.get_repository_transport,
1216
 
                              identifiable_format)
1217
 
        except errors.IncompatibleFormat:
1218
 
            found_transport = dir.get_repository_transport(identifiable_format)
1219
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1220
 
        # and the dir which has been initialized for us must exist.
1221
 
        found_transport.list_dir('.')
1222
 
 
1223
 
    def test_get_workingtree_transport(self):
1224
 
        dir = self.make_bzrdir('.')
1225
 
        # without a format, get_workingtree_transport gives use a transport
1226
 
        # which -may- point to an existing dir.
1227
 
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1228
 
                                   transport.Transport))
1229
 
        # with a given format, either the bzr dir supports identifiable
1230
 
        # trees, or it supports anonymous tree formats, but not both.
1231
 
        anonymous_format = workingtree.WorkingTreeFormat2()
1232
 
        identifiable_format = workingtree.WorkingTreeFormat3()
1233
 
        try:
1234
 
            found_transport = dir.get_workingtree_transport(anonymous_format)
1235
 
            self.assertRaises(errors.IncompatibleFormat,
1236
 
                              dir.get_workingtree_transport,
1237
 
                              identifiable_format)
1238
 
        except errors.IncompatibleFormat:
1239
 
            found_transport = dir.get_workingtree_transport(identifiable_format)
1240
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1241
 
        # and the dir which has been initialized for us must exist.
1242
 
        found_transport.list_dir('.')
 
1315
        self.assertIsInstance(opened_tree, made_tree.__class__)
 
1316
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
 
1317
 
 
1318
    def test_get_selected_branch(self):
 
1319
        # The segment parameters are accessible from the root transport
 
1320
        # if a URL with segment parameters is opened.
 
1321
        if not self.bzrdir_format.is_initializable():
 
1322
            raise TestNotApplicable("format is not initializable")
 
1323
        t = self.get_transport()
 
1324
        try:
 
1325
            made_control = self.bzrdir_format.initialize(t.base)
 
1326
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
 
1327
            raise TestSkipped("Can't initialize %r on transport %r"
 
1328
                              % (self.bzrdir_format, t))
 
1329
        dir = bzrdir.BzrDir.open(t.base+",branch=foo")
 
1330
        self.assertEquals({"branch": "foo"},
 
1331
            dir.user_transport.get_segment_parameters())
 
1332
        self.assertEquals("foo", dir._get_selected_branch())
 
1333
 
 
1334
    def test_get_selected_branch_none_selected(self):
 
1335
        # _get_selected_branch defaults to None
 
1336
        if not self.bzrdir_format.is_initializable():
 
1337
            raise TestNotApplicable("format is not initializable")
 
1338
        t = self.get_transport()
 
1339
        try:
 
1340
            made_control = self.bzrdir_format.initialize(t.base)
 
1341
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
 
1342
            raise TestSkipped("Can't initialize %r on transport %r"
 
1343
                              % (self.bzrdir_format, t))
 
1344
        dir = bzrdir.BzrDir.open(t.base)
 
1345
        self.assertIs(None, dir._get_selected_branch())
1243
1346
 
1244
1347
    def test_root_transport(self):
1245
1348
        dir = self.make_bzrdir('.')
1246
1349
        self.assertEqual(dir.root_transport.base,
1247
 
                         transport.get_transport(self.get_url('.')).base)
 
1350
                         self.get_transport().base)
1248
1351
 
1249
1352
    def test_find_repository_no_repo_under_standalone_branch(self):
1250
1353
        # finding a repo stops at standalone branches even if there is a
1253
1356
            repo = self.make_repository('.', shared=True)
1254
1357
        except errors.IncompatibleFormat:
1255
1358
            # need a shared repository to test this.
1256
 
            return
 
1359
            raise TestNotApplicable("requires shared repository support")
 
1360
        if not repo._format.supports_nesting_repositories:
 
1361
            raise TestNotApplicable("requires nesting repositories")
1257
1362
        url = self.get_url('intermediate')
1258
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1259
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1363
        t = self.get_transport()
 
1364
        t.mkdir('intermediate')
 
1365
        t.mkdir('intermediate/child')
1260
1366
        made_control = self.bzrdir_format.initialize(url)
1261
1367
        made_control.create_repository()
1262
1368
        innermost_control = self.bzrdir_format.initialize(
1278
1384
            repo = self.make_repository('.', shared=True)
1279
1385
        except errors.IncompatibleFormat:
1280
1386
            # need a shared repository to test this.
1281
 
            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")
1282
1392
        url = self.get_url('childbzrdir')
1283
 
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
 
1393
        self.get_transport().mkdir('childbzrdir')
1284
1394
        made_control = self.bzrdir_format.initialize(url)
1285
1395
        try:
1286
1396
            child_repo = made_control.open_repository()
1294
1404
                         found_repo.bzrdir.root_transport.base)
1295
1405
 
1296
1406
    def test_find_repository_standalone_with_containing_shared_repository(self):
1297
 
        # 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
1298
1409
        try:
1299
1410
            containing_repo = self.make_repository('.', shared=True)
1300
1411
        except errors.IncompatibleFormat:
1301
1412
            # need a shared repository to test this.
1302
 
            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")
1303
1418
        child_repo = self.make_repository('childrepo')
1304
1419
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1305
1420
        found_repo = opened_control.find_repository()
1312
1427
            containing_repo = self.make_repository('.', shared=True)
1313
1428
        except errors.IncompatibleFormat:
1314
1429
            # need a shared repository to test this.
1315
 
            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")
1316
1435
        url = self.get_url('childrepo')
1317
 
        transport.get_transport(self.get_url()).mkdir('childrepo')
 
1436
        self.get_transport().mkdir('childrepo')
1318
1437
        child_control = self.bzrdir_format.initialize(url)
1319
1438
        child_repo = child_control.create_repository(shared=True)
1320
1439
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1331
1450
            repo = self.make_repository('.', shared=True)
1332
1451
        except errors.IncompatibleFormat:
1333
1452
            # need a shared repository to test this.
1334
 
            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")
1335
1458
        url = self.get_url('intermediate')
1336
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1337
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1459
        t = self.get_transport()
 
1460
        t.mkdir('intermediate')
 
1461
        t.mkdir('intermediate/child')
1338
1462
        made_control = self.bzrdir_format.initialize(url)
1339
1463
        try:
1340
1464
            child_repo = made_control.open_repository()
1364
1488
            # (we force the latest known format as downgrades may not be
1365
1489
            # available
1366
1490
            self.assertTrue(isinstance(dir._format.get_converter(
1367
 
                format=dir._format), bzrdir.Converter))
 
1491
                format=dir._format), controldir.Converter))
1368
1492
        dir.needs_format_conversion(
1369
1493
            controldir.ControlDirFormat.get_default_format())
1370
1494
 
1376
1500
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1377
1501
        old_path = urlutils.local_path_from_url(old_url)
1378
1502
        new_path = urlutils.local_path_from_url(new_url)
1379
 
        self.failUnlessExists(old_path)
1380
 
        self.failUnlessExists(new_path)
 
1503
        self.assertPathExists(old_path)
 
1504
        self.assertPathExists(new_path)
1381
1505
        for (((dir_relpath1, _), entries1),
1382
1506
             ((dir_relpath2, _), entries2)) in izip(
1383
1507
                osutils.walkdirs(old_path),
1411
1535
    def test_format_description(self):
1412
1536
        dir = self.make_bzrdir('.')
1413
1537
        text = dir._format.get_format_description()
1414
 
        self.failUnless(len(text))
 
1538
        self.assertTrue(len(text))
1415
1539
 
1416
1540
 
1417
1541
class TestBreakLock(TestCaseWithControlDir):
1434
1558
            # and thus this interaction cannot be tested at the interface
1435
1559
            # level.
1436
1560
            repo.unlock()
1437
 
            return
 
1561
            raise TestNotApplicable("format does not physically lock")
1438
1562
        # only one yes needed here: it should only be unlocking
1439
1563
        # the repo
1440
1564
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1443
1567
        except NotImplementedError:
1444
1568
            # this bzrdir does not implement break_lock - so we cant test it.
1445
1569
            repo.unlock()
1446
 
            return
 
1570
            raise TestNotApplicable("format does not support breaking locks")
1447
1571
        lock_repo.lock_write()
1448
1572
        lock_repo.unlock()
1449
1573
        self.assertRaises(errors.LockBroken, repo.unlock)
1460
1584
            bzrlib.branch.BranchReferenceFormat().initialize(
1461
1585
                thisdir, target_branch=master)
1462
1586
        except errors.IncompatibleFormat:
1463
 
            return
 
1587
            raise TestNotApplicable("format does not support "
 
1588
                "branch references")
1464
1589
        unused_repo = thisdir.create_repository()
1465
1590
        master.lock_write()
1466
1591
        unused_repo.lock_write()
1513
1638
            # raised a LockActive because we do still have a live locked
1514
1639
            # object.
1515
1640
            tree.unlock()
1516
 
            return
 
1641
            raise TestNotApplicable("format does not support breaking locks")
1517
1642
        self.assertEqual([True],
1518
1643
                bzrlib.ui.ui_factory.responses)
1519
1644
        lock_tree = tree.bzrdir.open_workingtree()
1549
1674
    def test_find_repository_no_repository(self):
1550
1675
        # loopback test to check the current format fails to find a
1551
1676
        # share repository correctly.
1552
 
        if not self.bzrdir_format.is_supported():
 
1677
        if not self.bzrdir_format.is_initializable():
1553
1678
            # unsupported formats are not loopback testable
1554
1679
            # because the default open will not open them and
1555
1680
            # they may not be initializable.
1556
 
            return
 
1681
            raise TestNotApplicable("format is not initializable")
1557
1682
        # supported formats must be able to init and open
1558
1683
        # - do the vfs initialisation over the basic vfs transport
1559
1684
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1560
1685
        url = self.get_vfs_only_url('subdir')
1561
 
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1686
        transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
1562
1687
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1563
1688
        try:
1564
1689
            repo = made_control.open_repository()