/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 16:40:42 UTC
  • mfrom: (6653.6.7 rename-controldir)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610164042-zrxqgy2htyduvke2
MergeĀ rename-controldirĀ branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
class TestControlDir(TestCaseWithControlDir):
54
54
 
55
 
    def skipIfNoWorkingTree(self, a_bzrdir):
56
 
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
 
55
    def skipIfNoWorkingTree(self, a_controldir):
 
56
        """Raises TestSkipped if a_controldir doesn't have a working tree.
57
57
 
58
58
        If the bzrdir does have a workingtree, this is a no-op.
59
59
        """
60
60
        try:
61
 
            a_bzrdir.open_workingtree()
 
61
            a_controldir.open_workingtree()
62
62
        except (errors.NotLocalUrl, errors.NoWorkingTree):
63
63
            raise TestSkipped("bzrdir on transport %r has no working tree"
64
 
                              % a_bzrdir.transport)
 
64
                              % a_controldir.transport)
65
65
 
66
 
    def openWorkingTreeIfLocal(self, a_bzrdir):
67
 
        """If a_bzrdir is on a local transport, call open_workingtree() on it.
 
66
    def openWorkingTreeIfLocal(self, a_controldir):
 
67
        """If a_controldir is on a local transport, call open_workingtree() on it.
68
68
        """
69
 
        if not isinstance(a_bzrdir.root_transport, LocalTransport):
 
69
        if not isinstance(a_controldir.root_transport, LocalTransport):
70
70
            # it's not local, but that's ok
71
71
            return
72
 
        a_bzrdir.open_workingtree()
 
72
        a_controldir.open_workingtree()
73
73
 
74
 
    def createWorkingTreeOrSkip(self, a_bzrdir):
75
 
        """Create a working tree on a_bzrdir, or raise TestSkipped.
 
74
    def createWorkingTreeOrSkip(self, a_controldir):
 
75
        """Create a working tree on a_controldir, or raise TestSkipped.
76
76
 
77
77
        A simple wrapper for create_workingtree that translates NotLocalUrl into
78
78
        TestSkipped.  Returns the newly created working tree.
79
79
        """
80
80
        try:
81
 
            return a_bzrdir.create_workingtree()
 
81
            return a_controldir.create_workingtree()
82
82
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
83
83
            raise TestSkipped("cannot make working tree with transport %r"
84
 
                              % a_bzrdir.transport)
 
84
                              % a_controldir.transport)
85
85
 
86
86
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
87
87
                     force_new_repo=False, accelerator_tree=None,
120
120
            self.bzrdir_format.initialize, '.')
121
121
 
122
122
    def test_create_null_workingtree(self):
123
 
        dir = self.make_bzrdir('dir1')
 
123
        dir = self.make_controldir('dir1')
124
124
        dir.create_repository()
125
125
        dir.create_branch()
126
126
        try:
135
135
        self.build_tree(['tree/file'])
136
136
        tree.add('file')
137
137
        tree.commit('first commit')
138
 
        bzrdir = tree.bzrdir
 
138
        bzrdir = tree.controldir
139
139
        try:
140
140
            bzrdir.destroy_workingtree()
141
141
        except errors.UnsupportedOperation:
150
150
 
151
151
    def test_destroy_branch(self):
152
152
        branch = self.make_branch('branch')
153
 
        bzrdir = branch.bzrdir
 
153
        bzrdir = branch.controldir
154
154
        try:
155
155
            bzrdir.destroy_branch()
156
156
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
161
161
 
162
162
    def test_destroy_branch_no_branch(self):
163
163
        branch = self.make_repository('branch')
164
 
        bzrdir = branch.bzrdir
 
164
        bzrdir = branch.controldir
165
165
        try:
166
166
            self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
167
167
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
169
169
 
170
170
    def test_destroy_repository(self):
171
171
        repo = self.make_repository('repository')
172
 
        bzrdir = repo.bzrdir
 
172
        bzrdir = repo.controldir
173
173
        try:
174
174
            bzrdir.destroy_repository()
175
175
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
185
185
        """ControlDir.open_workingtree() should raise NoWorkingTree (rather than
186
186
        e.g. NotLocalUrl) if there is no working tree.
187
187
        """
188
 
        dir = self.make_bzrdir('source')
 
188
        dir = self.make_controldir('source')
189
189
        vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
190
190
        if vfs_dir.has_workingtree():
191
191
            # This ControlDir format doesn't support ControlDirs without
196
196
 
197
197
    def test_clone_bzrdir_repository_under_shared(self):
198
198
        tree = self.make_branch_and_tree('commit_tree')
199
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
199
        self.build_tree(['foo'], transport=tree.controldir.transport.clone('..'))
200
200
        tree.add('foo')
201
201
        tree.commit('revision 1', rev_id='1')
202
 
        dir = self.make_bzrdir('source')
 
202
        dir = self.make_controldir('source')
203
203
        repo = dir.create_repository()
204
204
        if not repo._format.supports_nesting_repositories:
