~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from StringIO import StringIO
23
23
 
 
24
from bzrlib import (
 
25
    help_topics,
 
26
    symbol_versioning,
 
27
    )
24
28
import bzrlib.branch
25
29
import bzrlib.bzrdir as bzrdir
26
30
import bzrlib.errors as errors
42
46
        old_format = bzrdir.BzrDirFormat.get_default_format()
43
47
        # default is BzrDirFormat6
44
48
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
45
 
        bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
 
49
        self.applyDeprecated(symbol_versioning.zero_fourteen, 
 
50
                             bzrdir.BzrDirFormat.set_default_format, 
 
51
                             SampleBzrDirFormat())
46
52
        # creating a bzr dir should now create an instrumented dir.
47
53
        try:
48
54
            result = bzrdir.BzrDir.create('memory:///')
49
55
            self.failUnless(isinstance(result, SampleBzrDir))
50
56
        finally:
51
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
57
            self.applyDeprecated(symbol_versioning.zero_fourteen,
 
58
                bzrdir.BzrDirFormat.set_default_format, old_format)
52
59
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
53
60
 
54
61
 
 
62
class TestFormatRegistry(TestCase):
 
63
 
 
64
    def make_format_registry(self):
 
65
        my_format_registry = bzrdir.BzrDirFormatRegistry()
 
66
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
 
67
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
 
68
            ' repositories', deprecated=True)
 
69
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir', 
 
70
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
 
71
        my_format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
 
72
            'Format using knits')
 
73
        my_format_registry.set_default('knit')
 
74
        my_format_registry.register_metadir('metaweave', 'RepositoryFormat7',
 
75
            'Transitional format in 0.8.  Slower than knit.', deprecated=True)
 
76
        my_format_registry.register_metadir('experimental-knit2', 
 
77
                                            'RepositoryFormatKnit2',
 
78
            'Experimental successor to knit.  Use at your own risk.')
 
79
        return my_format_registry
 
80
 
 
81
    def test_format_registry(self):
 
82
        my_format_registry = self.make_format_registry()
 
83
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
 
84
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
 
85
        my_bzrdir = my_format_registry.make_bzrdir('weave')
 
86
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
 
87
        my_bzrdir = my_format_registry.make_bzrdir('default')
 
88
        self.assertIsInstance(my_bzrdir.repository_format, 
 
89
            repository.RepositoryFormatKnit1)
 
90
        my_bzrdir = my_format_registry.make_bzrdir('knit')
 
91
        self.assertIsInstance(my_bzrdir.repository_format, 
 
92
            repository.RepositoryFormatKnit1)
 
93
        my_bzrdir = my_format_registry.make_bzrdir('metaweave')
 
94
        self.assertIsInstance(my_bzrdir.repository_format, 
 
95
            repository.RepositoryFormat7)
 
96
 
 
97
    def test_get_help(self):
 
98
        my_format_registry = self.make_format_registry()
 
99
        self.assertEqual('Format registered lazily',
 
100
                         my_format_registry.get_help('lazy'))
 
101
        self.assertEqual('Format using knits', 
 
102
                         my_format_registry.get_help('knit'))
 
103
        self.assertEqual('Format using knits', 
 
104
                         my_format_registry.get_help('default'))
 
105
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
 
106
                         ' checkouts or shared repositories', 
 
107
                         my_format_registry.get_help('weave'))
 
108
        
 
109
    def test_help_topic(self):
 
110
        topics = help_topics.HelpTopicRegistry()
 
111
        topics.register('formats', self.make_format_registry().help_topic, 
 
112
                        'Directory formats')
 
113
        topic = topics.get_detail('formats')
 
114
        new, deprecated = topic.split('Deprecated formats')
 
115
        self.assertContainsRe(new, 'Bazaar directory formats')
 
116
        self.assertContainsRe(new, 
 
117
            '  knit/default:\n    \(native\) Format using knits\n')
 
118
        self.assertContainsRe(deprecated, 
 
119
            '  lazy:\n    \(native\) Format registered lazily\n')
 
120
 
 
121
    def test_set_default_repository(self):
 
122
        default_factory = bzrdir.format_registry.get('default')
 
