~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

(jameinel) Bug #581311,
 treat WSAECONNABORTED as ConnectionReset. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    help_topics,
32
32
    lock,
33
33
    repository,
34
 
    revision as _mod_revision,
35
34
    osutils,
36
35
    remote,
37
36
    symbol_versioning,
38
 
    transport as _mod_transport,
39
37
    urlutils,
40
38
    win32utils,
41
 
    workingtree_3,
42
 
    workingtree_4,
 
39
    workingtree,
43
40
    )
44
41
import bzrlib.branch
45
 
from bzrlib.errors import (
46
 
    NotBranchError,
47
 
    NoColocatedBranchSupport,
48
 
    UnknownFormatError,
49
 
    UnsupportedFormatError,
50
 
    )
 
42
from bzrlib.errors import (NotBranchError,
 
43
                           NoColocatedBranchSupport,
 
44
                           UnknownFormatError,
 
45
                           UnsupportedFormatError,
 
46
                           )
51
47
from bzrlib.tests import (
52
48
    TestCase,
53
49
    TestCaseWithMemoryTransport,
60
56
    )
61
57
from bzrlib.tests.test_http import TestWithTransport_pycurl
62
58
from bzrlib.transport import (
 
59
    get_transport,
63
60
    memory,
64
61
    pathfilter,
65
62
    )
66
63
from bzrlib.transport.http._urllib import HttpTransport_urllib
67
64
from bzrlib.transport.nosmart import NoSmartTransportDecorator
68
65
from bzrlib.transport.readonly import ReadonlyTransportDecorator
69
 
from bzrlib.repofmt import knitrepo, knitpack_repo
 
66
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
70
67
 
71
68
 
72
69
class TestDefaultFormat(TestCase):
73
70
 
74
71
    def test_get_set_default_format(self):
75
72
        old_format = bzrdir.BzrDirFormat.get_default_format()
76
 
        # default is BzrDirMetaFormat1
77
 
        self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
 
73
        # default is BzrDirFormat6
 
74
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
78
75
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
79
76
        # creating a bzr dir should now create an instrumented dir.
80
77
        try:
81
78
            result = bzrdir.BzrDir.create('memory:///')
82
 
            self.assertIsInstance(result, SampleBzrDir)
 
79
            self.failUnless(isinstance(result, SampleBzrDir))
83
80
        finally:
84
81
            controldir.ControlDirFormat._set_default_format(old_format)
85
82
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
86
83
 
87
84
 
88
 
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
89
 
    """A deprecated bzr dir format."""
90
 
 
91
 
 
92
85
class TestFormatRegistry(TestCase):
93
86
 
94
87
    def make_format_registry(self):
95
88
        my_format_registry = controldir.ControlDirFormatRegistry()
96
 
        my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
97
 
            'Some format.  Slower and unawesome and deprecated.',
98
 
            deprecated=True)
99
 
        my_format_registry.register_lazy('lazy', 'bzrlib.tests.test_bzrdir',
100
 
            'DeprecatedBzrDirFormat', 'Format registered lazily',
101
 
            deprecated=True)
 
89
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
 
90
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
91
            ' repositories', deprecated=True)
 
92
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
 
93
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
102
94
        bzrdir.register_metadir(my_format_registry, 'knit',
103
95
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
104
96
            'Format using knits',
115
107
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
116
108
            'Experimental successor to knit.  Use at your own risk.',
117
109
            branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
118
 
        my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
119
 
            'Old format.  Slower and does not support things. ', hidden=True)
120
 
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.tests.test_bzrdir',
121
 
            'DeprecatedBzrDirFormat', 'Format registered lazily',
122
 
            deprecated=True, hidden=True)
 
110
        my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
 
111
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
112
            ' repositories', hidden=True)
 
113
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
 
114
            'BzrDirFormat6', 'Format registered lazily', deprecated=True,
 
115
            hidden=True)
123
116
        return my_format_registry
124
117
 
125
118
    def test_format_registry(self):
126
119
        my_format_registry = self.make_format_registry()
127
120
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
128
 
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
129
 
        my_bzrdir = my_format_registry.make_bzrdir('deprecated')
130
 
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
 
121
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
 
122
        my_bzrdir = my_format_registry.make_bzrdir('weave')
 