205
205
            raise TestNotApplicable("repository format does not support "
228
228
        # Make a branch, 'commit_tree', and working tree outside of the shared
229
229
        # repository, and commit some revisions to it.
230
230
        tree = self.make_branch_and_tree('commit_tree')
231
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
231
        self.build_tree(['foo'], transport=tree.controldir.root_transport)
232
232
        tree.add('foo')
233
233
        tree.commit('revision 1', rev_id='1')
234
 
        tree.bzrdir.open_branch().generate_revision_history(
 
234
        tree.controldir.open_branch().generate_revision_history(
235
235
            _mod_revision.NULL_REVISION)
236
236
        tree.set_parent_trees([])
237
237
        tree.commit('revision 2', rev_id='2')
239
239
        # repository into the shared repository.
240
240
        tree.branch.repository.copy_content_into(shared_repo)
241
241
        # Make a branch 'source' inside the shared repository.
242
 
        dir = self.make_bzrdir('shared/source')
 
242
        dir = self.make_controldir('shared/source')
243
243
        dir.create_branch()
244
244
        # Clone 'source' to 'target', also inside the shared repository.
245
245
        target = dir.clone(self.get_url('shared/target'))
246
246
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
247
247
        self.assertNotEqual(dir.transport.base, target.transport.base)
248
 
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
248
        self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
249
249
        # The shared repository will contain revisions from the 'commit_tree'
250
250
        # repository, even revisions that are not part of the history of the
251
251
        # 'commit_tree' branch.
264
264
        self.build_tree(['commit_tree/foo'])
265
265
        tree.add('foo')
266
266
        tree.commit('revision 1', rev_id='1')
267
 
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
267
        tree.branch.controldir.open_branch().generate_revision_history(
268
268
            _mod_revision.NULL_REVISION)
269
269
        tree.set_parent_trees([])
270
270
        tree.commit('revision 2', rev_id='2')
273
273
            shared_repo.set_make_working_trees(False)
274
274
            self.assertFalse(shared_repo.make_working_trees())
275
275
        self.assertTrue(shared_repo.has_revision('1'))
276
 
        dir = self.make_bzrdir('shared/source')
 
276
        dir = self.make_controldir('shared/source')
277
277
        dir.create_branch()
278
278
        target = dir.clone(self.get_url('target'))
279
279
        self.assertNotEqual(dir.transport.base, target.transport.base)
280
 
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
280
        self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
281
281
        branch = target.open_branch()
282
282
        self.assertTrue(branch.repository.has_revision('1'))
283
283
        self.assertFalse(branch.repository.make_working_trees())
292
292
        self.build_tree(['commit_tree/foo'])
293
293
        tree.add('foo')
294
294
        tree.commit('revision 1', rev_id='1')
295
 
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
295
        tree.branch.controldir.open_branch().generate_revision_history(
296
296
            _mod_revision.NULL_REVISION)
297
297
        tree.set_parent_trees([])
298
298
        tree.commit('revision 2', rev_id='2')
299
299
        source = self.make_repository('source')
300
300
        tree.branch.repository.copy_content_into(source)
301
 
        dir = source.bzrdir
 
301
        dir = source.controldir
302
302
        target = dir.clone(self.get_url('target'), revision_id='2')
303
303
        raise TestSkipped('revision limiting not strict yet')
304
304
 
340
340
        if not shared_repo._format.supports_nesting_repositories:
341
341
            raise TestNotApplicable("format does not support nesting "
342
342
                "repositories")
343
 
        dir = source.bzrdir
 
343
        dir = source.controldir
344
344
        target = dir.clone(self.get_url('target/child'))
345
345
        self.assertNotEqual(dir.transport.base, target.transport.base)
346
346
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
360
360
        source = self.make_branch('source')
361
361
        tree.branch.repository.copy_content_into(source.repository)
362
362
        tree.branch.copy_content_into(source)
363
 
        dir = source.bzrdir
 
363
        dir = source.controldir
364
364
        target = dir.clone(self.get_url('target'), revision_id='1')
365
365
        self.assertEqual('1', target.open_branch().last_revision())
366
366
 
367
367
    def test_clone_on_transport_preserves_repo_format(self):
368
 
        if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
 
368
        if self.bzrdir_format == controldir.format_registry.make_controldir('default'):
369
369
            format = 'knit'
370
370
        else:
371
371
            format = None
372
372
        source_branch = self.make_branch('source', format=format)
373
373
        # Ensure no format data is cached
374
374
        a_dir = breezy.branch.Branch.open_from_transport(
375
 
            self.get_transport('source')).bzrdir
 
375
            self.get_transport('source')).controldir
376
376
        target_transport = self.get_transport('target')
377
377
        target_bzrdir = a_dir.clone_on_transport(target_transport)
378
378
        target_repo = target_bzrdir.open_repository()
394
394
        tree.add('foo')
395
395
        tree.commit('revision 1', rev_id='1')
396
396
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
397
 
        dir = tree.bzrdir
 
397
        dir = tree.controldir
398
398
        target = dir.clone(self.get_url('target'), revision_id='1')
399
399
        self.skipIfNoWorkingTree(target)
400
400
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
414
414
            repo.set_make_working_trees(False)
415
415
            self.assertFalse(repo.make_working_trees())
416
416
 
417
 
        a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
 
417
        a_dir = tree.controldir.clone(self.get_url('repo/a'))
418
418
        a_branch = a_dir.open_branch()
419
419
        # If the new control dir actually uses the repository, it should
420
420
        # not have a working tree.
426
426
        branch = self.make_branch('parent')
427
427
        child_transport = self.get_transport('child')
428
428
        try:
429
 
            child = branch.bzrdir.clone_on_transport(child_transport,
 
429
            child = branch.controldir.clone_on_transport(child_transport,
430
430
                                                     stacked_on=branch.base)
431
431
        except (errors.UnstackableBranchFormat,
432
432
                errors.UnstackableRepositoryFormat):
437
437
    def test_set_branch_reference(self):
438
438
        """set_branch_reference creates a branch reference"""
439
439
        referenced_branch = self.make_branch('referenced')
440
 
        dir = self.make_bzrdir('source')
 
440
        dir = self.make_controldir('source')
441
441
        try:
442
442
            reference = dir.set_branch_reference(referenced_branch)
443
443
        except errors.IncompatibleFormat:
445
445
            raise TestNotApplicable("control directory does not "
446
446
                "support branch references")
447
447
        self.assertEqual(
448
 
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
448
            referenced_branch.controldir.root_transport.abspath('') + '/',
449
449
            dir.get_branch_reference())
450
450
 
451
451
    def test_set_branch_reference_on_existing_reference(self):
452
452
        """set_branch_reference creates a branch reference"""
453
453
        referenced_branch1 = self.make_branch('old-referenced')
454
454
        referenced_branch2 = self.make_branch('new-referenced')
455
 
        dir = self.make_bzrdir('source')
 
455
        dir = self.make_controldir('source')
456
456
        try:
457
457
            reference = dir.set_branch_reference(referenced_branch1)
458
458
        except errors.IncompatibleFormat:
461
461
                "support branch references")
462
462
        reference = dir.set_branch_reference(referenced_branch2)
463
463
        self.assertEqual(
464
 
            referenced_branch2.bzrdir.root_transport.abspath('') + '/',
 
464
            referenced_branch2.controldir.root_transport.abspath('') + '/',
465
465
            dir.get_branch_reference())
466
466
 
467
467
    def test_set_branch_reference_on_existing_branch(self):
468
468
        """set_branch_reference creates a branch reference"""
469
469
        referenced_branch = self.make_branch('referenced')
470
 
        dir = self.make_branch('source').bzrdir
 
470
        dir = self.make_branch('source').controldir
471
471
        try:
472
472
            reference = dir.set_branch_reference(referenced_branch)
473
473
        except errors.IncompatibleFormat:
475
475
            raise TestNotApplicable("control directory does not "
476
476
                "support branch references")
477
477
        self.assertEqual(
478
 
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
478
            referenced_branch.controldir.root_transport.abspath('') + '/',
479
479
            dir.get_branch_reference())
480
480
 
481
481
    def test_get_branch_reference_on_reference(self):
482
482
        """get_branch_reference should return the right url."""
483
483
        referenced_branch = self.make_branch('referenced')
484
 
        dir = self.make_bzrdir('source')
 
484
        dir = self.make_controldir('source')
485
485
        try:
486
486
            dir.set_branch_reference(referenced_branch)
487
487
        except errors.IncompatibleFormat:
488
488
            # this is ok too, not all formats have to support references.
489
489
            raise TestNotApplicable("control directory does not "
490
490
                "support branch references")
491
 
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
491
        self.assertEqual(referenced_branch.controldir.root_transport.abspath('') + '/',
492
492
            dir.get_branch_reference())
493
493
 
494
494
    def test_get_branch_reference_on_non_reference(self):
495
495
        """get_branch_reference should return None for non-reference branches."""
496
496
        branch = self.make_branch('referenced')
497
 
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
 
497
        self.assertEqual(None, branch.controldir.get_branch_reference())
498
498
 
499
499
    def test_get_branch_reference_no_branch(self):
500
500
        """get_branch_reference should not mask NotBranchErrors."""
501
 
        dir = self.make_bzrdir('source')
 
501
        dir = self.make_controldir('source')
502
502
        if dir.has_branch():
503
503
            # this format does not support branchless bzrdirs.
504
504
            raise TestNotApplicable("format does not support "
506
506
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
507
507
 
508
508
    def test_sprout_bzrdir_empty(self):
509
 
        dir = self.make_bzrdir('source')
 
509
        dir = self.make_controldir('source')
510
510
        target = dir.sprout(self.get_url('target'))
511
511
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
512
512
        # creates a new repository branch and tree
516
516
 
517
517
    def test_sprout_bzrdir_empty_under_shared_repo(self):
518
518
        # sprouting an empty dir into a repo uses the repo
519
 
        dir = self.make_bzrdir('source')
 
519
        dir = self.make_controldir('source')
520
520
        try:
521
521
            self.make_repository('target', shared=True)
522
522
        except errors.IncompatibleFormat:
530
530
        except errors.NoWorkingTree:
531
531
            # Some bzrdirs can never have working trees.
532
532
            repo = target.find_repository()
533
 
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
 
533
            self.assertFalse(repo.controldir._format.supports_workingtrees)
534
534
 
535
535
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
536
536
        # the force_new_repo parameter should force use of a new repo in an empty
537
537
        # bzrdir's sprout logic
538
 
        dir = self.make_bzrdir('source')
 
538
        dir = self.make_controldir('source')
539
539
        try:
540
540
            self.make_repository('target', shared=True)
541
541
        except errors.IncompatibleFormat:
551
551
        self.build_tree(['commit_tree/foo'])
552
552
        tree.add('foo')
553
553
        tree.commit('revision 1', rev_id='1')
554
 
        tree.bzrdir.open_branch().generate_revision_history(
 
554
        tree.controldir.open_branch().generate_revision_history(
555
555
            _mod_revision.NULL_REVISION)
556
556
        tree.set_parent_trees([])
557
557
        tree.commit('revision 2', rev_id='2')
558
558
        source = self.make_repository('source')
559
559
        tree.branch.repository.copy_content_into(source)
560
 
        dir = source.bzrdir
 
560
        dir = source.controldir
561
561
        try:
562
562
            shared_repo = self.make_repository('target', shared=True)
563
563
        except errors.IncompatibleFormat:
580
580
        self.build_tree(['commit_tree/foo'])
581
581
        tree.add('foo')
582
582
        tree.commit('revision 1', rev_id='1')
583
 
        tree.bzrdir.open_branch().generate_revision_history(
 
583
        tree.controldir.open_branch().generate_revision_history(
584
584
            _mod_revision.NULL_REVISION)
585
585
        tree.set_parent_trees([])
586
586
        tree.commit('revision 2', rev_id='2')
587
587
        tree.branch.repository.copy_content_into(shared_repo)
588
 
        dir = self.make_bzrdir('shared/source')
 
588
        dir = self.make_controldir('shared/source')
589
589
        dir.create_branch()
590
590
        target = dir.sprout(self.get_url('shared/target'))
591
591
        self.assertNotEqual(dir.transport.base, target.transport.base)
592
 
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
592
        self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
593
593
        self.assertTrue(shared_repo.has_revision('1'))
594
594
 
595
595
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
605
605
        self.build_tree(['commit_tree/foo'])
606
606
        tree.add('foo')
607
607
        tree.commit('revision 1', rev_id='1')
608
 
        tree.bzrdir.open_branch().generate_revision_history(
 
608
        tree.controldir.open_branch().generate_revision_history(
609
609
            _mod_revision.NULL_REVISION)
610
610
        tree.set_parent_trees([])
611
611
        tree.commit('revision 2', rev_id='2')
614
614
            shared_repo.set_make_working_trees(False)
615
615
            self.assertFalse(shared_repo.make_working_trees())
616
616
        self.assertTrue(shared_repo.has_revision('1'))
617
 
        dir = self.make_bzrdir('shared/source')
 
617
        dir = self.make_controldir('shared/source')
618
618
        dir.create_branch()
619
619
        target = dir.sprout(self.get_url('target'))
620
620
        self.assertNotEqual(dir.transport.base, target.transport.base)
621
 
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
621
        self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
622
622
        branch = target.open_branch()
623
623
        # The sprouted bzrdir has a branch, so only revisions referenced by
624
624
        # that branch are copied, rather than the whole repository.  It's an
625
625
        # empty branch, so none are copied.
626
626
        self.assertEqual([], branch.repository.all_revision_ids())
627
 
        if branch.bzrdir._format.supports_workingtrees:
 
627
        if branch.controldir._format.supports_workingtrees:
628
628
            self.assertTrue(branch.repository.make_working_trees())
629
629
        self.assertFalse(branch.repository.is_shared())
630
630
 
633
633
        self.build_tree(['commit_tree/foo'])
634
634
        tree.add('foo')
635
635
        tree.commit('revision 1', rev_id='1')
636
 
        tree.bzrdir.open_branch().generate_revision_history(
 
636
        tree.controldir.open_branch().generate_revision_history(
637
637
            _mod_revision.NULL_REVISION)
638
638
        tree.set_parent_trees([])
639
639
        tree.commit('revision 2', rev_id='2')
640
640
        source = self.make_repository('source')
641
641
        tree.branch.repository.copy_content_into(source)
642
 
        dir = source.bzrdir
 
642
        dir = source.controldir
643
643
        try:
644
644
            shared_repo = self.make_repository('target', shared=True)
645
645
        except errors.IncompatibleFormat:
660
660
        self.build_tree(['commit_tree/foo'])
661
661
        tree.add('foo')
662
662
        tree.commit('revision 1', rev_id='1')
663
 
        br = tree.bzrdir.open_branch()
 
663
        br = tree.controldir.open_branch()
664
664
        br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
665
665
        tree.set_parent_trees([])
666
666
        tree.commit('revision 2', rev_id='2')
667
667
        source = self.make_repository('source')
668
668
        tree.branch.repository.copy_content_into(source)
669
 
        dir = source.bzrdir
 
669
        dir = source.controldir
670
670
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
671
671
        raise TestSkipped('revision limiting not strict yet')
672
672
 
679
679
        tree.commit('revision 1', rev_id='1')
680
680
        source = self.make_branch('source')
681
681
        tree.branch.repository.copy_content_into(source.repository)
682
 
        tree.bzrdir.open_branch().copy_content_into(source)
683
 
        dir = source.bzrdir
 
682
        tree.controldir.open_branch().copy_content_into(source)
 
683
        dir = source.controldir
684
684
        try:
685
685
            shared_repo = self.make_repository('target', shared=True)
686
686
        except errors.IncompatibleFormat:
698
698
        tree.commit('revision 1', rev_id='1')
699
699
        source = self.make_branch('source')
700
700
        tree.branch.repository.copy_content_into(source.repository)
701
 
        tree.bzrdir.open_branch().copy_content_into(source)
702
 
        dir = source.bzrdir
 
701
        tree.controldir.open_branch().copy_content_into(source)
 
702
        dir = source.controldir
703
703
        try:
704
704
            shared_repo = self.make_repository('target', shared=True)
705
705
        except errors.IncompatibleFormat:
712
712
    def test_sprout_bzrdir_branch_reference(self):
713
713
        # sprouting should create a repository if needed and a sprouted branch.
714
714
        referenced_branch = self.make_branch('referenced')
715
 
        dir = self.make_bzrdir('source')
 
715
        dir = self.make_controldir('source')
716
716
        try:
717
717
            dir.set_branch_reference(referenced_branch)
718
718
        except errors.IncompatibleFormat:
722
722
        target = dir.sprout(self.get_url('target'))
723
723
        self.assertNotEqual(dir.transport.base, target.transport.base)
724
724
        # we want target to have a branch that is in-place.
725
 
        self.assertEqual(target, target.open_branch().bzrdir)
 
725
        self.assertEqual(target, target.open_branch().controldir)
726
726
        # and as we dont support repositories being detached yet, a repo in
727
727
        # place
728
728
        target.open_repository()
731
731
        # sprouting should create a repository if needed and a sprouted branch.
732
732
        referenced_tree = self.make_branch_and_tree('referenced')
733
733
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
734
 
        dir = self.make_bzrdir('source')
 
734
        dir = self.make_controldir('source')
735
735
        try:
736
736
            dir.set_branch_reference(referenced_tree.branch)
737
737
        except errors.IncompatibleFormat:
746
746
        target = dir.sprout(self.get_url('target/child'))
747
747
        self.assertNotEqual(dir.transport.base, target.transport.base)
748
748
        # we want target to have a branch that is in-place.
749
 
        self.assertEqual(target, target.open_branch().bzrdir)
 
749
        self.assertEqual(target, target.open_branch().controldir)
750
750
        # and we want no repository as the target is shared
751
751
        self.assertRaises(errors.NoRepositoryPresent,
752
752
                          target.open_repository)
757
757
        # sprouting should create a repository if needed and a sprouted branch.
758
758
        referenced_tree = self.make_branch_and_tree('referenced')
759
759
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
760
 
        dir = self.make_bzrdir('source')
 
760
        dir = self.make_controldir('source')
761
761
        try:
762
762
            dir.set_branch_reference(referenced_tree.branch)
763
763
        except errors.IncompatibleFormat:
773
773
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
774
774
        self.assertNotEqual(dir.transport.base, target.transport.base)
775
775
        # we want target to have a branch that is in-place.
776
 
        self.assertEqual(target, target.open_branch().bzrdir)
 
776
        self.assertEqual(target, target.open_branch().controldir)
777
777
        # and we want revision '1' in the new repo
778
778
        self.assertTrue(target.open_repository().has_revision('1'))
779
779
        # but not the shared one
791
791
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
792
792
        source = self.make_branch('source')
793
793
        tree.branch.repository.copy_content_into(source.repository)
794
 
        tree.bzrdir.open_branch().copy_content_into(source)
795
 
        dir = source.bzrdir
 
794
        tree.controldir.open_branch().copy_content_into(source)
 
795
        dir = source.controldir
796
796
        target = dir.sprout(self.get_url('target'), revision_id='1')
797
797
        self.assertEqual('1', target.open_branch().last_revision())
798
798
 
807
807
            raise TestNotApplicable('Branch format does not support tags.')
808
808
        source.get_config_stack().set('branch.fetch_tags', True)
809
809
        # Now source has a tag not in its ancestry.  Sprout its controldir.
810
 
        dir = source.bzrdir
 
810
        dir = source.controldir
811
811
        target = dir.sprout(self.get_url('target'))
812
812
        # The tag is present, and so is its revision.
813
813
        new_branch = target.open_branch()
827
827
                'or tags referencing ghost revisions.')
828
828
        # Now source has a tag pointing to an absent revision.  Sprout its
829
829
        # controldir.
830
 
        dir = source.bzrdir
 
830
        dir = source.controldir
831
831
        target = dir.sprout(self.get_url('target'))
832
832
        # The tag is present in the target
833
833
        new_branch = target.open_branch()
846
846
                'or tags referencing missing revisions.')
847
847
        # Now source has a tag pointing to an absent revision.  Sprout its
848
848
        # controldir.
849
 
        dir = source.bzrdir
 
849
        dir = source.controldir
850
850
        target = dir.sprout(self.get_url('target'), source_branch=source)
851
851
        # The tag is present in the target
852
852
        new_branch = target.open_branch()
886
886
            has_ghost_tag = True
887
887
        source.get_config_stack().set('branch.fetch_tags', True)
888
888
        # And ask sprout for C2
889
 
        dir = source.bzrdir
 
889
        dir = source.controldir
890
890
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
891
891
        # The tags are present
892
892
        new_branch = target.open_branch()
908
908
        # sprouting should create a repository if needed and a sprouted branch.
909
909
        # the tree state should not be copied.
910
910
        referenced_branch = self.make_branch('referencced')
911
 
        dir = self.make_bzrdir('source')
 
911
        dir = self.make_controldir('source')
912
912
        try:
913
913
            dir.set_branch_reference(referenced_branch)
914
914
        except errors.IncompatibleFormat:
922
922
        target = dir.sprout(self.get_url('target'))
923
923
        self.assertNotEqual(dir.transport.base, target.transport.base)
924
924
        # we want target to have a branch that is in-place.
925
 
        self.assertEqual(target, target.open_branch().bzrdir)
 
925
        self.assertEqual(target, target.open_branch().controldir)
926
926
        # and as we dont support repositories being detached yet, a repo in
927
927
        # place
928
928
        target.open_repository()
934
934
        # the tree state should not be copied but the revision changed,
935
935
        # and the likewise the new branch should be truncated too
936
936
        referenced_branch = self.make_branch('referencced')
937
 
        dir = self.make_bzrdir('source')
 
937
        dir = self.make_controldir('source')
938
938
        try:
939
939
            dir.set_branch_reference(referenced_branch)
940
940
        except errors.IncompatibleFormat:
951
951
        self.skipIfNoWorkingTree(target)
952
952
        self.assertNotEqual(dir.transport.base, target.transport.base)
953
953
        # we want target to have a branch that is in-place.
954
 
        self.assertEqual(target, target.open_branch().bzrdir)
 
954
        self.assertEqual(target, target.open_branch().controldir)
955
955
        # and as we dont support repositories being detached yet, a repo in
956
956
        # place
957
957
        target.open_repository()
970
970
        tree.add('foo')
971
971
        tree.commit('revision 1', rev_id='1')
972
972
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
973
 
        dir = tree.bzrdir
 
973
        dir = tree.controldir
974
974
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
975
975
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
976
976
 
980
980
        tree.add('foo')
981
981
        tree.commit('revision 1', rev_id='1')
982
982
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
983
 
        dir = tree.bzrdir
 
983
        dir = tree.controldir
984
984
        target = self.sproutOrSkip(dir, self.get_url('target'),
985
985
                                   accelerator_tree=tree)
986
986
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
991
991
        tree.add('foo')
992
992
        tree.commit('revision 1', rev_id='1')
993
993
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
994
 
        dir = tree.bzrdir
 
994
        dir = tree.controldir
995
995
        try:
996
996
            target = dir.sprout(self.get_url('target'),
997
997
                create_tree_if_local=False)
1011
1011
        builder.finish_series()
1012
1012
        stack_on = builder.get_branch()
1013
1013
        # Make a bzrdir with a default stacking policy to stack on that branch.
1014
 
        config = self.make_bzrdir('policy-dir').get_config()
 
1014
        config = self.make_controldir('policy-dir').get_config()
1015
1015
        try:
1016
1016
            config.set_default_stack_on(self.get_url('stack-on'))
1017
1017
        except errors.BzrError:
1018
1018
            raise TestNotApplicable('Only relevant for stackable formats.')
1019
1019
        # Sprout the stacked-on branch into the bzrdir.
1020
 
        sprouted = stack_on.bzrdir.sprout(
 
1020
        sprouted = stack_on.controldir.sprout(
1021
1021
            self.get_url('policy-dir/sprouted'), revision_id='rev-3')
1022
1022
        # Not all revisions are copied into the sprouted repository.
1023
1023
        repo = sprouted.open_repository()
1086
1086
 
1087
1087
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1088
1088
        t = self.get_transport('repo')
1089
 
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
 
1089
        repo_fmt = controldir.format_registry.make_controldir('1.9')
1090
1090
        repo_name = repo_fmt.repository_format.network_name()
1091
1091
        repo = repo_fmt.initialize_on_transport_ex(t,
1092
1092
            repo_format_name=repo_name, shared_repo=True)[0]
1093
1093
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1094
1094
            force_new_repo=True, repo_format_name=repo_name)
1095
 
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1096
 
            made_repo.bzrdir.root_transport.base)
 
1095
        self.assertNotEqual(repo.controldir.root_transport.base,
 
1096
            made_repo.controldir.root_transport.base)
1097
1097
 
1098
1098
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1099
1099
        t = self.get_transport('repo')
1100
 
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
 
1100
        repo_fmt = controldir.format_registry.make_controldir('1.9')
1101
1101
        repo_name = repo_fmt.repository_format.network_name()
1102
1102
        repo = repo_fmt.initialize_on_transport_ex(t,
1103
1103
            repo_format_name=repo_name, shared_repo=True)[0]
1104
1104
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1105
1105
            force_new_repo=False, repo_format_name=repo_name)
1106
1106
        if not control._format.fixed_components:
1107
 
            self.assertEqual(repo.bzrdir.root_transport.base,
1108
 
                made_repo.bzrdir.root_transport.base)
 
1107
            self.assertEqual(repo.controldir.root_transport.base,
 
1108
                made_repo.controldir.root_transport.base)
1109
1109
 
1110
1110
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1111
1111
        t = self.get_transport('dir')
1115
1115
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1116
1116
        t = self.get_transport('dir')
1117
1117
        # 1.6 is likely to never be default
1118
 
        fmt = controldir.format_registry.make_bzrdir('1.6')
 
1118
        fmt = controldir.format_registry.make_controldir('1.6')
1119
1119
        repo_name = fmt.repository_format.network_name()
1120
1120
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1121
1121
        if self.bzrdir_format.fixed_components:
1156
1156
 
1157
1157
    def test_format_network_name(self):
1158
1158
        # All control formats must have a network name.
1159
 
        dir = self.make_bzrdir('.')
 
1159
        dir = self.make_controldir('.')
1160
1160
        format = dir._format
1161
1161
        # We want to test that the network_name matches the actual format on
1162
1162
        # disk. For local control dirsthat means that using network_name as a
1195
1195
        made_repo = made_control.create_repository()
1196
1196
        made_branch = made_control.create_branch()
1197
1197
        self.assertIsInstance(made_branch, breezy.branch.Branch)
1198
 
        self.assertEqual(made_control, made_branch.bzrdir)
 
1198
        self.assertEqual(made_control, made_branch.controldir)
1199
1199
 
1200
1200
    def test_create_branch_append_revisions_only(self):
1201
1201
        # a bzrdir can construct a branch and repository for itself.
1215
1215
                "append_revisions_only setting")
1216
1216
        self.assertIsInstance(made_branch, breezy.branch.Branch)
1217
1217
        self.assertEqual(True, made_branch.get_append_revisions_only())
1218
 
        self.assertEqual(made_control, made_branch.bzrdir)
 
1218
        self.assertEqual(made_control, made_branch.controldir)
1219
1219
 
1220
1220
    def test_open_branch(self):
1221
1221
        if not self.bzrdir_format.is_initializable():
1228
1228
        made_repo = made_control.create_repository()
1229
1229
        made_branch = made_control.create_branch()
1230
1230
        opened_branch = made_control.open_branch()
1231
 
        self.assertEqual(made_control, opened_branch.bzrdir)
 
1231
        self.assertEqual(made_control, opened_branch.controldir)
1232
1232
        self.assertIsInstance(opened_branch, made_branch.__class__)
1233
1233
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1234
1234
 
1251
1251
 
1252
1252
    def test_get_branches(self):
1253
1253
        repo = self.make_repository('branch-1')
1254
 
        target_branch = repo.bzrdir.create_branch()
1255
 
        self.assertEqual([""], list(repo.bzrdir.get_branches()))
 
1254
        target_branch = repo.controldir.create_branch()
 
1255
        self.assertEqual([""], list(repo.controldir.get_branches()))
1256
1256
 
1257
1257
    def test_create_repository(self):
1258
1258
        # a bzrdir can construct a repository for itself.
1266
1266
        made_repo = made_control.create_repository()
1267
1267
        # Check that we have a repository object.
1268
1268
        made_repo.has_revision('foo')
1269
 
        self.assertEqual(made_control, made_repo.bzrdir)
 
1269
        self.assertEqual(made_control, made_repo.controldir)
1270
1270
 
1271
1271
    def test_create_repository_shared(self):
1272
1272
        # a bzrdir can create a shared repository or
1315
1315
        made_control = self.bzrdir_format.initialize(t.base)
1316
1316
        made_repo = made_control.create_repository()
1317
1317
        opened_repo = made_control.open_repository()
1318
 
        self.assertEqual(made_control, opened_repo.bzrdir)
 
1318
        self.assertEqual(made_control, opened_repo.controldir)
1319
1319
        self.assertIsInstance(opened_repo, made_repo.__class__)
1320
1320
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1321
1321
 
1332
1332
        made_branch = made_control.create_branch()
1333
1333
        made_tree = self.createWorkingTreeOrSkip(made_control)
1334
1334
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
1335
 
        self.assertEqual(made_control, made_tree.bzrdir)
 
1335
        self.assertEqual(made_control, made_tree.controldir)
1336
1336
 
1337
1337
    def test_create_workingtree_revision(self):
1338
1338
        # a bzrdir can construct a working tree for itself @ a specific revision.
1368
1368
            raise TestSkipped("Can't initialize %r on transport %r"
1369
1369
                              % (self.bzrdir_format, t))
1370
1370
        opened_tree = made_control.open_workingtree()
1371
 
        self.assertEqual(made_control, opened_tree.bzrdir)
 
1371
        self.assertEqual(made_control, opened_tree.controldir)
1372
1372
        self.assertIsInstance(opened_tree, made_tree.__class__)
1373
1373
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1374
1374
 
1402
1402
        self.assertEqual(u"", dir._get_selected_branch())
1403
1403
 
1404
1404
    def test_root_transport(self):
1405
 
        dir = self.make_bzrdir('.')
 
1405
        dir = self.make_controldir('.')
1406
1406
        self.assertEqual(dir.root_transport.base,
1407
1407
                         self.get_transport().base)
1408
1408
 
1457
1457
        except errors.NoRepositoryPresent:
1458
1458
            pass
1459
1459
        found_repo = made_control.find_repository()
1460
 
        self.assertEqual(repo.bzrdir.root_transport.base,
1461
 
                         found_repo.bzrdir.root_transport.base)
 
1460
        self.assertEqual(repo.controldir.root_transport.base,
 
1461
                         found_repo.controldir.root_transport.base)
1462
1462
 
1463
1463
    def test_find_repository_standalone_with_containing_shared_repository(self):
1464
1464
        # find repo inside a standalone repo inside a shared repo finds the
1475
1475
        child_repo = self.make_repository('childrepo')
1476
1476
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1477
1477
        found_repo = opened_control.find_repository()
1478
 
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1479
 
                         found_repo.bzrdir.root_transport.base)
 