123
        old_default = [k for k, v in bzrdir.format_registry.iteritems()
 
124
                       if v == default_factory and k != 'default'][0]
 
125
        bzrdir.format_registry.set_default_repository('metaweave')
 
126
        try:
 
127
            self.assertIs(bzrdir.format_registry.get('metaweave'),
 
128
                          bzrdir.format_registry.get('default'))
 
129
            self.assertIs(
 
130
                repository.RepositoryFormat.get_default_format().__class__,
 
131
                repository.RepositoryFormat7)
 
132
        finally:
 
133
            bzrdir.format_registry.set_default_repository(old_default)
 
134
 
55
135
class SampleBranch(bzrlib.branch.Branch):
56
136
    """A dummy branch for guess what, dummy use."""
57
137
 
155
235
 
156
236
    def test_create_repository(self):
157
237
        format = SampleBzrDirFormat()
158
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
159
 
        bzrdir.BzrDirFormat.set_default_format(format)
160
 
        try:
161
 
            repo = bzrdir.BzrDir.create_repository(self.get_url())
162
 
            self.assertEqual('A repository', repo)
163
 
        finally:
164
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
238
        repo = bzrdir.BzrDir.create_repository(self.get_url(), format=format)
 
239
        self.assertEqual('A repository', repo)
165
240
 
166
241
    def test_create_repository_shared(self):
167
242
        old_format = bzrdir.BzrDirFormat.get_default_format()
176
251
    def test_create_repository_under_shared(self):
177
252
        # an explicit create_repository always does so.
178
253
        # we trust the format is right from the 'create_repository test'
179
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
180
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
181
 
        try:
182
 
            self.make_repository('.', shared=True)
183
 
            repo = bzrdir.BzrDir.create_repository(self.get_url('child'))
184
 
            self.assertTrue(isinstance(repo, repository.Repository))
185
 
            self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
186
 
        finally:
187
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
254
        format = bzrdir.format_registry.make_bzrdir('knit')
 
255
        self.make_repository('.', shared=True, format=format)
 
256
        repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
 
257
                                               format=format)
 
258
        self.assertTrue(isinstance(repo, repository.Repository))
 
259
        self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
188
260
 
189
261
    def test_create_branch_and_repo_uses_default(self):
190
262
        format = SampleBzrDirFormat()
191
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
192
 
        bzrdir.BzrDirFormat.set_default_format(format)
193
 
        try:
194
 
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url())
195
 
            self.assertTrue(isinstance(branch, SampleBranch))
196
 
        finally:
197
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
263
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(), 
 
264
                                                      format=format)
 
265
        self.assertTrue(isinstance(branch, SampleBranch))
198
266
 
199
267
    def test_create_branch_and_repo_under_shared(self):
200
268
        # creating a branch and repo in a shared repo uses the
201
269
        # shared repository
202
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
203
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
204
 
        try:
205
 
            self.make_repository('.', shared=True)
206
 
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'))
207
 
            self.assertRaises(errors.NoRepositoryPresent,
208
 
                              branch.bzrdir.open_repository)
209
 
        finally:
210
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
270
        format = bzrdir.format_registry.make_bzrdir('knit')
 
271
        self.make_repository('.', shared=True, format=format)
 
272
        branch = bzrdir.BzrDir.create_branch_and_repo(
 
273
            self.get_url('child'), format=format)
 
274
        self.assertRaises(errors.NoRepositoryPresent,
 
275
                          branch.bzrdir.open_repository)
211
276
 
212
277
    def test_create_branch_and_repo_under_shared_force_new(self):
213
278
        # creating a branch and repo in a shared repo can be forced to 
214
279
        # make a new repo
215
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
216
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
217
 
        try:
218
 
            self.make_repository('.', shared=True)
219
 
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
220
 
                                                          force_new_repo=True)
221
 
            branch.bzrdir.open_repository()
222
 
        finally:
223
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
280
        format = bzrdir.format_registry.make_bzrdir('knit')
 
281
        self.make_repository('.', shared=True, format=format)
 
282
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
 
283
                                                      force_new_repo=True,
 
284
                                                      format=format)
 
285
        branch.bzrdir.open_repository()
224
286
 
225
287
    def test_create_standalone_working_tree(self):
226
288
        format = SampleBzrDirFormat()
