~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

(gz) Change minimum required testtools version for selftest to 0.9.5 for
 unicode fixes (Martin [gz])

Show diffs side-by-side

added added

removed removed

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