~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin
  • Date: 2011-04-15 21:22:57 UTC
  • mto: This revision was merged to the branch mainline in revision 5797.
  • Revision ID: gzlist@googlemail.com-20110415212257-jgtovwwp4be7egd9
Add release notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    controldir,
30
30
    errors,
31
31
    help_topics,
 
32
    lock,
32
33
    repository,
 
34
    revision as _mod_revision,
33
35
    osutils,
34
36
    remote,
35
37
    symbol_versioning,
 
38
    transport as _mod_transport,
36
39
    urlutils,
37
40
    win32utils,
38
41
    workingtree,
39
42
    )
40
43
import bzrlib.branch
41
 
from bzrlib.errors import (NotBranchError,
42
 
                           NoColocatedBranchSupport,
43
 
                           UnknownFormatError,
44
 
                           UnsupportedFormatError,
45
 
                           )
 
44
from bzrlib.errors import (
 
45
    NotBranchError,
 
46
    NoColocatedBranchSupport,
 
47
    UnknownFormatError,
 
48
    UnsupportedFormatError,
 
49
    )
46
50
from bzrlib.tests import (
47
51
    TestCase,
48
52
    TestCaseWithMemoryTransport,
55
59
    )
56
60
from bzrlib.tests.test_http import TestWithTransport_pycurl
57
61
from bzrlib.transport import (
58
 
    get_transport,
59
62
    memory,
60
63
    pathfilter,
61
64
    )
62
65
from bzrlib.transport.http._urllib import HttpTransport_urllib
63
66
from bzrlib.transport.nosmart import NoSmartTransportDecorator
64
67
from bzrlib.transport.readonly import ReadonlyTransportDecorator
65
 
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
 
68
from bzrlib.repofmt import knitrepo, knitpack_repo
66
69
 
67
70
 
68
71
class TestDefaultFormat(TestCase):
69
72
 
70
73
    def test_get_set_default_format(self):
71
74
        old_format = bzrdir.BzrDirFormat.get_default_format()
72
 
        # default is BzrDirFormat6
 
75
        # default is BzrDirMetaFormat1
73
76
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
74
77
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
75
78
        # creating a bzr dir should now create an instrumented dir.
81
84
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
82
85
 
83
86
 
 
87
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
 
88
    """A deprecated bzr dir format."""
 
89
 
 
90
 
84
91
class TestFormatRegistry(TestCase):
85
92
 
86
93
    def make_format_registry(self):
87
94
        my_format_registry = controldir.ControlDirFormatRegistry()
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)
 
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)
93
101
        bzrdir.register_metadir(my_format_registry, 'knit',
94
102
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
95
103
            'Format using knits',
106
114
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
107
115
            'Experimental successor to knit.  Use at your own risk.',
108
116
            branch_format='bzrlib.branch.BzrBranchFormat6', 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)
 
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)
115
122
        return my_format_registry
116
123
 
117
124
    def test_format_registry(self):
118
125
        my_format_registry = self.make_format_registry()
119
126
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
120
 
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
121
 
        my_bzrdir = my_format_registry.make_bzrdir('weave')
122
 
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
 
127
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
 
128
        my_bzrdir = my_format_registry.make_bzrdir('deprecated')
 
129
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
123
130
        my_bzrdir = my_format_registry.make_bzrdir('default')
124
131
        self.assertIsInstance(my_bzrdir.repository_format,
125
132
            knitrepo.RepositoryFormatKnit1)
138
145
                         my_format_registry.get_help('knit'))
139
146
        self.assertEqual('Format using knits',
140
147
                         my_format_registry.get_help('default'))
141
 
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
142
 
                         ' checkouts or shared repositories',
143
 
                         my_format_registry.get_help('weave'))
 
148
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
 
149
                         my_format_registry.get_help('deprecated'))
144
150
 
145
151
    def test_help_topic(self):
146
152
        topics = help_topics.HelpTopicRegistry()
170
176
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
171
177
                          bzrdir.format_registry.get('default'))
172
178
            self.assertIs(
173
 
                repository.RepositoryFormat.get_default_format().__class__,
 
179
                repository.format_registry.get_default().__class__,
174
180
                knitrepo.RepositoryFormatKnit3)
175
181
        finally:
176
182
            bzrdir.format_registry.set_default_repository(old_default)
177
183
 
178
184
    def test_aliases(self):
179
185
        a_registry = controldir.ControlDirFormatRegistry()
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())
 
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())
187
193
 
188
194
 
189
195
class SampleBranch(bzrlib.branch.Branch):
246
252
        return "opened branch."
247
253
 
248
254
 
 
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
 
249
269
class TestBzrDirFormat(TestCaseWithTransport):
250
270
    """Tests for the BzrDirFormat facility."""
251
271
 
252
272
    def test_find_format(self):
253
273
        # is the right format object found for a branch?
254
274
        # create a branch with a few known format objects.
255
 
        # this is not quite the same as
256
 
        t = get_transport(self.get_url())
 
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()
257
284
        self.build_tree(["foo/", "bar/"], transport=t)
