~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

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
 
    symbol_versioning,
38
 
    transport as _mod_transport,
39
35
    urlutils,
40
36
    win32utils,
41
 
    workingtree_3,
42
 
    workingtree_4,
 
37
    workingtree,
43
38
    )
44
39
import bzrlib.branch
45
 
from bzrlib.errors import (
46
 
    NotBranchError,
47
 
    NoColocatedBranchSupport,
48
 
    UnknownFormatError,
49
 
    UnsupportedFormatError,
50
 
    )
 
40
from bzrlib.errors import (NotBranchError,
 
41
                           NoColocatedBranchSupport,
 
42
                           UnknownFormatError,
 
43
                           UnsupportedFormatError,
 
44
                           )
51
45
from bzrlib.tests import (
52
46
    TestCase,
53
47
    TestCaseWithMemoryTransport,
60
54
    )
61
55
from bzrlib.tests.test_http import TestWithTransport_pycurl
62
56
from bzrlib.transport import (
 
57
    get_transport,
63
58
    memory,
64
59
    pathfilter,
65
60
    )
66
61
from bzrlib.transport.http._urllib import HttpTransport_urllib
67
62
from bzrlib.transport.nosmart import NoSmartTransportDecorator
68
63
from bzrlib.transport.readonly import ReadonlyTransportDecorator
69
 
from bzrlib.repofmt import knitrepo, knitpack_repo
 
64
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
70
65
 
71
66
 
72
67
class TestDefaultFormat(TestCase):
73
68
 
74
69
    def test_get_set_default_format(self):
75
70
        old_format = bzrdir.BzrDirFormat.get_default_format()
76
 
        # default is BzrDirMetaFormat1
77
 
        self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
 
71
        # default is BzrDirFormat6
 
72
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
78
73
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
79
74
        # creating a bzr dir should now create an instrumented dir.
80
75
        try:
81
76
            result = bzrdir.BzrDir.create('memory:///')
82
 
            self.assertIsInstance(result, SampleBzrDir)
 
77
            self.failUnless(isinstance(result, SampleBzrDir))
83
78
        finally:
84
79
            controldir.ControlDirFormat._set_default_format(old_format)
85
80
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
86
81
 
87
82
 
88
 
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
89
 
    """A deprecated bzr dir format."""
90
 
 
91
 
 
92
83
class TestFormatRegistry(TestCase):
93
84
 
94
85
    def make_format_registry(self):
95
86
        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)
 
87
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
 
88
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
89
            ' repositories', deprecated=True)
 
90
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
 
91
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
102
92
        bzrdir.register_metadir(my_format_registry, 'knit',
103
93
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
104
94
            'Format using knits',
115
105
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
116
106
            'Experimental successor to knit.  Use at your own risk.',
117
107
            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)
 
108
        my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
 
109
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
110
            ' repositories', hidden=True)
 
111
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
 
112
            'BzrDirFormat6', 'Format registered lazily', deprecated=True,
 
113
            hidden=True)
123
114
        return my_format_registry
124
115
 
125
116
    def test_format_registry(self):
126
117
        my_format_registry = self.make_format_registry()
127
118
        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)
 
119
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
 
120
        my_bzrdir = my_format_registry.make_bzrdir('weave')
 
121
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
131
122
        my_bzrdir = my_format_registry.make_bzrdir('default')
132
123
        self.assertIsInstance(my_bzrdir.repository_format,
133
124
            knitrepo.RepositoryFormatKnit1)
146
137
                         my_format_registry.get_help('knit'))
147
138
        self.assertEqual('Format using knits',
148
139
                         my_format_registry.get_help('default'))
149
 
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
150
 
                         my_format_registry.get_help('deprecated'))
 
140
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
 
141
                         ' checkouts or shared repositories',
 
142
                         my_format_registry.get_help('weave'))
151
143
 
152
144
    def test_help_topic(self):
153
145
        topics = help_topics.HelpTopicRegistry()
177
169
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
178
170
                          bzrdir.format_registry.get('default'))