1478
        self.assertEqual(child_repo.controldir.root_transport.base,
 
1479
                         found_repo.controldir.root_transport.base)
1480
1480
 
1481
1481
    def test_find_repository_shared_within_shared_repository(self):
1482
1482
        # find repo at a shared repo inside a shared repo finds the inner repo
1495
1495
        child_repo = child_control.create_repository(shared=True)
1496
1496
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1497
1497
        found_repo = opened_control.find_repository()
1498
 
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1499
 
                         found_repo.bzrdir.root_transport.base)
1500
 
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1501
 
                            containing_repo.bzrdir.root_transport.base)
 
1498
        self.assertEqual(child_repo.controldir.root_transport.base,
 
1499
                         found_repo.controldir.root_transport.base)
 
1500
        self.assertNotEqual(child_repo.controldir.root_transport.base,
 
1501
                            containing_repo.controldir.root_transport.base)
1502
1502
 
1503
1503
    def test_find_repository_with_nested_dirs_works(self):
1504
1504
        # find repo inside a bzrdir inside a bzrdir inside a shared repo
1534
1534
        except errors.NoRepositoryPresent:
1535
1535
            pass
1536
1536
        found_repo = innermost_control.find_repository()
1537
 
        self.assertEqual(repo.bzrdir.root_transport.base,
1538
 
                         found_repo.bzrdir.root_transport.base)
 