123
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
131
124
        my_bzrdir = my_format_registry.make_bzrdir('default')
132
125
        self.assertIsInstance(my_bzrdir.repository_format,
133
126
            knitrepo.RepositoryFormatKnit1)
146
139
                         my_format_registry.get_help('knit'))
147
140
        self.assertEqual('Format using knits',
148
141
                         my_format_registry.get_help('default'))
149
 
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
150
 
                         my_format_registry.get_help('deprecated'))
 
142
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
 
143
                         ' checkouts or shared repositories',
 
144
                         my_format_registry.get_help('weave'))
151
145
 
152
146
    def test_help_topic(self):
153
147
        topics = help_topics.HelpTopicRegistry()
177
171
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
178
172
                          bzrdir.format_registry.get('default'))
179
173
            self.assertIs(
180
 
                repository.format_registry.get_default().__class__,
 
174
                repository.RepositoryFormat.get_default_format().__class__,
181
175
                knitrepo.RepositoryFormatKnit3)
182
176
        finally:
183
177
            bzrdir.format_registry.set_default_repository(old_default)
184
178
 
185
179
    def test_aliases(self):
186
180
        a_registry = controldir.ControlDirFormatRegistry()
187
 
        a_registry.register('deprecated', DeprecatedBzrDirFormat,
188
 
            'Old format.  Slower and does not support stuff',
189
 
            deprecated=True)
190
 
        a_registry.register('deprecatedalias', DeprecatedBzrDirFormat,
191
 
            'Old format.  Slower and does not support stuff',
192
 
            deprecated=True, alias=True)
193
 
        self.assertEqual(frozenset(['deprecatedalias']), a_registry.aliases())
 
181
        a_registry.register('weave', bzrdir.BzrDirFormat6,
 
182
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
183
            ' repositories', deprecated=True)
 
184
        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
 
185
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
186
            ' repositories', deprecated=True, alias=True)
 
187
        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
194
188
 
195
189
 
196
190
class SampleBranch(bzrlib.branch.Branch):
253
247
        return "opened branch."
254
248
 
255
249
 
256
 
class BzrDirFormatTest1(bzrdir.BzrDirMetaFormat1):
257
 
 
258
 
    @staticmethod
259
 
    def get_format_string():
260
 
        return "Test format 1"
261
 
 
262
 
 
263
 
class BzrDirFormatTest2(bzrdir.BzrDirMetaFormat1):
264
 
 
265
 
    @staticmethod
266
 
    def get_format_string():
267
 
        return "Test format 2"
268
 
 
269
 
 
270
250
class TestBzrDirFormat(TestCaseWithTransport):
271
251
    """Tests for the BzrDirFormat facility."""
272
252
 
273
253
    def test_find_format(self):
274
254
        # is the right format object found for a branch?
275
255
        # create a branch with a few known format objects.
276
 
        bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
277
 
            BzrDirFormatTest1())
278
 
        self.addCleanup(bzrdir.BzrProber.formats.remove,
279
 
            BzrDirFormatTest1.get_format_string())
280
 
        bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
281
 
            BzrDirFormatTest2())
282
 
        self.addCleanup(bzrdir.BzrProber.formats.remove,
283
 
            BzrDirFormatTest2.get_format_string())
284
 
        t = self.get_transport()
 
256
        # this is not quite the same as
 
257
        t = get_transport(self.get_url())
285
258
        self.build_tree(["foo/", "bar/"], transport=t)
286
259
        def check_format(format, url):
287
260
            format.initialize(url)
288
 
            t = _mod_transport.get_transport(url)
 
261
            t = get_transport(url)
289
262
            found_format = bzrdir.BzrDirFormat.find_format(t)
290
 
            self.assertIsInstance(found_format, format.__class__)
291
 
        check_format(BzrDirFormatTest1(), "foo")
292
 
        check_format(BzrDirFormatTest2(), "bar")
 
263
            self.failUnless(isinstance(found_format, format.__class__))
 
264
        check_format(bzrdir.BzrDirFormat5(), "foo")
 
265
        check_format(bzrdir.BzrDirFormat6(), "bar")
293
266
 
294
267
    def test_find_format_nothing_there(self):
295
268
        self.assertRaises(NotBranchError,
296
269
                          bzrdir.BzrDirFormat.find_format,
297
 
                          _mod_transport.get_transport('.'))
 