179
171
            self.assertIs(
180
 
                repository.format_registry.get_default().__class__,
 
172
                repository.RepositoryFormat.get_default_format().__class__,
181
173
                knitrepo.RepositoryFormatKnit3)
182
174
        finally:
183
175
            bzrdir.format_registry.set_default_repository(old_default)
184
176
 
185
177
    def test_aliases(self):
186
178
        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())
 
179
        a_registry.register('weave', bzrdir.BzrDirFormat6,
 
180
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
181
            ' repositories', deprecated=True)
 
182
        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
 
183
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
184
            ' repositories', deprecated=True, alias=True)
 
185
        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
194
186
 
195
187
 
196
188
class SampleBranch(bzrlib.branch.Branch):
253
245
        return "opened branch."
254
246
 
255
247
 
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
248
class TestBzrDirFormat(TestCaseWithTransport):
271
249
    """Tests for the BzrDirFormat facility."""
272
250
 
273
251
    def test_find_format(self):
274
252
        # is the right format object found for a branch?
275
253
        # 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()
 
254
        # this is not quite the same as
 
255
        t = get_transport(self.get_url())
285
256
        self.build_tree(["foo/", "bar/"], transport=t)
286
257
        def check_format(format, url):
287
258
            format.initialize(url)
288
 
            t = _mod_transport.get_transport(url)
 
259
            t = get_transport(url)
289
260
            found_format = bzrdir.BzrDirFormat.find_format(t)
290
 
            self.assertIsInstance(found_format, format.__class__)
291
 
        check_format(BzrDirFormatTest1(), "foo")
292
 
        check_format(BzrDirFormatTest2(), "bar")
 
261
            self.failUnless(isinstance(found_format, format.__class__))
 
262
        check_format(bzrdir.BzrDirFormat5(), "foo")
 
263
        check_format(bzrdir.BzrDirFormat6(), "bar")
293
264
 
294
265
    def test_find_format_nothing_there(self):
295
266
        self.assertRaises(NotBranchError,
296
267
                          bzrdir.BzrDirFormat.find_format,
297
 
                          _mod_transport.get_transport('.'))
 
268
                          get_transport('.'))
298
269
 
299
270
    def test_find_format_unknown_format(self):
300
 
        t = self.get_transport()
 
271
        t = get_transport(self.get_url())
301
272
        t.mkdir('.bzr')
302
273
        t.put_bytes('.bzr/branch-format', '')
303
274
        self.assertRaises(UnknownFormatError,
304
275
                          bzrdir.BzrDirFormat.find_format,
305
 
                          _mod_transport.get_transport('.'))
 
276
                          get_transport('.'))
306
277
 
307
278
    def test_register_unregister_format(self):
308
279
        format = SampleBzrDirFormat()
310
281
        # make a bzrdir
311
282
        format.initialize(url)
312
283
        # register a format for it.
313
 
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
 
284
        bzrdir.BzrDirFormat.register_format(format)
314
285
        # which bzrdir.Open will refuse (not supported)
315
286
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
316
287
        # which bzrdir.open_containing will refuse (not supported)
317
288
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
318
289
        # but open_downlevel will work
319
 
        t = _mod_transport.get_transport(url)
 
290
        t = get_transport(url)
320
291
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
321
292
        # unregister the format
322
 
        bzrdir.BzrProber.formats.remove(format.get_format_string())
 
293
        bzrdir.BzrDirFormat.unregister_format(format)
323
294
        # now open_downlevel should fail too.
324
295
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
325
296
 
502
473
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
503
474
        # Make stackable source branch with an unstackable repo format.
504
475
        source_bzrdir = self.make_bzrdir('source')
505
 
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
476
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
506
477
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
507
478
            source_bzrdir)
508
479
        # Make a directory with a default stacking policy
708
679
        self.assertEqual(relpath, 'baz')
709
680
 
710
681
    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')))
 
682
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
683
                          get_transport(self.get_readonly_url('')))
 
684
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
685
                          get_transport(self.get_readonly_url('g/p/q')))
717
686
        control = bzrdir.BzrDir.create(self.get_url())
718
687
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
719
 
            _mod_transport.get_transport(self.get_readonly_url('')))
 