227
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
228
 
        bzrdir.BzrDirFormat.set_default_format(format)
229
 
        try:
230
 
            # note this is deliberately readonly, as this failure should 
231
 
            # occur before any writes.
232
 
            self.assertRaises(errors.NotLocalUrl,
233
 
                              bzrdir.BzrDir.create_standalone_workingtree,
234
 
                              self.get_readonly_url())
235
 
            tree = bzrdir.BzrDir.create_standalone_workingtree('.')
236
 
            self.assertEqual('A tree', tree)
237
 
        finally:
238
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
289
        # note this is deliberately readonly, as this failure should 
 
290
        # occur before any writes.
 
291
        self.assertRaises(errors.NotLocalUrl,
 
292
                          bzrdir.BzrDir.create_standalone_workingtree,
 
293
                          self.get_readonly_url(), format=format)
 
294
        tree = bzrdir.BzrDir.create_standalone_workingtree('.', 
 
295
                                                           format=format)
 
296
        self.assertEqual('A tree', tree)
239
297
 
240
298
    def test_create_standalone_working_tree_under_shared_repo(self):
241
299
        # create standalone working tree always makes a repo.
242
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
243
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
244
 
        try:
245
 
            self.make_repository('.', shared=True)
246
 
            # note this is deliberately readonly, as this failure should 
247
 
            # occur before any writes.
248
 
            self.assertRaises(errors.NotLocalUrl,
249
 
                              bzrdir.BzrDir.create_standalone_workingtree,
250
 
                              self.get_readonly_url('child'))
251
 
            tree = bzrdir.BzrDir.create_standalone_workingtree('child')
252
 
            tree.bzrdir.open_repository()
253
 
        finally:
254
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
300
        format = bzrdir.format_registry.make_bzrdir('knit')
 
301
        self.make_repository('.', shared=True, format=format)
 
302
        # note this is deliberately readonly, as this failure should 
 
303
        # occur before any writes.
 
304
        self.assertRaises(errors.NotLocalUrl,
 
305
                          bzrdir.BzrDir.create_standalone_workingtree,
 
306
                          self.get_readonly_url('child'), format=format)
 
307
        tree = bzrdir.BzrDir.create_standalone_workingtree('child', 
 
308
            format=format)
 
309
        tree.bzrdir.open_repository()
255
310
 
256
311
    def test_create_branch_convenience(self):
257
312
        # outside a repo the default convenience output is a repo+branch_tree
258
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
259
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
260
 
        try:
261
 
            branch = bzrdir.BzrDir.create_branch_convenience('.')
262
 
            branch.bzrdir.open_workingtree()
263
 
            branch.bzrdir.open_repository()
264
 
        finally:
265
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
313
        format = bzrdir.format_registry.make_bzrdir('knit')
 
314
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
 
315
        branch.bzrdir.open_workingtree()
 
316
        branch.bzrdir.open_repository()
266
317
 
267
318
    def test_create_branch_convenience_root(self):
268
319
        """Creating a branch at the root of a fs should work."""
269
320
        self.transport_server = MemoryServer
270
321
        # outside a repo the default convenience output is a repo+branch_tree
271
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
272
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
273
 
        try:
274
 
            branch = bzrdir.BzrDir.create_branch_convenience(self.get_url())
275
 
            self.assertRaises(errors.NoWorkingTree,
276
 
                              branch.bzrdir.open_workingtree)
277
 
            branch.bzrdir.open_repository()
278
 
        finally:
279
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
322
        format = bzrdir.format_registry.make_bzrdir('knit')
 
323
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(), 
 
324
                                                         format=format)
 
325
        self.assertRaises(errors.NoWorkingTree,
 
326
                          branch.bzrdir.open_workingtree)
 
327
        branch.bzrdir.open_repository()
280
328
 
281
329
    def test_create_branch_convenience_under_shared_repo(self):
282
330
        # inside a repo the default convenience output is a branch+ follow the
283
331
        # repo tree policy
284
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
285
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
286
 
        try:
287
 
            self.make_repository('.', shared=True)
288
 
            branch = bzrdir.BzrDir.create_branch_convenience('child')
289
 
            branch.bzrdir.open_workingtree()