1537
        self.assertEqual(repo.controldir.root_transport.base,
 
1538
                         found_repo.controldir.root_transport.base)
1539
1539
 
1540
1540
    def test_can_and_needs_format_conversion(self):
1541
1541
        # check that we can ask an instance if its upgradable
1542
 
        dir = self.make_bzrdir('.')
 
1542
        dir = self.make_controldir('.')
1543
1543
        if dir.can_convert_format():
1544
1544
            # if its default updatable there must be an updater
1545
1545
            # (we force the latest known format as downgrades may not be
1554
1554
        self.build_tree(['test/a'])
1555
1555
        tree.add(['a'], ['a-id'])
1556
1556
        tree.commit('some data to be copied.')
1557
 
        old_url, new_url = tree.bzrdir.backup_bzrdir()
 
1557
        old_url, new_url = tree.controldir.backup_bzrdir()
1558
1558
        old_path = urlutils.local_path_from_url(old_url)
1559
1559
        new_path = urlutils.local_path_from_url(new_url)
1560
1560
        self.assertPathExists(old_path)
1572
1572
 
1573
1573
    def test_upgrade_new_instance(self):
1574
1574
        """Does an available updater work?"""
1575
 
        dir = self.make_bzrdir('.')
 
1575
        dir = self.make_controldir('.')