688
            get_transport(self.get_readonly_url('')))
720
689
        self.assertEqual('', relpath)
721
690
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
722
 
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
 
691
            get_transport(self.get_readonly_url('g/p/q')))
723
692
        self.assertEqual('g/p/q', relpath)
724
693
 
725
694
    def test_open_containing_tree_or_branch(self):
769
738
        # transport pointing at bzrdir should give a bzrdir with root transport
770
739
        # set to the given transport
771
740
        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)
 
741
        transport = get_transport(self.get_url())
 
742
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
 
743
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
775
744
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
776
745
 
777
746
    def test_open_from_transport_no_bzrdir(self):
778
 
        t = self.get_transport()
779
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
 
747
        transport = get_transport(self.get_url())
 
748
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
 
749
                          transport)
780
750
 
781
751
    def test_open_from_transport_bzrdir_in_parent(self):
782
752
        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)
 
753
        transport = get_transport(self.get_url())
 
754
        transport.mkdir('subdir')
 
755
        transport = transport.clone('subdir')
 
756
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
 
757
                          transport)
787
758
 
788
759
    def test_sprout_recursive(self):
789
760
        tree = self.make_branch_and_tree('tree1',
798
769
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
799
770
        tree2.lock_read()
800
771
        self.addCleanup(tree2.unlock)
801
 
        self.assertPathExists('tree2/subtree/file')
 
772
        self.failUnlessExists('tree2/subtree/file')
802
773
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
803
774
 
804
775
    def test_cloning_metadir(self):
808
779
        branch = self.make_branch('branch', format='knit')
809
780
        format = branch.bzrdir.cloning_metadir()
810
781
        self.assertIsInstance(format.workingtree_format,
811
 
            workingtree_4.WorkingTreeFormat6)
 
782
            workingtree.WorkingTreeFormat3)
812
783
 
813
784
    def test_sprout_recursive_treeless(self):
814
785
        tree = self.make_branch_and_tree('tree1',
819
790
        self.build_tree(['tree1/subtree/file'])
820
791
        sub_tree.add('file')
821
792
        tree.commit('Initial commit')
822
 
        # The following line force the orhaning to reveal bug #634470
823
 
        tree.branch.get_config().set_user_option(
824
 
            'bzr.transform.orphan_policy', 'move')
825
793
        tree.bzrdir.destroy_workingtree()
826
 
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
827
 
        # fail :-( ) -- vila 20100909
828
794
        repo = self.make_repository('repo', shared=True,
829
795
            format='dirstate-with-subtree')
830
796
        repo.set_make_working_trees(False)
831
 
        # FIXME: we just deleted the workingtree and now we want to use it ????
832
 
        # At a minimum, we should use tree.branch below (but this fails too
833
 
        # currently) or stop calling this test 'treeless'. Specifically, I've
834
 
        # turn the line below into an assertRaises when 'subtree/.bzr' is
835
 
        # orphaned and sprout tries to access the branch there (which is left
836
 
        # by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
837
 
        # [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
838
 
        # #634470.  -- vila 20100909
839
 
        self.assertRaises(errors.NotBranchError,
840
 
                          tree.bzrdir.sprout, 'repo/tree2')
841
 
#        self.assertPathExists('repo/tree2/subtree')
842
 
#        self.assertPathDoesNotExist('repo/tree2/subtree/file')
 
797
        tree.bzrdir.sprout('repo/tree2')
 
798
        self.failUnlessExists('repo/tree2/subtree')
 
799
        self.failIfExists('repo/tree2/subtree/file')
843
800
 
844
801
    def make_foo_bar_baz(self):
845
802
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
849
806
 
850
807
    def test_find_bzrdirs(self):
851
808
        foo, bar, baz = self.make_foo_bar_baz()
852
 
        t = self.get_transport()
853
 
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
 
809
        transport = get_transport(self.get_url())
 
810
        self.assertEqualBzrdirs([baz, foo, bar],
 
811
                                bzrdir.BzrDir.find_bzrdirs(transport))
854
812
 
855
813
    def make_fake_permission_denied_transport(self, transport, paths):
856
814
        """Create a transport that raises PermissionDenied for some paths."""
872
830
 
873
831
    def test_find_bzrdirs_permission_denied(self):
874
832
        foo, bar, baz = self.make_foo_bar_baz()
875
 
        t = self.get_transport()
 
833
        transport = get_transport(self.get_url())
876
834
        path_filter_server, path_filter_transport = \
877
 
            self.make_fake_permission_denied_transport(t, ['foo'])
 
835
            self.make_fake_permission_denied_transport(transport, ['foo'])
878
836
        # local transport
879
837
        self.assertBranchUrlsEndWith('/baz/',
880
838
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
889
847
            return [s for s in transport.list_dir('') if s != 'baz']
890
848
 
891
849
        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))
 