290
 
            self.assertRaises(errors.NoRepositoryPresent,
291
 
                              branch.bzrdir.open_repository)
292
 
        finally:
293
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
332
        format = bzrdir.format_registry.make_bzrdir('knit')
 
333
        self.make_repository('.', shared=True, format=format)
 
334
        branch = bzrdir.BzrDir.create_branch_convenience('child',
 
335
            format=format)
 
336
        branch.bzrdir.open_workingtree()
 
337
        self.assertRaises(errors.NoRepositoryPresent,
 
338
                          branch.bzrdir.open_repository)
294
339
            
295
340
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
296
341
        # inside a repo the default convenience output is a branch+ follow the
297
342
        # repo tree policy but we can override that
298
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
299
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
300
 
        try:
301
 
            self.make_repository('.', shared=True)
302
 
            branch = bzrdir.BzrDir.create_branch_convenience('child',
303
 
                force_new_tree=False)
304
 
            self.assertRaises(errors.NoWorkingTree,
305
 
                              branch.bzrdir.open_workingtree)
306
 
            self.assertRaises(errors.NoRepositoryPresent,
307
 
                              branch.bzrdir.open_repository)
308
 
        finally:
309
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
343
        format = bzrdir.format_registry.make_bzrdir('knit')
 
344
        self.make_repository('.', shared=True, format=format)
 
345
        branch = bzrdir.BzrDir.create_branch_convenience('child',
 
346
            force_new_tree=False, format=format)
 
347
        self.assertRaises(errors.NoWorkingTree,
 
348
                          branch.bzrdir.open_workingtree)
 
349
        self.assertRaises(errors.NoRepositoryPresent,
 
350
                          branch.bzrdir.open_repository)
310
351
            
311
352
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
312
353
        # inside a repo the default convenience output is a branch+ follow the
313
354
        # repo tree policy
314
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
315
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
316
 
        try:
317
 
            repo = self.make_repository('.', shared=True)
318
 
            repo.set_make_working_trees(False)
319
 
            branch = bzrdir.BzrDir.create_branch_convenience('child')
320
 
            self.assertRaises(errors.NoWorkingTree,
321
 
                              branch.bzrdir.open_workingtree)
322
 
            self.assertRaises(errors.NoRepositoryPresent,
323
 
                              branch.bzrdir.open_repository)
324
 
        finally:
325
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
355
        format = bzrdir.format_registry.make_bzrdir('knit')
 
356
        repo = self.make_repository('.', shared=True, format=format)
 
357
        repo.set_make_working_trees(False)
 
358
        branch = bzrdir.BzrDir.create_branch_convenience('child', 
 
359
                                                         format=format)
 
360
        self.assertRaises(errors.NoWorkingTree,
 
361
                          branch.bzrdir.open_workingtree)
 
362
        self.assertRaises(errors.NoRepositoryPresent,
 
363
                          branch.bzrdir.open_repository)
326
364
 
327
365
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
328
366
        # inside a repo the default convenience output is a branch+ follow the
329
367
        # repo tree policy but we can override that
330
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
331
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
332
 
        try:
333
 
            repo = self.make_repository('.', shared=True)
334
 
            repo.set_make_working_trees(False)
335
 
            branch = bzrdir.BzrDir.create_branch_convenience('child',
336
 
                force_new_tree=True)
337
 
            branch.bzrdir.open_workingtree()
338
 
            self.assertRaises(errors.NoRepositoryPresent,
339
 
                              branch.bzrdir.open_repository)
340
 
        finally:
341
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
368
        format = bzrdir.format_registry.make_bzrdir('knit')
 
369
        repo = self.make_repository('.', shared=True, format=format)
 
370
        repo.set_make_working_trees(False)
 
371
        branch = bzrdir.BzrDir.create_branch_convenience('child',
 
372
            force_new_tree=True, format=format)
 
373
        branch.bzrdir.open_workingtree()
 
374
        self.assertRaises(errors.NoRepositoryPresent,
 
375
                          branch.bzrdir.open_repository)
342
376
 
343
377
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
344
378
        # inside a repo the default convenience output is overridable to give
345
379
        # repo+branch+tree
346
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
347
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
348
 
        try:
349
 
            self.make_repository('.', shared=True)