270
                          get_transport('.'))
298
271
 
299
272
    def test_find_format_unknown_format(self):
300
 
        t = self.get_transport()
 
273
        t = get_transport(self.get_url())
301
274
        t.mkdir('.bzr')
302
275
        t.put_bytes('.bzr/branch-format', '')
303
276
        self.assertRaises(UnknownFormatError,
304
277
                          bzrdir.BzrDirFormat.find_format,
305
 
                          _mod_transport.get_transport('.'))
 
278
                          get_transport('.'))
306
279
 
307
280
    def test_register_unregister_format(self):
308
281
        format = SampleBzrDirFormat()
310
283
        # make a bzrdir
311
284
        format.initialize(url)
312
285
        # register a format for it.
313
 
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
 
286
        bzrdir.BzrDirFormat.register_format(format)
314
287
        # which bzrdir.Open will refuse (not supported)
315
288
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
316
289
        # which bzrdir.open_containing will refuse (not supported)
317
290
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
318
291
        # but open_downlevel will work
319
 
        t = _mod_transport.get_transport(url)
 
292
        t = get_transport(url)
320
293
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
321
294
        # unregister the format
322
 
        bzrdir.BzrProber.formats.remove(format.get_format_string())
 
295
        bzrdir.BzrDirFormat.unregister_format(format)
323
296
        # now open_downlevel should fail too.
324
297
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
325
298
 
502
475
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
503
476
        # Make stackable source branch with an unstackable repo format.
504
477
        source_bzrdir = self.make_bzrdir('source')
505
 
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
478
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
506
479
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
507
480
            source_bzrdir)
508
481
        # Make a directory with a default stacking policy
708
681
        self.assertEqual(relpath, 'baz')
709
682
 
710
683
    def test_open_containing_from_transport(self):
711
 
        self.assertRaises(NotBranchError,
712
 
            bzrdir.BzrDir.open_containing_from_transport,
713
 
            _mod_transport.get_transport(self.get_readonly_url('')))
714
 
        self.assertRaises(NotBranchError,
715
 
            bzrdir.BzrDir.open_containing_from_transport,
716
 
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
 
684
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
685
                          get_transport(self.get_readonly_url('')))
 
686
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
687
                          get_transport(self.get_readonly_url('g/p/q')))
717
688
        control = bzrdir.BzrDir.create(self.get_url())
718
689
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
719
 
            _mod_transport.get_transport(self.get_readonly_url('')))
 
690
            get_transport(self.get_readonly_url('')))
720
691
        self.assertEqual('', relpath)
721
692
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
722
 
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
 
693
            get_transport(self.get_readonly_url('g/p/q')))
723
694
        self.assertEqual('g/p/q', relpath)
724
695
 
725
696
    def test_open_containing_tree_or_branch(self):
769
740
        # transport pointing at bzrdir should give a bzrdir with root transport
770
741
        # set to the given transport
771
742
        control = bzrdir.BzrDir.create(self.get_url())
772
 
        t = self.get_transport()
773
 
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
774
 
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
 
743
        transport = get_transport(self.get_url())
 
744
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
 
745
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
775
746
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
776
747
 
777
748
    def test_open_from_transport_no_bzrdir(self):
778
 
        t = self.get_transport()
779
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
 
749
        transport = get_transport(self.get_url())
 
750
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
 
751
                          transport)
780
752
 
781
753
    def test_open_from_transport_bzrdir_in_parent(self):
782
754
        control = bzrdir.BzrDir.create(self.get_url())
783
 
        t = self.get_transport()
784
 
        t.mkdir('subdir')
785
 
        t = t.clone('subdir')
786
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
 
755
        transport = get_transport(self.get_url())
 
756
        transport.mkdir('subdir')
 
757
        transport = transport.clone('subdir')
 
758
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
 
759
                          transport)
787
760
 
788
761
    def test_sprout_recursive(self):
789
762
        tree = self.make_branch_and_tree('tree1',
798
771
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
799
772
        tree2.lock_read()
800
773
        self.addCleanup(tree2.unlock)
801
 
        self.assertPathExists('tree2/subtree/file')
 
774
        self.failUnlessExists('tree2/subtree/file')
802
775
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
803
776
 
804
777
    def test_cloning_metadir(self):
808
781
        branch = self.make_branch('branch', format='knit')
809
782
        format = branch.bzrdir.cloning_metadir()
810
783
        self.assertIsInstance(format.workingtree_format,
811
 
            workingtree_4.WorkingTreeFormat6)
 
784
            workingtree.WorkingTreeFormat3)