850
        transport = get_transport(self.get_url())
 
851
        self.assertEqualBzrdirs([foo, bar],
 
852
                                bzrdir.BzrDir.find_bzrdirs(transport,
 
853
                                    list_current=list_current))
896
854
 
897
855
    def test_find_bzrdirs_evaluate(self):
898
856
        def evaluate(bzrdir):
904
862
                return False, bzrdir.root_transport.base
905
863
 
906
864
        foo, bar, baz = self.make_foo_bar_baz()
907
 
        t = self.get_transport()
 
865
        transport = get_transport(self.get_url())
908
866
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
909
 
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
 
867
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
 
868
                                                         evaluate=evaluate)))
910
869
 
911
870
    def assertEqualBzrdirs(self, first, second):
912
871
        first = list(first)
919
878
        root = self.make_repository('', shared=True)
920
879
        foo, bar, baz = self.make_foo_bar_baz()
921
880
        qux = self.make_bzrdir('foo/qux')
922
 
        t = self.get_transport()
923
 
        branches = bzrdir.BzrDir.find_branches(t)
 
881
        transport = get_transport(self.get_url())
 
882
        branches = bzrdir.BzrDir.find_branches(transport)
924
883
        self.assertEqual(baz.root_transport.base, branches[0].base)
925
884
        self.assertEqual(foo.root_transport.base, branches[1].base)
926
885
        self.assertEqual(bar.root_transport.base, branches[2].base)
927
886
 
928
887
        # ensure this works without a top-level repo
929
 
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
 
888
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
930
889
        self.assertEqual(foo.root_transport.base, branches[0].base)
931
890
        self.assertEqual(bar.root_transport.base, branches[1].base)
932
891
 
934
893
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
935
894
 
936
895
    def test_find_bzrdirs_missing_repo(self):
937
 
        t = self.get_transport()
 
896
        transport = get_transport(self.get_url())
938
897
        arepo = self.make_repository('arepo', shared=True)
939
898
        abranch_url = arepo.user_url + '/abranch'
940
899
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
941
 
        t.delete_tree('arepo/.bzr')
 
900
        transport.delete_tree('arepo/.bzr')
942
901
        self.assertRaises(errors.NoRepositoryPresent,
943
902
            branch.Branch.open, abranch_url)
944
903
        self.make_branch('baz')
945
 
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
 
904
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
946
905
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
947
906
 
948
907
 
958
917
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
959
918
        repository_base = t.clone('repository').base
960
919
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
961
 
        repository_format = repository.format_registry.get_default()
962
920
        self.assertEqual(repository_base,
963
 
                         dir.get_repository_transport(repository_format).base)
 
921
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
964
922
        checkout_base = t.clone('checkout').base