258
285
        def check_format(format, url):
259
286
            format.initialize(url)
260
 
            t = get_transport(url)
 
287
            t = _mod_transport.get_transport(url)
261
288
            found_format = bzrdir.BzrDirFormat.find_format(t)
262
289
            self.failUnless(isinstance(found_format, format.__class__))
263
 
        check_format(bzrdir.BzrDirFormat5(), "foo")
264
 
        check_format(bzrdir.BzrDirFormat6(), "bar")
 
290
        check_format(BzrDirFormatTest1(), "foo")
 
291
        check_format(BzrDirFormatTest2(), "bar")
265
292
 
266
293
    def test_find_format_nothing_there(self):
267
294
        self.assertRaises(NotBranchError,
268
295
                          bzrdir.BzrDirFormat.find_format,
269
 
                          get_transport('.'))
 
296
                          _mod_transport.get_transport('.'))
270
297
 
271
298
    def test_find_format_unknown_format(self):
272
 
        t = get_transport(self.get_url())
 
299
        t = self.get_transport()
273
300
        t.mkdir('.bzr')
274
301
        t.put_bytes('.bzr/branch-format', '')
275
302
        self.assertRaises(UnknownFormatError,
276
303
                          bzrdir.BzrDirFormat.find_format,
277
 
                          get_transport('.'))
 
304
                          _mod_transport.get_transport('.'))
278
305
 
279
306
    def test_register_unregister_format(self):
280
307
        format = SampleBzrDirFormat()
282
309
        # make a bzrdir
283
310
        format.initialize(url)
284
311
        # register a format for it.
285
 
        bzrdir.BzrDirFormat.register_format(format)
 
312
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
286
313
        # which bzrdir.Open will refuse (not supported)
287
314
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
288
315
        # which bzrdir.open_containing will refuse (not supported)
289
316
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
290
317
        # but open_downlevel will work
291
 
        t = get_transport(url)
 
318
        t = _mod_transport.get_transport(url)
292
319
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
293
320
        # unregister the format
294
 
        bzrdir.BzrDirFormat.unregister_format(format)
 
321
        bzrdir.BzrProber.formats.remove(format.get_format_string())
295
322
        # now open_downlevel should fail too.
296
323
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
297
324
 
474
501
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
475
502
        # Make stackable source branch with an unstackable repo format.
476
503
        source_bzrdir = self.make_bzrdir('source')
477
 
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
504
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
478
505
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
479
506
            source_bzrdir)
480
507
        # Make a directory with a default stacking policy
680
707
        self.assertEqual(relpath, 'baz')
681
708
 
682
709
    def test_open_containing_from_transport(self):
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')))
 
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')))
687
716
        control = bzrdir.BzrDir.create(self.get_url())
688
717
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
689
 
            get_transport(self.get_readonly_url('')))
 
718
            _mod_transport.get_transport(self.get_readonly_url('')))
690
719
        self.assertEqual('', relpath)
691
720
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
692
 
            get_transport(self.get_readonly_url('g/p/q')))
 
721
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
693
722
        self.assertEqual('g/p/q', relpath)
694
723
 
695
724
    def test_open_containing_tree_or_branch(self):
739
768
        # transport pointing at bzrdir should give a bzrdir with root transport
740
769
        # set to the given transport
741
770
        control = bzrdir.BzrDir.create(self.get_url())
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)
 
771
        t = self.get_transport()
 
772
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
 
773
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
745
774
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
746
775
 
747
776
    def test_open_from_transport_no_bzrdir(self):
748
 
        transport = get_transport(self.get_url())
749
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
750
 
                          transport)
 
777
        t = self.get_transport()
 
778
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
751
779
 
752
780
    def test_open_from_transport_bzrdir_in_parent(self):
753
781
        control = bzrdir.BzrDir.create(self.get_url())
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)
 
782
        t = self.get_transport()
 
783
        t.mkdir('subdir')
 
784
        t = t.clone('subdir')
 
785
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
759
786
 
760
787
    def test_sprout_recursive(self):