812
785
 
813
786
    def test_sprout_recursive_treeless(self):
814
787
        tree = self.make_branch_and_tree('tree1',
838
811
        # #634470.  -- vila 20100909
839
812
        self.assertRaises(errors.NotBranchError,
840
813
                          tree.bzrdir.sprout, 'repo/tree2')
841
 
#        self.assertPathExists('repo/tree2/subtree')
842
 
#        self.assertPathDoesNotExist('repo/tree2/subtree/file')
 
814
#        self.failUnlessExists('repo/tree2/subtree')
 
815
#        self.failIfExists('repo/tree2/subtree/file')
843
816
 
844
817
    def make_foo_bar_baz(self):
845
818
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
849
822
 
850
823
    def test_find_bzrdirs(self):
851
824
        foo, bar, baz = self.make_foo_bar_baz()
852
 
        t = self.get_transport()
853
 
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
 
825
        transport = get_transport(self.get_url())
 
826
        self.assertEqualBzrdirs([baz, foo, bar],
 
827
                                bzrdir.BzrDir.find_bzrdirs(transport))
854
828
 
855
829
    def make_fake_permission_denied_transport(self, transport, paths):
856
830
        """Create a transport that raises PermissionDenied for some paths."""
872
846
 
873
847
    def test_find_bzrdirs_permission_denied(self):
874
848
        foo, bar, baz = self.make_foo_bar_baz()
875
 
        t = self.get_transport()
 
849
        transport = get_transport(self.get_url())
876
850
        path_filter_server, path_filter_transport = \
877
 
            self.make_fake_permission_denied_transport(t, ['foo'])
 
851
            self.make_fake_permission_denied_transport(transport, ['foo'])
878
852
        # local transport
879
853
        self.assertBranchUrlsEndWith('/baz/',
880
854
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
889
863
            return [s for s in transport.list_dir('') if s != 'baz']
890
864
 
891
865
        foo, bar, baz = self.make_foo_bar_baz()
892
 
        t = self.get_transport()
893
 
        self.assertEqualBzrdirs(
894
 
            [foo, bar],
895
 
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
 
866
        transport = get_transport(self.get_url())
 
867
        self.assertEqualBzrdirs([foo, bar],
 
868
                                bzrdir.BzrDir.find_bzrdirs(transport,
 
869
                                    list_current=list_current))
896
870
 
897
871
    def test_find_bzrdirs_evaluate(self):
898
872
        def evaluate(bzrdir):
904
878
                return False, bzrdir.root_transport.base
905
879
 
906
880
        foo, bar, baz = self.make_foo_bar_baz()
907
 
        t = self.get_transport()
 
881
        transport = get_transport(self.get_url())
908
882
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
909
 
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
 
883
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
 
884
                                                         evaluate=evaluate)))
910
885
 
911
886
    def assertEqualBzrdirs(self, first, second):
912
887
        first = list(first)
919
894
        root = self.make_repository('', shared=True)
920
895
        foo, bar, baz = self.make_foo_bar_baz()
921
896
        qux = self.make_bzrdir('foo/qux')
922
 
        t = self.get_transport()
923
 
        branches = bzrdir.BzrDir.find_branches(t)
 
897
        transport = get_transport(self.get_url())
 
898
        branches = bzrdir.BzrDir.find_branches(transport)
924
899
        self.assertEqual(baz.root_transport.base, branches[0].base)
925
900
        self.assertEqual(foo.root_transport.base, branches[1].base)
926
901
        self.assertEqual(bar.root_transport.base, branches[2].base)
927
902
 
928
903
        # ensure this works without a top-level repo
929
 
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
 
904
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
930
905
        self.assertEqual(foo.root_transport.base, branches[0].base)
931
906
        self.assertEqual(bar.root_transport.base, branches[1].base)
932
907
 
934
909
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
935
910
 
936
911
    def test_find_bzrdirs_missing_repo(self):
937
 
        t = self.get_transport()
 
912
        transport = get_transport(self.get_url())