965
923
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
966
924
        self.assertEqual(checkout_base,
967
 
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
 
925
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
968
926
 
969
927
    def test_meta1dir_uses_lockdir(self):
970
928
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
1012
970
        self.assertEqual(2, rpc_count)
1013
971
 
1014
972
 
 
973
class TestFormat5(TestCaseWithTransport):
 
974
    """Tests specific to the version 5 bzrdir format."""
 
975
 
 
976
    def test_same_lockfiles_between_tree_repo_branch(self):
 
977
        # this checks that only a single lockfiles instance is created
 
978
        # for format 5 objects
 
979
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
980
        def check_dir_components_use_same_lock(dir):
 
981
            ctrl_1 = dir.open_repository().control_files
 
982
            ctrl_2 = dir.open_branch().control_files
 
983
            ctrl_3 = dir.open_workingtree()._control_files
 
984
            self.assertTrue(ctrl_1 is ctrl_2)
 
985
            self.assertTrue(ctrl_2 is ctrl_3)
 
986
        check_dir_components_use_same_lock(dir)
 
987
        # and if we open it normally.
 
988
        dir = bzrdir.BzrDir.open(self.get_url())
 
989
        check_dir_components_use_same_lock(dir)
 
990
 
 
991
    def test_can_convert(self):
 
992
        # format 5 dirs are convertable
 
993
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
994
        self.assertTrue(dir.can_convert_format())
 
995
 
 
996
    def test_needs_conversion(self):
 
997
        # format 5 dirs need a conversion if they are not the default,
 
998
        # and they aren't
 
999
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
1000
        # don't need to convert it to itself
 
1001
        self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
 
1002
        # do need to convert it to the current default
 
1003
        self.assertTrue(dir.needs_format_conversion(
 
1004
            bzrdir.BzrDirFormat.get_default_format()))
 
1005
 
 
1006
 
 
1007
class TestFormat6(TestCaseWithTransport):
 
1008
    """Tests specific to the version 6 bzrdir format."""
 
1009
 
 
1010
    def test_same_lockfiles_between_tree_repo_branch(self):
 
1011
        # this checks that only a single lockfiles instance is created
 
1012
        # for format 6 objects
 
1013
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1014
        def check_dir_components_use_same_lock(dir):
 
1015
            ctrl_1 = dir.open_repository().control_files
 
1016
            ctrl_2 = dir.open_branch().control_files
 
1017
            ctrl_3 = dir.open_workingtree()._control_files
 
1018
            self.assertTrue(ctrl_1 is ctrl_2)
 
1019
            self.assertTrue(ctrl_2 is ctrl_3)
 
1020
        check_dir_components_use_same_lock(dir)
 
1021
        # and if we open it normally.
 
1022
        dir = bzrdir.BzrDir.open(self.get_url())
 
1023
        check_dir_components_use_same_lock(dir)
 
1024
 
 
1025
    def test_can_convert(self):
 
1026
        # format 6 dirs are convertable
 
1027
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1028
        self.assertTrue(dir.can_convert_format())
 
1029
 
 
1030
    def test_needs_conversion(self):
 
1031
        # format 6 dirs need an conversion if they are not the default.
 
1032
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
1033
        self.assertTrue(dir.needs_format_conversion(
 
1034
            bzrdir.BzrDirFormat.get_default_format()))
 
1035
 
 
1036
 
 
1037
class NotBzrDir(bzrlib.bzrdir.BzrDir):
 
1038
    """A non .bzr based control directory."""
 
1039
 
 
1040
    def __init__(self, transport, format):
 
1041
        self._format = format
 
1042
        self.root_transport = transport
 
1043
        self.transport = transport.clone('.not')
 
1044
 
 
1045
 
 
1046
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
 
1047
    """A test class representing any non-.bzr based disk format."""
 
1048
 
 
1049
    def initialize_on_transport(self, transport):
 
1050
        """Initialize a new .not dir in the base directory of a Transport."""
 
1051
        transport.mkdir('.not')
 
1052
        return self.open(transport)
 
1053
 
 
1054
    def open(self, transport):
 
1055
        """Open this directory."""
 
1056
        return NotBzrDir(transport, self)
 
1057
 
 
1058
    @classmethod
 
1059
    def _known_formats(self):
 
1060
        return set([NotBzrDirFormat()])
 
1061
 
 
1062
 
 
1063
class NotBzrDirProber(controldir.Prober):
 
1064
 
 
1065
    def probe_transport(self, transport):
 
1066
        """Our format is present if the transport ends in '.not/'."""
 
1067
        if transport.has('.not'):
 
1068
            return NotBzrDirFormat()
 
1069
 
 
1070
 
 
1071
class TestNotBzrDir(TestCaseWithTransport):
 
1072
    """Tests for using the bzrdir api with a non .bzr based disk format.
 
1073
 
 
1074
    If/when one of these is in the core, we can let the implementation tests
 
1075
    verify this works.
 
1076
    """
 
1077
 
 
1078
    def test_create_and_find_format(self):
 
1079
        # create a .notbzr dir
 
1080
        format = NotBzrDirFormat()
 
1081
        dir = format.initialize(self.get_url())
 
1082
        self.assertIsInstance(dir, NotBzrDir)
 
1083
        # now probe for it.
 
1084
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
 
1085
        try:
 
1086
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
 
1087
                get_transport(self.get_url()))
 
