49
42
old_format = bzrdir.BzrDirFormat.get_default_format()
50
43
# default is BzrDirFormat6
51
44
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
52
self.applyDeprecated(symbol_versioning.zero_fourteen,
53
bzrdir.BzrDirFormat.set_default_format,
45
bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
55
46
# creating a bzr dir should now create an instrumented dir.
57
48
result = bzrdir.BzrDir.create('memory:///')
58
49
self.failUnless(isinstance(result, SampleBzrDir))
60
self.applyDeprecated(symbol_versioning.zero_fourteen,
61
bzrdir.BzrDirFormat.set_default_format, old_format)
51
bzrdir.BzrDirFormat.set_default_format(old_format)
62
52
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
65
class TestFormatRegistry(TestCase):
67
def make_format_registry(self):
68
my_format_registry = bzrdir.BzrDirFormatRegistry()
69
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
70
'Pre-0.8 format. Slower and does not support checkouts or shared'
71
' repositories', deprecated=True)
72
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
73
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
74
my_format_registry.register_metadir('knit',
75
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
78
my_format_registry.set_default('knit')
79
my_format_registry.register_metadir(
81
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
82
'Experimental successor to knit. Use at your own risk.',
83
branch_format='bzrlib.branch.BzrBranchFormat6')
84
return my_format_registry
86
def test_format_registry(self):
87
my_format_registry = self.make_format_registry()
88
my_bzrdir = my_format_registry.make_bzrdir('lazy')
89
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
90
my_bzrdir = my_format_registry.make_bzrdir('weave')
91
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
92
my_bzrdir = my_format_registry.make_bzrdir('default')
93
self.assertIsInstance(my_bzrdir.repository_format,
94
knitrepo.RepositoryFormatKnit1)
95
my_bzrdir = my_format_registry.make_bzrdir('knit')
96
self.assertIsInstance(my_bzrdir.repository_format,
97
knitrepo.RepositoryFormatKnit1)
98
my_bzrdir = my_format_registry.make_bzrdir('branch6')
99
self.assertIsInstance(my_bzrdir.get_branch_format(),
100
bzrlib.branch.BzrBranchFormat6)
102
def test_get_help(self):
103
my_format_registry = self.make_format_registry()
104
self.assertEqual('Format registered lazily',
105
my_format_registry.get_help('lazy'))
106
self.assertEqual('Format using knits',
107
my_format_registry.get_help('knit'))
108
self.assertEqual('Format using knits',
109
my_format_registry.get_help('default'))
110
self.assertEqual('Pre-0.8 format. Slower and does not support'
111
' checkouts or shared repositories',
112
my_format_registry.get_help('weave'))
114
def test_help_topic(self):
115
topics = help_topics.HelpTopicRegistry()
116
topics.register('formats', self.make_format_registry().help_topic,
118
topic = topics.get_detail('formats')
119
new, deprecated = topic.split('Deprecated formats')
120
self.assertContainsRe(new, 'Bazaar directory formats')
121
self.assertContainsRe(new,
122
' knit/default:\n \(native\) Format using knits\n')
123
self.assertContainsRe(deprecated,
124
' lazy:\n \(native\) Format registered lazily\n')
126
def test_set_default_repository(self):
127
default_factory = bzrdir.format_registry.get('default')
128
old_default = [k for k, v in bzrdir.format_registry.iteritems()
129
if v == default_factory and k != 'default'][0]
130
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
132
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
133
bzrdir.format_registry.get('default'))
135
repository.RepositoryFormat.get_default_format().__class__,
136
knitrepo.RepositoryFormatKnit3)
138
bzrdir.format_registry.set_default_repository(old_default)
141
55
class SampleBranch(bzrlib.branch.Branch):
142
56
"""A dummy branch for guess what, dummy use."""
257
176
def test_create_repository_under_shared(self):
258
177
# an explicit create_repository always does so.
259
178
# we trust the format is right from the 'create_repository test'
260
format = bzrdir.format_registry.make_bzrdir('knit')
261
self.make_repository('.', shared=True, format=format)
262
repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
264
self.assertTrue(isinstance(repo, repository.Repository))
265
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
179
old_format = bzrdir.BzrDirFormat.get_default_format()
180
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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/'))
187
bzrdir.BzrDirFormat.set_default_format(old_format)
267
189
def test_create_branch_and_repo_uses_default(self):
268
190
format = SampleBzrDirFormat()
269
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
271
self.assertTrue(isinstance(branch, SampleBranch))
191
old_format = bzrdir.BzrDirFormat.get_default_format()
192
bzrdir.BzrDirFormat.set_default_format(format)
194
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url())
195
self.assertTrue(isinstance(branch, SampleBranch))
197
bzrdir.BzrDirFormat.set_default_format(old_format)
273
199
def test_create_branch_and_repo_under_shared(self):
274
200
# creating a branch and repo in a shared repo uses the
275
201
# shared repository
276
format = bzrdir.format_registry.make_bzrdir('knit')
277
self.make_repository('.', shared=True, format=format)
278
branch = bzrdir.BzrDir.create_branch_and_repo(
279
self.get_url('child'), format=format)
280
self.assertRaises(errors.NoRepositoryPresent,
281
branch.bzrdir.open_repository)
202
old_format = bzrdir.BzrDirFormat.get_default_format()
203
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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)
210
bzrdir.BzrDirFormat.set_default_format(old_format)
283
212
def test_create_branch_and_repo_under_shared_force_new(self):
284
213
# creating a branch and repo in a shared repo can be forced to
285
214
# make a new repo
286
format = bzrdir.format_registry.make_bzrdir('knit')
287
self.make_repository('.', shared=True, format=format)
288
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
291
branch.bzrdir.open_repository()
215
old_format = bzrdir.BzrDirFormat.get_default_format()
216
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
218
self.make_repository('.', shared=True)
219
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
221
branch.bzrdir.open_repository()
223
bzrdir.BzrDirFormat.set_default_format(old_format)
293
225
def test_create_standalone_working_tree(self):
294
226
format = SampleBzrDirFormat()
295
# note this is deliberately readonly, as this failure should
296
# occur before any writes.
297
self.assertRaises(errors.NotLocalUrl,
298
bzrdir.BzrDir.create_standalone_workingtree,
299
self.get_readonly_url(), format=format)
300
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
302
self.assertEqual('A tree', tree)
227
old_format = bzrdir.BzrDirFormat.get_default_format()
228
bzrdir.BzrDirFormat.set_default_format(format)
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)
238
bzrdir.BzrDirFormat.set_default_format(old_format)
304
240
def test_create_standalone_working_tree_under_shared_repo(self):
305
241
# create standalone working tree always makes a repo.
306
format = bzrdir.format_registry.make_bzrdir('knit')
307
self.make_repository('.', shared=True, format=format)
308
# note this is deliberately readonly, as this failure should
309
# occur before any writes.
310
self.assertRaises(errors.NotLocalUrl,
311
bzrdir.BzrDir.create_standalone_workingtree,
312
self.get_readonly_url('child'), format=format)
313
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
315
tree.bzrdir.open_repository()
242
old_format = bzrdir.BzrDirFormat.get_default_format()
243
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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()
254
bzrdir.BzrDirFormat.set_default_format(old_format)
317
256
def test_create_branch_convenience(self):
318
257
# outside a repo the default convenience output is a repo+branch_tree
319
format = bzrdir.format_registry.make_bzrdir('knit')
320
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
321
branch.bzrdir.open_workingtree()
322
branch.bzrdir.open_repository()
258
old_format = bzrdir.BzrDirFormat.get_default_format()
259
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
261
branch = bzrdir.BzrDir.create_branch_convenience('.')
262
branch.bzrdir.open_workingtree()
263
branch.bzrdir.open_repository()
265
bzrdir.BzrDirFormat.set_default_format(old_format)
324
267
def test_create_branch_convenience_root(self):
325
268
"""Creating a branch at the root of a fs should work."""
326
269
self.transport_server = MemoryServer
327
270
# outside a repo the default convenience output is a repo+branch_tree
328
format = bzrdir.format_registry.make_bzrdir('knit')
329
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
331
self.assertRaises(errors.NoWorkingTree,
332
branch.bzrdir.open_workingtree)
333
branch.bzrdir.open_repository()
271
old_format = bzrdir.BzrDirFormat.get_default_format()
272
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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()
279
bzrdir.BzrDirFormat.set_default_format(old_format)
335
281
def test_create_branch_convenience_under_shared_repo(self):
336
282
# inside a repo the default convenience output is a branch+ follow the
337
283
# repo tree policy
338
format = bzrdir.format_registry.make_bzrdir('knit')
339
self.make_repository('.', shared=True, format=format)
340
branch = bzrdir.BzrDir.create_branch_convenience('child',
342
branch.bzrdir.open_workingtree()
343
self.assertRaises(errors.NoRepositoryPresent,
344
branch.bzrdir.open_repository)
284
old_format = bzrdir.BzrDirFormat.get_default_format()
285
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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)
293
bzrdir.BzrDirFormat.set_default_format(old_format)
346
295
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
347
296
# inside a repo the default convenience output is a branch+ follow the
348
297
# repo tree policy but we can override that
349
format = bzrdir.format_registry.make_bzrdir('knit')
350
self.make_repository('.', shared=True, format=format)
351
branch = bzrdir.BzrDir.create_branch_convenience('child',
352
force_new_tree=False, format=format)
353
self.assertRaises(errors.NoWorkingTree,
354
branch.bzrdir.open_workingtree)
355
self.assertRaises(errors.NoRepositoryPresent,
356
branch.bzrdir.open_repository)
298
old_format = bzrdir.BzrDirFormat.get_default_format()
299
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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)
309
bzrdir.BzrDirFormat.set_default_format(old_format)
358
311
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
359
312
# inside a repo the default convenience output is a branch+ follow the
360
313
# repo tree policy
361
format = bzrdir.format_registry.make_bzrdir('knit')
362
repo = self.make_repository('.', shared=True, format=format)
363
repo.set_make_working_trees(False)
364
branch = bzrdir.BzrDir.create_branch_convenience('child',
366
self.assertRaises(errors.NoWorkingTree,
367
branch.bzrdir.open_workingtree)
368
self.assertRaises(errors.NoRepositoryPresent,
369
branch.bzrdir.open_repository)
314
old_format = bzrdir.BzrDirFormat.get_default_format()
315
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
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)
325
bzrdir.BzrDirFormat.set_default_format(old_format)
371
327
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
372
328
# inside a repo the default convenience output is a branch+ follow the
373
329
# repo tree policy but we can override that
374
format = bzrdir.format_registry.make_bzrdir('knit')
375
repo = self.make_repository('.', shared=True, format=format)
376
repo.set_make_working_trees(False)
377
branch = bzrdir.BzrDir.create_branch_convenience('child',
378
force_new_tree=True, format=format)
379
branch.bzrdir.open_workingtree()
380
self.assertRaises(errors.NoRepositoryPresent,
381
branch.bzrdir.open_repository)
330
old_format = bzrdir.BzrDirFormat.get_default_format()
331
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
333
repo = self.make_repository('.', shared=True)
334
repo.set_make_working_trees(False)
335
branch = bzrdir.BzrDir.create_branch_convenience('child',
337
branch.bzrdir.open_workingtree()
338
self.assertRaises(errors.NoRepositoryPresent,
339
branch.bzrdir.open_repository)
341
bzrdir.BzrDirFormat.set_default_format(old_format)
383
343
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
384
344
# inside a repo the default convenience output is overridable to give
385
345
# repo+branch+tree
386
format = bzrdir.format_registry.make_bzrdir('knit')
387
self.make_repository('.', shared=True, format=format)
388
branch = bzrdir.BzrDir.create_branch_convenience('child',
389
force_new_repo=True, format=format)
390
branch.bzrdir.open_repository()
391
branch.bzrdir.open_workingtree()
346
old_format = bzrdir.BzrDirFormat.get_default_format()
347
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
349
self.make_repository('.', shared=True)
350
branch = bzrdir.BzrDir.create_branch_convenience('child',
352
branch.bzrdir.open_repository()
353
branch.bzrdir.open_workingtree()
355
bzrdir.BzrDirFormat.set_default_format(old_format)
394
358
class ChrootedTests(TestCaseWithTransport):