938
913
        arepo = self.make_repository('arepo', shared=True)
939
914
        abranch_url = arepo.user_url + '/abranch'
940
915
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
941
 
        t.delete_tree('arepo/.bzr')
 
916
        transport.delete_tree('arepo/.bzr')
942
917
        self.assertRaises(errors.NoRepositoryPresent,
943
918
            branch.Branch.open, abranch_url)
944
919
        self.make_branch('baz')
945
 
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
 
920
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
946
921
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
947
922
 
948
923
 
958
933
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
959
934
        repository_base = t.clone('repository').base
960
935
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
961
 
        repository_format = repository.format_registry.get_default()
962
936
        self.assertEqual(repository_base,
963
 
                         dir.get_repository_transport(repository_format).base)
 
937
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
964
938
        checkout_base = t.clone('checkout').base
965
939
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
966
940
        self.assertEqual(checkout_base,
967
 
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
 
941
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
968
942
 
969
943
    def test_meta1dir_uses_lockdir(self):
970
944
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
1012
986
        self.assertEqual(2, rpc_count)
1013
987
 
1014
988
 
 
989
class TestFormat5(TestCaseWithTransport):
 
990
    """Tests specific to the version 5 bzrdir format."""
 
991
 
 
992
    def test_same_lockfiles_between_tree_repo_branch(self):
 
993
        # this checks that only a single lockfiles instance is created
 
994
        # for format 5 objects
 
995
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
996
        def check_dir_components_use_same_lock(dir):
 
997
            ctrl_1 = dir.open_repository().control_files
 
998
            ctrl_2 = dir.open_branch().control_files
 
999
            ctrl_3 = dir.open_workingtree()._control_files
 
1000
            self.assertTrue(ctrl_1 is ctrl_2)
 
1001
            self.assertTrue(ctrl_2 is ctrl_3)
 
1002
        check_dir_components_use_same_lock(dir)
 
1003
        # and if we open it normally.
 
1004
        dir = bzrdir.BzrDir.open(self.get_url())
 
1005
        check_dir_components_use_same_lock(dir)
 
1006
 
 
1007
    def test_can_convert(self):
 
1008
        # format 5 dirs are convertable
 
1009
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
1010
        self.assertTrue(dir.can_convert_format())
 
1011
 
 
1012
    def test_needs_conversion(self):
 
1013
        # format 5 dirs need a conversion if they are not the default,
 
1014
        # and they aren't
 
1015
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
1016
        # don't need to convert it to itself
 
1017
        self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
 
1018
        # do need to convert it to the current default
 
1019
        self.assertTrue(dir.needs_format_conversion(
 
1020
            bzrdir.BzrDirFormat.get_default_format()))
 
1021
 
 
1022
 
 
1023
class TestFormat6(TestCaseWithTransport):
 
1024
    """Tests specific to the version 6 bzrdir format."""
 
1025
 
 
1026
    def test_same_lockfiles_between_tree_repo_branch(self):
 
1027
        # this checks that only a single lockfiles instance is created
 
1028
        # for format 6 objects
 
1029
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1030
        def check_dir_components_use_same_lock(dir):
 
1031
            ctrl_1 = dir.open_repository().control_files
 
1032
            ctrl_2 = dir.open_branch().control_files
 
1033
            ctrl_3 = dir.open_workingtree()._control_files
 
1034
            self.assertTrue(ctrl_1 is ctrl_2)
 
1035
            self.assertTrue(ctrl_2 is ctrl_3)
 
1036
        check_dir_components_use_same_lock(dir)
 
1037
        # and if we open it normally.
 
1038
        dir = bzrdir.BzrDir.open(self.get_url())
 
1039
        check_dir_components_use_same_lock(dir)
 
1040
 
 
1041
    def test_can_convert(self):
 
1042
        # format 6 dirs are convertable
 
1043
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1044
        self.assertTrue(dir.can_convert_format())
 
1045
 
 
1046
    def test_needs_conversion(self):
 
1047
        # format 6 dirs need an conversion if they are not the default.
 
1048
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1049
        self.assertTrue(dir.needs_format_conversion(
 
1050
            bzrdir.BzrDirFormat.get_default_format()))
 
1051
 
 
1052
 
 
1053
class NotBzrDir(bzrlib.bzrdir.BzrDir):
 
1054
    """A non .bzr based control directory."""
 
1055
 
 
1056
    def __init__(self, transport, format):
 
1057
        self._format = format
 
1058
        self.root_transport = transport
 
1059
        self.transport = transport.clone('.not')
 
1060
 
 
1061
 
 
1062
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
 
1063
    """A test class representing any non-.bzr based disk format."""
 
1064
 
 
1065
    def initialize_on_transport(self, transport):
 
1066
        """Initialize a new .not dir in the base directory of a Transport."""
 
1067
        transport.mkdir('.not')
 
1068
        return self.open(transport)
 
1069
 
 
1070
    def open(self, transport):
 
1071
        """Open this directory."""
 
1072
        return NotBzrDir(transport, self)
 
1073
 
 
1074
    @classmethod
 
1075
    def _known_formats(self):
 
1076
        return set([NotBzrDirFormat()])
 
1077
 
 
1078
 
 
1079
class NotBzrDirProber(controldir.Prober):
 
1080
 
 
1081
    def probe_transport(self, transport):
 
1082
        """Our format is present if the transport ends in '.not/'."""
 
1083
        if transport.has('.not'):
 
1084
            return NotBzrDirFormat()
 
1085
 
 
1086
 
 
1087
class TestNotBzrDir(TestCaseWithTransport):
 
1088
    """Tests for using the bzrdir api with a non .bzr based disk format.
 
1089
 
 
1090
    If/when one of these is in the core, we can let the implementation tests
 
1091
    verify this works.
 
1092
    """
 
1093
 
 
1094
    def test_create_and_find_format(self):
 
1095
        # create a .notbzr dir
 
1096
        format = NotBzrDirFormat()
 
1097
        dir = format.initialize(self.get_url())
 
1098
        self.assertIsInstance(dir, NotBzrDir)
 
1099
        # now probe for it.
 
1100
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
 
1101
        try:
 
1102
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
 
1103
                get_transport(self.get_url()))
 