1088
            self.assertIsInstance(found, NotBzrDirFormat)
 
1089
        finally:
 
1090
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
 
1091
 
 
1092
    def test_included_in_known_formats(self):
 
1093
        not_format = NotBzrDirFormat()
 
1094
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
 
1095
        try:
 
1096
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
 
1097
            for format in formats:
 
1098
                if isinstance(format, NotBzrDirFormat):
 
1099
                    return
 
1100
            self.fail("No NotBzrDirFormat in %s" % formats)
 
1101
        finally:
 
1102
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
 
1103
 
 
1104
 
1015
1105
class NonLocalTests(TestCaseWithTransport):
1016
1106
    """Tests for bzrdir static behaviour on non local paths."""
1017
1107
 
1036
1126
            self.get_url('foo'),
1037
1127
            force_new_tree=True,
1038
1128
            format=format)
1039
 
        t = self.get_transport()
 
1129
        t = get_transport(self.get_url('.'))
1040
1130
        self.assertFalse(t.has('foo'))
1041
1131
 
1042
1132
    def test_clone(self):
1058
1148
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1059
1149
        checkout_format = my_bzrdir.checkout_metadir()
1060
1150
        self.assertIsInstance(checkout_format.workingtree_format,
1061
 
                              workingtree_4.WorkingTreeFormat4)
 
1151
                              workingtree.WorkingTreeFormat3)
1062
1152
 
1063
1153
 
1064
1154
class TestHTTPRedirections(object):
1238
1328
    def copy_content_into(self, destination, revision_id=None):
1239
1329
        self.calls.append('copy_content_into')
1240
1330
 
1241
 
    def last_revision(self):
1242
 
        return _mod_revision.NULL_REVISION
1243
 
 
1244
1331
    def get_parent(self):
1245
1332
        return self._parent
1246
1333
 
1247
1334
    def set_parent(self, parent):
1248
1335
        self._parent = parent
1249
1336
 
1250
 
    def lock_read(self):
1251
 
        return lock.LogicalLockResult(self.unlock)
1252
 
 
1253
 
    def unlock(self):
1254
 
        return
1255
 
 
1256
1337
 
1257
1338
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1258
1339
 
1336
1417
 
1337
1418
 
1338
1419
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1339
 
    # FIXME: This may need to be unified with test_osutils.TestBackupNames or
1340
 
    # moved to per_bzrdir or per_transport for better coverage ?
1341
 
    # -- vila 20100909
1342
1420
 
1343
1421
    def setUp(self):
1344
1422
        super(TestGenerateBackupName, self).setUp()
1345
 
        self._transport = self.get_transport()
 
1423
        self._transport = get_transport(self.get_url())
1346
1424
        bzrdir.BzrDir.create(self.get_url(),
1347
1425
            possible_transports=[self._transport])
1348
1426
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1349
1427
 
1350
 
    def test_deprecated_generate_backup_name(self):
1351
 
        res = self.applyDeprecated(
1352
 
                symbol_versioning.deprecated_in((2, 3, 0)),
1353
 
                self._bzrdir.generate_backup_name, 'whatever')
1354
 
 
1355
1428
    def test_new(self):
1356
 
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
 
1429
        self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
1357
1430
 
1358
1431
    def test_exiting(self):
1359
1432
        self._transport.put_bytes("a.~1~", "some content")
1360
 
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1361
 
 
 
1433
        self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))