~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
import bzrlib.branch
22
22
from bzrlib import (
23
 
    bzrdir,
 
23
    bzrdir as _mod_bzrdir,
24
24
    check,
25
25
    controldir,
26
26
    errors,
27
27
    gpg,
28
28
    osutils,
 
29
    revision as _mod_revision,
29
30
    transport,
30
31
    ui,
31
32
    urlutils,
32
33
    workingtree,
33
34
    )
34
 
import bzrlib.revision
35
35
from bzrlib.tests import (
36
36
    fixtures,
37
37
    ChrootedTestCase,
108
108
        self.assertRaises(errors.UninitializableFormat,
109
109
            self.bzrdir_format.initialize, t.base)
110
110
 
 
111
    def test_multiple_initialization(self):
 
112
        # loopback test to check the current format initializes to itself.
 
113
        if not self.bzrdir_format.is_initializable():
 
114
            # unsupported formats are not loopback testable
 
115
            # because the default open will not open them and
 
116
            # they may not be initializable.
 
117
            raise TestNotApplicable("format is not initializable")
 
118
        self.bzrdir_format.initialize('.')
 
119
        self.assertRaises(errors.AlreadyControlDirError,
 
120
            self.bzrdir_format.initialize, '.')
 
121
 
111
122
    def test_create_null_workingtree(self):
112
123
        dir = self.make_bzrdir('dir1')
113
124
        dir.create_repository()
114
125
        dir.create_branch()
115
126
        try:
116
 
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
127
            wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
117
128
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
118
129
            raise TestSkipped("cannot make working tree with transport %r"
119
130
                              % dir.transport)
148
159
        bzrdir.create_branch()
149
160
        bzrdir.open_branch()
150
161
 
 
162
    def test_destroy_branch_no_branch(self):
 
163
        branch = self.make_repository('branch')
 
164
        bzrdir = branch.bzrdir
 
165
        try:
 
166
            self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
 
167
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
 
168
            raise TestNotApplicable('Format does not support destroying branch')
 
169
 
151
170
    def test_destroy_repository(self):
152
171
        repo = self.make_repository('repository')
153
172
        bzrdir = repo.bzrdir
156
175
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
157
176
            raise TestNotApplicable('Format does not support destroying'
158
177
                                    ' repository')
 
178
        self.assertRaises(errors.NoRepositoryPresent,
 
179
            bzrdir.destroy_repository)
159
180
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
160
181
        bzrdir.create_repository()
161
182
        bzrdir.open_repository()
165
186
        e.g. NotLocalUrl) if there is no working tree.