1104
            self.assertIsInstance(found, NotBzrDirFormat)
 
1105
        finally:
 
1106
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
 
1107
 
 
1108
    def test_included_in_known_formats(self):
 
1109
        not_format = NotBzrDirFormat()
 
1110
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
 
1111
        try:
 
1112
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
 
1113
            for format in formats:
 
1114
                if isinstance(format, NotBzrDirFormat):
 
1115
                    return
 
1116
            self.fail("No NotBzrDirFormat in %s" % formats)
 
1117
        finally:
 
1118
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
 
1119
 
 
1120
 
1015
1121
class NonLocalTests(TestCaseWithTransport):
1016
1122
    """Tests for bzrdir static behaviour on non local paths."""
1017
1123
 
1036
1142
            self.get_url('foo'),
1037
1143
            force_new_tree=True,
1038
1144
            format=format)
1039
 
        t = self.get_transport()
 
1145
        t = get_transport(self.get_url('.'))
1040
1146
        self.assertFalse(t.has('foo'))
1041
1147
 
1042
1148
    def test_clone(self):
1058
1164
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1059
1165
        checkout_format = my_bzrdir.checkout_metadir()
1060
1166
        self.assertIsInstance(checkout_format.workingtree_format,
1061
 
                              workingtree_4.WorkingTreeFormat4)
 
1167
                              workingtree.WorkingTreeFormat3)
1062
1168
 
1063
1169
 
1064
1170
class TestHTTPRedirections(object):
1238
1344
    def copy_content_into(self, destination, revision_id=None):
1239
1345
        self.calls.append('copy_content_into')
1240
1346
 
1241
 
    def last_revision(self):
1242
 
        return _mod_revision.NULL_REVISION
1243
 
 
1244
1347
    def get_parent(self):
1245
1348
        return self._parent
1246
1349
 
1342
1445
 
1343
1446
    def setUp(self):
1344
1447
        super(TestGenerateBackupName, self).setUp()
1345
 
        self._transport = self.get_transport()
 
1448
        self._transport = get_transport(self.get_url())
1346
1449
        bzrdir.BzrDir.create(self.get_url(),
1347
1450
            possible_transports=[self._transport])
1348
1451
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1358
1461
    def test_exiting(self):
1359
1462
        self._transport.put_bytes("a.~1~", "some content")
1360
1463
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1361