1576
1576
        # for now, upgrade is not ready for partial bzrdirs.
1577
1577
        dir.create_repository()
1578
1578
        dir.create_branch()
1590
1590
            check.check_dwim(self.get_url('.'), False, True, True)
1591
1591
 
1592
1592
    def test_format_description(self):
1593
 
        dir = self.make_bzrdir('.')
 
1593
        dir = self.make_controldir('.')
1594
1594
        text = dir._format.get_format_description()
1595
1595
        self.assertTrue(len(text))
1596
1596
 
1599
1599
 
1600
1600
    def test_break_lock_empty(self):
1601
1601
        # break lock on an empty bzrdir should work silently.
1602
 
        dir = self.make_bzrdir('.')
 
1602
        dir = self.make_controldir('.')
1603
1603
        try:
1604
1604
            dir.break_lock()
1605
1605
        except NotImplementedError:
1609
1609
        # break lock with just a repo should unlock the repo.
1610
1610
        repo = self.make_repository('.')
1611
1611
        repo.lock_write()
1612
 
        lock_repo = repo.bzrdir.open_repository()
 
1612
        lock_repo = repo.controldir.open_repository()
1613
1613
        if not lock_repo.get_physical_lock_status():
1614
1614
            # This bzrdir's default repository does not physically lock things