761
788
        tree = self.make_branch_and_tree('tree1',
821
848
 
822
849
    def test_find_bzrdirs(self):
823
850
        foo, bar, baz = self.make_foo_bar_baz()
824
 
        transport = get_transport(self.get_url())
825
 
        self.assertEqualBzrdirs([baz, foo, bar],
826
 
                                bzrdir.BzrDir.find_bzrdirs(transport))
 
851
        t = self.get_transport()
 
852
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
827
853
 
828
854
    def make_fake_permission_denied_transport(self, transport, paths):
829
855
        """Create a transport that raises PermissionDenied for some paths."""
845
871
 
846
872
    def test_find_bzrdirs_permission_denied(self):
847
873
        foo, bar, baz = self.make_foo_bar_baz()
848
 
        transport = get_transport(self.get_url())
 
874
        t = self.get_transport()
849
875
        path_filter_server, path_filter_transport = \
850
 
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
876
            self.make_fake_permission_denied_transport(t, ['foo'])
851
877
        # local transport
852
878
        self.assertBranchUrlsEndWith('/baz/',
853
879
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
862
888
            return [s for s in transport.list_dir('') if s != 'baz']
863
889
 
864
890
        foo, bar, baz = self.make_foo_bar_baz()
865
 
        transport = get_transport(self.get_url())
866
 
        self.assertEqualBzrdirs([foo, bar],
867
 
                                bzrdir.BzrDir.find_bzrdirs(transport,
868
 
                                    list_current=list_current))
 
891
        t = self.get_transport()
 
892
        self.assertEqualBzrdirs(
 
893
            [foo, bar],
 
894
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
869
895
 
870
896
    def test_find_bzrdirs_evaluate(self):
871
897
        def evaluate(bzrdir):
877
903
                return False, bzrdir.root_transport.base
878
904
 
879
905
        foo, bar, baz = self.make_foo_bar_baz()
880
 
        transport = get_transport(self.get_url())
 
906
        t = self.get_transport()
881
907
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
882
 
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
883
 
                                                         evaluate=evaluate)))
 
908
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
884
909
 
885
910
    def assertEqualBzrdirs(self, first, second):
886
911
        first = list(first)
893
918
        root = self.make_repository('', shared=True)
894
919
        foo, bar, baz = self.make_foo_bar_baz()
895
920
        qux = self.make_bzrdir('foo/qux')
896
 
        transport = get_transport(self.get_url())
897
 
        branches = bzrdir.BzrDir.find_branches(transport)
 
921
        t = self.get_transport()
 
922
        branches = bzrdir.BzrDir.find_branches(t)
898
923
        self.assertEqual(baz.root_transport.base, branches[0].base)
899
924
        self.assertEqual(foo.root_transport.base, branches[1].base)
900
925
        self.assertEqual(bar.root_transport.base, branches[2].base)
901
926
 
902
927
        # ensure this works without a top-level repo
903
 
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
 
928
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
904
929
        self.assertEqual(foo.root_transport.base, branches[0].base)
905
930
        self.assertEqual(bar.root_transport.base, branches[1].base)
906
931
 
908
933
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
909
934
 
910
935
    def test_find_bzrdirs_missing_repo(self):
911
 
        transport = get_transport(self.get_url())
 
936
        t = self.get_transport()
912
937
        arepo = self.make_repository('arepo', shared=True)
913
938
        abranch_url = arepo.user_url + '/abranch'
914
939
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
915
 
        transport.delete_tree('arepo/.bzr')
 
940
        t.delete_tree('arepo/.bzr')
916
941
        self.assertRaises(errors.NoRepositoryPresent,
917
942
            branch.Branch.open, abranch_url)
918
943
        self.make_branch('baz')
919
 
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
 
944
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
920
945
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
921
946
 
922
947
 
932
957
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
933
958
        repository_base = t.clone('repository').base
934
959
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
 
960
        repository_format = repository.format_registry.get_default()
935
961
        self.assertEqual(repository_base,
936
 
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
 
962
                         dir.get_repository_transport(repository_format).base)
937
963
        checkout_base = t.clone('checkout').base
938
964
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
939
965
        self.assertEqual(checkout_base,
985
1011
        self.assertEqual(2, rpc_count)
986
1012
 
987
1013
 
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
 
 
1120
1014
class NonLocalTests(TestCaseWithTransport):
1121
1015
    """Tests for bzrdir static behaviour on non local paths."""
1122
1016
 
1141
1035
            self.get_url('foo'),
1142
1036
            force_new_tree=True,
1143
1037
            format=format)
1144
 
        t = get_transport(self.get_url('.'))
 
1038
        t = self.get_transport()
1145
1039
        self.assertFalse(t.has('foo'))
1146
1040
 
1147
1041
    def test_clone(self):
1343
1237
    def copy_content_into(self, destination, revision_id=None):
1344
1238
        self.calls.append('copy_content_into')
1345
1239
 
 
1240
    def last_revision(self):
 
1241
        return _mod_revision.NULL_REVISION
 
1242
 
1346
1243
    def get_parent(self):
1347
1244
        return self._parent
1348
1245
 
1349
1246
    def set_parent(self, parent):
1350
1247
        self._parent = parent
1351
1248
 
 
1249
    def lock_read(self):
 
1250
        return lock.LogicalLockResult(self.unlock)
 
1251
 
 
1252
    def unlock(self):
 
1253
        return
 
1254
 
1352
1255
 
1353
1256
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1354
1257
 
1438
1341
 
1439
1342
    def setUp(self):
1440
1343
        super(TestGenerateBackupName, self).setUp()
1441
 
        self._transport = get_transport(self.get_url())
 
1344
        self._transport = self.get_transport()
1442
1345
        bzrdir.BzrDir.create(self.get_url(),
1443
1346
            possible_transports=[self._transport])
1444
1347
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1454
1357
    def test_exiting(self):
1455
1358
        self._transport.put_bytes("a.~1~", "some content")
1456
1359
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
 
1360