350
 
            branch = bzrdir.BzrDir.create_branch_convenience('child',
351
 
                force_new_repo=True)
352
 
            branch.bzrdir.open_repository()
353
 
            branch.bzrdir.open_workingtree()
354
 
        finally:
355
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
380
        format = bzrdir.format_registry.make_bzrdir('knit')
 
381
        self.make_repository('.', shared=True, format=format)
 
382
        branch = bzrdir.BzrDir.create_branch_convenience('child',
 
383
            force_new_repo=True, format=format)
 
384
        branch.bzrdir.open_repository()
 
385
        branch.bzrdir.open_workingtree()
356
386
 
357
387
 
358
388
class ChrootedTests(TestCaseWithTransport):
468
498
        # format 5 dirs need a conversion if they are not the default.
469
499
        # and they start of not the default.
470
500
        old_format = bzrdir.BzrDirFormat.get_default_format()
471
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
501
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
472
502
        try:
473
503
            dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
474
504
            self.assertFalse(dir.needs_format_conversion())
475
505
        finally:
476
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
506
            bzrdir.BzrDirFormat._set_default_format(old_format)
477
507
        self.assertTrue(dir.needs_format_conversion())
478
508
 
479
509
 
503
533
    def test_needs_conversion(self):
504
534
        # format 6 dirs need an conversion if they are not the default.
505
535
        old_format = bzrdir.BzrDirFormat.get_default_format()
506
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
536
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
507
537
        try:
508
538
            dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
509
539
            self.assertTrue(dir.needs_format_conversion())
510
540
        finally:
511
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
541
            bzrdir.BzrDirFormat._set_default_format(old_format)
512
542
 
513
543
 
514
544
class NotBzrDir(bzrlib.bzrdir.BzrDir):
585
615
    
586
616
    def test_create_branch_convenience(self):
587
617
        # outside a repo the default convenience output is a repo+branch_tree
588
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
589
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
590
 
        try:
591
 
            branch = bzrdir.BzrDir.create_branch_convenience(self.get_url('foo'))
592
 
            self.assertRaises(errors.NoWorkingTree,
593
 
                              branch.bzrdir.open_workingtree)
594
 
            branch.bzrdir.open_repository()
595
 
        finally:
596
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
618
        format = bzrdir.format_registry.make_bzrdir('knit')
 
619
        branch = bzrdir.BzrDir.create_branch_convenience(
 
620
            self.get_url('foo'), format=format)
 
621
        self.assertRaises(errors.NoWorkingTree,
 
622
                          branch.bzrdir.open_workingtree)
 
623
        branch.bzrdir.open_repository()
597
624
 
598
625
    def test_create_branch_convenience_force_tree_not_local_fails(self):
599
626
        # outside a repo the default convenience output is a repo+branch_tree
600
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
601
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
602
 
        try:
603
 
            self.assertRaises(errors.NotLocalUrl,
604
 
                bzrdir.BzrDir.create_branch_convenience,
605
 
                self.get_url('foo'),
606
 
                force_new_tree=True)
607
 
            t = get_transport(self.get_url('.'))
608
 
            self.assertFalse(t.has('foo'))
609
 
        finally:
610
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
627
        format = bzrdir.format_registry.make_bzrdir('knit')
 
628
        self.assertRaises(errors.NotLocalUrl,
 
629
            bzrdir.BzrDir.create_branch_convenience,
 
630
            self.get_url('foo'),
 
631
            force_new_tree=True,
 
632
            format=format)
 
633
        t = get_transport(self.get_url('.'))
 
634
        self.assertFalse(t.has('foo'))
611
635
 
612
636
    def test_clone(self):
613
637
        # clone into a nonlocal path works
614
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
615
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
616
 
        try:
617
 
            branch = bzrdir.BzrDir.create_branch_convenience('local')
618
 
        finally:
619
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
638
        format = bzrdir.format_registry.make_bzrdir('knit')
 
639
        branch = bzrdir.BzrDir.create_branch_convenience('local',
 
640
                                                         format=format)
620
641
        branch.bzrdir.open_workingtree()
621
642
        result = branch.bzrdir.clone(self.get_url('remote'))
622
643
        self.assertRaises(errors.NoWorkingTree,