1615
1615
            # and thus this interaction cannot be tested at the interface
1620
1620
        # the repo
1621
1621
        breezy.ui.ui_factory = CannedInputUIFactory([True])
1622
1622
        try:
1623
 
            repo.bzrdir.break_lock()
 
1623
            repo.controldir.break_lock()
1624
1624
        except NotImplementedError:
1625
1625
            # this bzrdir does not implement break_lock - so we cant test it.
1626
1626
            repo.unlock()
1636
1636
        # and repository in another bzrdir
1637
1637
        # for pre-metadir formats this will fail, thats ok.
1638
1638
        master = self.make_branch('branch')
1639
 
        thisdir = self.make_bzrdir('this')
 
1639
        thisdir = self.make_controldir('this')
1640
1640
        try:
1641
1641
            thisdir.set_branch_reference(master)
1642
1642
        except errors.IncompatibleFormat:
1653
1653
            # determine if the repository will have been locked;
1654
1654
            this_repo_locked = \
1655
1655
                thisdir.open_repository().get_physical_lock_status()
1656
 
            master.bzrdir.break_lock()
 
1656
            master.controldir.break_lock()
1657
1657
            if this_repo_locked:
1658
1658
                # only two ys should have been read
1659
1659
                self.assertEqual([True],
1663
1663
                self.assertEqual([True, True],
1664
1664
                    breezy.ui.ui_factory.responses)
1665
1665
            # we should be able to lock a newly opened branch now
1666
 
            branch = master.bzrdir.open_branch()
 
1666
            branch = master.controldir.open_branch()
1667
1667
            branch.lock_write()
1668
1668
            branch.unlock()
1669
1669
            if this_repo_locked:
1687
1687
        # three yes's : tree, branch and repository.
1688
1688
        breezy.ui.ui_factory = CannedInputUIFactory([True, True, True])
1689
1689
        try:
1690
 
            tree.bzrdir.break_lock()
 
1690
            tree.controldir.break_lock()
1691
1691
        except (NotImplementedError, errors.LockActive):
1692
1692
            # bzrdir does not support break_lock
1693
1693
            # or one of the locked objects (currently only tree does this)
1697
1697
            raise TestNotApplicable("format does not support breaking locks")
1698
1698
        self.assertEqual([True],
1699
1699
                breezy.ui.ui_factory.responses)
1700
 
        lock_tree = tree.bzrdir.open_workingtree()
 
1700
        lock_tree = tree.controldir.open_workingtree()
1701
1701
        lock_tree.lock_write()
1702
1702
        lock_tree.unlock()
1703
1703
        self.assertRaises(errors.LockBroken, tree.unlock)
1706
1706
class TestTransportConfig(TestCaseWithControlDir):
1707
1707
 
1708
1708
    def test_get_config(self):
1709
 
        my_dir = self.make_bzrdir('.')
 
1709
        my_dir = self.make_controldir('.')
1710
1710
        config = my_dir.get_config()
1711
1711
        try:
1712
1712
            config.set_default_stack_on('http://example.com')
1757
1757
    """ControlDir implementations adequately implement ControlComponent."""
1758
1758
 
1759
1759
    def test_urls(self):
1760
 
        bd = self.make_bzrdir('bd')
 
1760
        bd = self.make_controldir('bd')
1761
1761
        self.assertIsInstance(bd.user_url, str)
1762
1762
        self.assertEqual(bd.user_url, bd.user_transport.base)
1763
1763
        # for all current bzrdir implementations the user dir must be