166
187
        """
167
188
        dir = self.make_bzrdir('source')
168
 
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
 
189
        vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
169
190
        if vfs_dir.has_workingtree():
170
191
            # This ControlDir format doesn't support ControlDirs without
171
192
            # working trees, so this test is irrelevant.
211
232
        tree.add('foo')
212
233
        tree.commit('revision 1', rev_id='1')
213
234
        tree.bzrdir.open_branch().generate_revision_history(
214
 
            bzrlib.revision.NULL_REVISION)
 
235
            _mod_revision.NULL_REVISION)
215
236
        tree.set_parent_trees([])
216
237
        tree.commit('revision 2', rev_id='2')
217
238
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
244
265
        tree.add('foo')
245
266
        tree.commit('revision 1', rev_id='1')
246
267
        tree.branch.bzrdir.open_branch().generate_revision_history(
247
 
            bzrlib.revision.NULL_REVISION)
 
268
            _mod_revision.NULL_REVISION)
248
269
        tree.set_parent_trees([])
249
270
        tree.commit('revision 2', rev_id='2')
250
271
        tree.branch.repository.copy_content_into(shared_repo)
272
293
        tree.add('foo')
273
294
        tree.commit('revision 1', rev_id='1')
274
295
        tree.branch.bzrdir.open_branch().generate_revision_history(
275
 
            bzrlib.revision.NULL_REVISION)
 
296
            _mod_revision.NULL_REVISION)
276
297
        tree.set_parent_trees([])
277
298
        tree.commit('revision 2', rev_id='2')
278
299
        source = self.make_repository('source')
323
344
        target = dir.clone(self.get_url('target/child'))
324
345
        self.assertNotEqual(dir.transport.base, target.transport.base)
325
346
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
326
 
        self.assertEqual(source.revision_history(),
327
 
                         target.open_branch().revision_history())
 
347
        self.assertEqual(source.last_revision(),
 
348
                         target.open_branch().last_revision())
328
349
 
329
350
    def test_clone_bzrdir_branch_revision(self):
330
351
        # test for revision limiting, [smoke test, not corner case checks].
344
365
        self.assertEqual('1', target.open_branch().last_revision())
345
366
 
346
367
    def test_clone_on_transport_preserves_repo_format(self):
347
 
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
 
368
        if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
348
369
            format = 'knit'
349
370
        else:
350
371
            format = None
393
414
            repo.set_make_working_trees(False)
394
415
            self.assertFalse(repo.make_working_trees())
395
416
 
396
 
        dir = tree.bzrdir
397
 
        a_dir = dir.clone(self.get_url('repo/a'))
398
 
        a_dir.open_branch()
 
417
        a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
 
418
        a_branch = a_dir.open_branch()
 
419
        # If the new control dir actually uses the repository, it should
 
420
        # not have a working tree.
 
421
        if not a_branch.repository.has_same_location(repo):
 
422
            raise TestNotApplicable('new control dir does not use repository')
399
423
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
400
424
 
401
425
    def test_clone_respects_stacked(self):
406
430
                                                     stacked_on=branch.base)
407
431
        except (errors.UnstackableBranchFormat,
408
432
                errors.UnstackableRepositoryFormat):
409
 
            raise TestNotApplicable("branch or repository format do "
 
433
            raise TestNotApplicable("branch or repository format does "
410
434
                "not support stacking")
411
435
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
412
436
 
 
437
    def test_set_branch_reference(self):
 
438
        """set_branch_reference creates a branch reference"""
 
439
        referenced_branch = self.make_branch('referenced')
 
440
        dir = self.make_bzrdir('source')
 
441
        try:
 
442
            reference = dir.set_branch_reference(referenced_branch)
 
443
        except errors.IncompatibleFormat:
 
444
            # this is ok too, not all formats have to support references.
 
445
            raise TestNotApplicable("control directory does not "
 
446
                "support branch references")
 
447
        self.assertEqual(
 
448
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
449
            dir.get_branch_reference())
 
450
 
 
451
    def test_set_branch_reference_on_existing_reference(self):
 
452
        """set_branch_reference creates a branch reference"""
 
453
        referenced_branch1 = self.make_branch('old-referenced')
 
454
        referenced_branch2 = self.make_branch('new-referenced')
 
455
        dir = self.make_bzrdir('source')
 
456
        try:
 
457
            reference = dir.set_branch_reference(referenced_branch1)
 
458
        except errors.IncompatibleFormat:
 
459
            # this is ok too, not all formats have to support references.
 
460
            raise TestNotApplicable("control directory does not "
 
461
                "support branch references")
 
462
        reference = dir.set_branch_reference(referenced_branch2)
 
463
        self.assertEqual(
 
464
            referenced_branch2.bzrdir.root_transport.abspath('') + '/',
 
465
            dir.get_branch_reference())
 
466
 
 
467
    def test_set_branch_reference_on_existing_branch(self):
 
468
        """set_branch_reference creates a branch reference"""
 
469
        referenced_branch = self.make_branch('referenced')
 
470
        dir = self.make_branch('source').bzrdir
 
471
        try:
 
472
            reference = dir.set_branch_reference(referenced_branch)
 
473
        except errors.IncompatibleFormat:
 
474
            # this is ok too, not all formats have to support references.
 
475
            raise TestNotApplicable("control directory does not "
 
476
                "support branch references")
 
477
        self.assertEqual(
 
478
            referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
479
            dir.get_branch_reference())
 
480
 
413
481
    def test_get_branch_reference_on_reference(self):
414
482
        """get_branch_reference should return the right url."""
415
483
        referenced_branch = self.make_branch('referenced')
416
484
        dir = self.make_bzrdir('source')
417
485
        try:
418
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
419
 
                target_branch=referenced_branch)
 
486
            dir.set_branch_reference(referenced_branch)
420
487
        except errors.IncompatibleFormat:
421
488
            # this is ok too, not all formats have to support references.
422
489
            raise TestNotApplicable("control directory does not "
462
529
            target.open_workingtree()
463
530
        except errors.NoWorkingTree:
464
531
            # Some bzrdirs can never have working trees.
465
 
            self.assertFalse(target._format.supports_workingtrees)
 
532
            repo = target.find_repository()
 
533
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
466
534
 
467
535
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
468
536
        # the force_new_repo parameter should force use of a new repo in an empty
484
552
        tree.add('foo')
485
553
        tree.commit('revision 1', rev_id='1')
486
554
        tree.bzrdir.open_branch().generate_revision_history(
487
 
            bzrlib.revision.NULL_REVISION)
 
555
            _mod_revision.NULL_REVISION)
488
556
        tree.set_parent_trees([])
489
557
        tree.commit('revision 2', rev_id='2')
490
558
        source = self.make_repository('source')
513
581
        tree.add('foo')
514
582
        tree.commit('revision 1', rev_id='1')
515
583
        tree.bzrdir.open_branch().generate_revision_history(
516
 
            bzrlib.revision.NULL_REVISION)
 
584
            _mod_revision.NULL_REVISION)
517
585
        tree.set_parent_trees([])
518
586
        tree.commit('revision 2', rev_id='2')
519
587
        tree.branch.repository.copy_content_into(shared_repo)
538
606
        tree.add('foo')
539
607
        tree.commit('revision 1', rev_id='1')
540
608
        tree.bzrdir.open_branch().generate_revision_history(
541
 
            bzrlib.revision.NULL_REVISION)
 
609
            _mod_revision.NULL_REVISION)
542
610
        tree.set_parent_trees([])
543
611
        tree.commit('revision 2', rev_id='2')
544
612
        tree.branch.repository.copy_content_into(shared_repo)
566
634
        tree.add('foo')
567
635
        tree.commit('revision 1', rev_id='1')
568
636
        tree.bzrdir.open_branch().generate_revision_history(
569
 
            bzrlib.revision.NULL_REVISION)
 
637
            _mod_revision.NULL_REVISION)
570
638
        tree.set_parent_trees([])
571
639
        tree.commit('revision 2', rev_id='2')
572
640
        source = self.make_repository('source')
593
661
        tree.add('foo')
594
662
        tree.commit('revision 1', rev_id='1')
595
663
        br = tree.bzrdir.open_branch()
596
 
        br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
 
664
        br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
597
665
        tree.set_parent_trees([])
598
666
        tree.commit('revision 2', rev_id='2')
599
667
        source = self.make_repository('source')
646
714
        referenced_branch = self.make_branch('referenced')
647
715
        dir = self.make_bzrdir('source')
648
716
        try:
649
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
650
 
                target_branch=referenced_branch)
 
717
            dir.set_branch_reference(referenced_branch)
651
718
        except errors.IncompatibleFormat:
652
719
            raise TestNotApplicable("format does not support branch "
653
720
                "references")
666
733
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
667
734
        dir = self.make_bzrdir('source')
668
735
        try:
669
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
670
 
                target_branch=referenced_tree.branch)
 
736
            dir.set_branch_reference(referenced_tree.branch)
671
737
        except errors.IncompatibleFormat:
672
738
            raise TestNotApplicable("format does not support branch "
673
739
                "references")
693
759
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
694
760
        dir = self.make_bzrdir('source')
695
761
        try:
696
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
697
 
                target_branch=referenced_tree.branch)
 
762
            dir.set_branch_reference(referenced_tree.branch)
698
763
        except errors.IncompatibleFormat:
699
764
            # this is ok too, not all formats have to support references.
700
765
            raise TestNotApplicable("format does not support "
740
805
            source.tags.set_tag('tag-a', 'rev-2')
741
806
        except errors.TagsNotSupported:
742
807
            raise TestNotApplicable('Branch format does not support tags.')
743
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
808
        source.get_config_stack().set('branch.fetch_tags', True)
744
809
        # Now source has a tag not in its ancestry.  Sprout its controldir.
745
810
        dir = source.bzrdir
746
811
        target = dir.sprout(self.get_url('target'))
819
884
            has_ghost_tag = False
820
885
        else:
821
886
            has_ghost_tag = True
822
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
887
        source.get_config_stack().set('branch.fetch_tags', True)
823
888
        # And ask sprout for C2
824
889
        dir = source.bzrdir
825
890
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
845
910
        referenced_branch = self.make_branch('referencced')
846
911
        dir = self.make_bzrdir('source')
847
912
        try:
848
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
849
 
                target_branch=referenced_branch)
 
913
            dir.set_branch_reference(referenced_branch)
850
914
        except errors.IncompatibleFormat:
851
915
            # this is ok too, not all formats have to support references.
852
916
            raise TestNotApplicable("format does not support "
872
936
        referenced_branch = self.make_branch('referencced')
873
937
        dir = self.make_bzrdir('source')
874
938
        try:
875
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
876
 
                target_branch=referenced_branch)
 
939
            dir.set_branch_reference(referenced_branch)
877
940
        except errors.IncompatibleFormat:
878
941
            # this is ok too, not all formats have to support references.
879
942
            raise TestNotApplicable("format does not support "
972
1035
        # network name to use - it's possible that this may somehow have got
973
1036
        # in through an unisolated test though - see
974
1037
        # <https://bugs.launchpad.net/bzr/+bug/504102>
975
 
        self.assertEquals(getattr(self.bzrdir_format,
 
1038
        self.assertEqual(getattr(self.bzrdir_format,
976
1039
            '_network_name', None),
977
1040
            None)
978
1041
        # supported formats must be able to init and open
985
1048
        self.assertEqual(self.bzrdir_format,
986
1049
                         controldir.ControlDirFormat.find_format(readonly_t))
987
1050
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
988
 
        opened_dir = bzrdir.BzrDir.open(t.base)
 
1051
        opened_dir = controldir.ControlDir.open(t.base)
989
1052
        self.assertEqual(made_control._format,
990
1053
                         opened_dir._format)
991
1054
        self.assertEqual(direct_opened_dir._format,
1023
1086
 
1024
1087
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1025
1088
        t = self.get_transport('repo')
1026
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1089
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1027
1090
        repo_name = repo_fmt.repository_format.network_name()
1028
1091
        repo = repo_fmt.initialize_on_transport_ex(t,
1029
1092
            repo_format_name=repo_name, shared_repo=True)[0]
1034
1097
 
1035
1098
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1036
1099
        t = self.get_transport('repo')
1037
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1100
        repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1038
1101
        repo_name = repo_fmt.repository_format.network_name()
1039
1102
        repo = repo_fmt.initialize_on_transport_ex(t,
1040
1103
            repo_format_name=repo_name, shared_repo=True)[0]
1044
1107
            self.assertEqual(repo.bzrdir.root_transport.base,
1045
1108
                made_repo.bzrdir.root_transport.base)
1046
1109
 
1047
 
    def test_format_initialize_on_transport_ex_stacked_on(self):
1048
 
        if not self.bzrdir_format.is_initializable():
1049
 
            raise TestNotApplicable("format is not initializable")
1050
 
        # trunk is a stackable format.  Note that its in the same server area
1051
 
        # which is what launchpad does, but not sufficient to exercise the
1052
 
        # general case.
1053
 
        trunk = self.make_branch('trunk', format='1.9')
1054
 
        t = self.get_transport('stacked')
1055
 
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1056
 
        repo_name = old_fmt.repository_format.network_name()
1057
 
        # Should end up with a 1.9 format (stackable)
1058
 
        repo, control = self.assertInitializeEx(t, need_meta=True,
1059
 
            repo_format_name=repo_name, stacked_on='../trunk',
1060
 
            stack_on_pwd=t.base)
1061
 
        self.assertLength(1, repo._fallback_repositories)
1062
 
 
1063
 
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1064
 
        # When initialize_on_transport_ex uses a stacked-on branch because of
1065
 
        # a stacking policy on the target, the location of the fallback
1066
 
        # repository is the same as the external location of the stacked-on
1067
 
        # branch.
1068
 
        balloon = self.make_bzrdir('balloon')
1069
 
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1070
 
            stack_on = self.make_branch('stack-on', format='1.9')
1071
 
        else:
1072
 
            stack_on = self.make_branch('stack-on')
1073
 
        config = self.make_bzrdir('.').get_config()
1074
 
        try:
1075
 
            config.set_default_stack_on('stack-on')
1076
 
        except errors.BzrError:
1077
 
            raise TestNotApplicable('Only relevant for stackable formats.')
1078
 
        # Initialize a bzrdir subject to the policy.
1079
 
        t = self.get_transport('stacked')
1080
 
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1081
 
        repo_name = repo_fmt.repository_format.network_name()
1082
 
        repo, control = self.assertInitializeEx(
1083
 
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1084
 
        # self.addCleanup(repo.unlock)
1085
 
        # There's one fallback repo, with a public location.
1086
 
        self.assertLength(1, repo._fallback_repositories)
1087
 
        fallback_repo = repo._fallback_repositories[0]
1088
 
        self.assertEqual(
1089
 
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
1090
 
        # The bzrdir creates a branch in stacking-capable format.
1091
 
        new_branch = control.create_branch()
1092
 
        self.assertTrue(new_branch._format.supports_stacking())
1093
 
 
1094
1110
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1095
1111
        t = self.get_transport('dir')
1096
1112
        repo, control = self.assertInitializeEx(t)
1099
1115
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1100
1116
        t = self.get_transport('dir')
1101
1117
        # 1.6 is likely to never be default
1102
 
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
 
1118
        fmt = controldir.format_registry.make_bzrdir('1.6')
1103
1119
        repo_name = fmt.repository_format.network_name()
1104
1120
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1105
1121
        if self.bzrdir_format.fixed_components:
1107
1123
            repo_name = self.bzrdir_format.network_name()
1108
1124
        self.assertEqual(repo_name, repo._format.network_name())
1109
1125
 
1110
 
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
1126
    def assertInitializeEx(self, t, **kwargs):
1111
1127
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1112
1128
 
1113
1129
        This involves checking that the disk objects were created, open with
1128
1144
            self.assertTrue(repo.is_write_locked())
1129
1145
            self.addCleanup(repo.unlock)
1130
1146
        self.assertIsInstance(control, controldir.ControlDir)
1131
 
        opened = bzrdir.BzrDir.open(t.base)
 
1147
        opened = controldir.ControlDir.open(t.base)
1132
1148
        expected_format = self.bzrdir_format
1133
 
        if need_meta and expected_format.fixed_components:
1134
 
            # Pre-metadir formats change when we are making something that
1135
 
            # needs a metaformat, because clone is used for push.
1136
 
            expected_format = bzrdir.BzrDirMetaFormat1()
1137
1149
        if not isinstance(expected_format, RemoteBzrDirFormat):
1138
1150
            self.assertEqual(control._format.network_name(),
1139
1151
                expected_format.network_name())
1202
1214
            raise TestNotApplicable("format does not support "
1203
1215
                "append_revisions_only setting")
1204
1216
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1205
 
        self.assertEquals(True, made_branch.get_append_revisions_only())
 
1217
        self.assertEqual(True, made_branch.get_append_revisions_only())
1206
1218
        self.assertEqual(made_control, made_branch.bzrdir)
1207
1219
 
1208
1220
    def test_open_branch(self):
1228
1240
        made_repo = made_control.create_repository()
1229
1241
        made_branch = made_control.create_branch()
1230
1242
        branches = made_control.list_branches()
1231
 
        self.assertEquals(1, len(branches))
1232
 
        self.assertEquals(made_branch.base, branches[0].base)
 
1243
        self.assertEqual(1, len(branches))
 
1244
        self.assertEqual(made_branch.base, branches[0].base)
1233
1245
        try:
1234
1246
            made_control.destroy_branch()
1235
1247
        except errors.UnsupportedOperation:
1236
1248
            pass # Not all bzrdirs support destroying directories
1237
1249
        else:
1238
 
            self.assertEquals([], made_control.list_branches())
 
1250
            self.assertEqual([], made_control.list_branches())
 
1251
 
 
1252
    def test_get_branches(self):
 
1253
        repo = self.make_repository('branch-1')
 
1254
        target_branch = repo.bzrdir.create_branch()
 
1255
        self.assertEqual([""], repo.bzrdir.get_branches().keys())
1239
1256
 
1240
1257
    def test_create_repository(self):
1241
1258
        # a bzrdir can construct a repository for itself.
1366
1383
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1367
1384
            raise TestSkipped("Can't initialize %r on transport %r"
1368
1385
                              % (self.bzrdir_format, t))
1369
 
        dir = bzrdir.BzrDir.open(t.base+",branch=foo")
1370
 
        self.assertEquals({"branch": "foo"},
 
1386
        dir = controldir.ControlDir.open(t.base+",branch=foo")
 
1387
        self.assertEqual({"branch": "foo"},
1371
1388
            dir.user_transport.get_segment_parameters())
1372
 
        self.assertEquals("foo", dir._get_selected_branch())
 
1389
        self.assertEqual("foo", dir._get_selected_branch())
1373
1390
 
1374
1391
    def test_get_selected_branch_none_selected(self):
1375
1392
        # _get_selected_branch defaults to None
1381
1398
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1382
1399
            raise TestSkipped("Can't initialize %r on transport %r"
1383
1400
                              % (self.bzrdir_format, t))
1384
 
        dir = bzrdir.BzrDir.open(t.base)
1385
 
        self.assertIs(None, dir._get_selected_branch())
 
1401
        dir = controldir.ControlDir.open(t.base)
 
1402
        self.assertEqual(u"", dir._get_selected_branch())
1386
1403
 
1387
1404
    def test_root_transport(self):
1388
1405
        dir = self.make_bzrdir('.')
1456
1473
            raise TestNotApplicable("format does not support "
1457
1474
                "nesting repositories")
1458
1475
        child_repo = self.make_repository('childrepo')
1459
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1476
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1460
1477
        found_repo = opened_control.find_repository()
1461
1478
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1462
1479
                         found_repo.bzrdir.root_transport.base)
1476
1493
        self.get_transport().mkdir('childrepo')
1477
1494
        child_control = self.bzrdir_format.initialize(url)
1478
1495
        child_repo = child_control.create_repository(shared=True)
1479
 
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
1496
        opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1480
1497
        found_repo = opened_control.find_repository()
1481
1498
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1482
1499
                         found_repo.bzrdir.root_transport.base)
1546
1563
             ((dir_relpath2, _), entries2)) in izip(
1547
1564
                osutils.walkdirs(old_path),
1548
1565
                osutils.walkdirs(new_path)):
1549
 
            self.assertEquals(dir_relpath1, dir_relpath2)
 
1566
            self.assertEqual(dir_relpath1, dir_relpath2)
1550
1567
            for f1, f2 in zip(entries1, entries2):
1551
 
                self.assertEquals(f1[0], f2[0])
1552
 
                self.assertEquals(f1[2], f2[2])
 
1568
                self.assertEqual(f1[0], f2[0])
 
1569
                self.assertEqual(f1[2], f2[2])
1553
1570
                if f1[2] == "file":
1554
1571
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1555
1572
 
1621
1638
        master = self.make_branch('branch')
1622
1639
        thisdir = self.make_bzrdir('this')
1623
1640
        try:
1624
 
            bzrlib.branch.BranchReferenceFormat().initialize(
1625
 
                thisdir, target_branch=master)
 
1641
            thisdir.set_branch_reference(master)
1626
1642
        except errors.IncompatibleFormat:
1627
1643
            raise TestNotApplicable("format does not support "
1628
1644
                "branch references")
1697
1713
        except errors.BzrError, e:
1698
1714
            if 'Cannot set config' in str(e):
1699
1715
                self.assertFalse(
1700
 
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
 
1716
                    isinstance(my_dir, (_mod_bzrdir.BzrDirMeta1, RemoteBzrDir)),
1701
1717
                    "%r should support configs" % my_dir)
1702
1718
                raise TestNotApplicable(
1703
1719
                    'This BzrDir format does not support configs.')
1704
1720
            else:
1705
1721
                raise
1706
1722
        self.assertEqual('http://example.com', config.get_default_stack_on())
1707
 
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
 
1723
        my_dir2 = controldir.ControlDir.open(self.get_url('.'))
1708
1724
        config2 = my_dir2.get_config()
1709
1725
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1710
1726
 
1732
1748
            return
1733
1749
        except errors.NoRepositoryPresent:
1734
1750
            pass
1735
 
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1751
        made_control = controldir.ControlDir.open(self.get_readonly_url('subdir'))
1736
1752
        self.assertRaises(errors.NoRepositoryPresent,
1737
1753
                          made_control.find_repository)
1738
1754