~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2010-08-18 07:25:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5383.
  • Revision ID: mbp@sourcefrog.net-20100818072522-uk3gsazoia3l3s0a
Start adding 'what's new in 2.3'

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