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,
46
52
# creating a bzr dir should now create an instrumented dir.
48
54
result = bzrdir.BzrDir.create('memory:///')
49
55
self.failUnless(isinstance(result, SampleBzrDir))
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())
62
class TestFormatRegistry(TestCase):
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',
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
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)
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'))
109
def test_help_topic(self):
110
topics = help_topics.HelpTopicRegistry()
111
topics.register('formats', self.make_format_registry().help_topic,
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')
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')
127
self.assertIs(bzrdir.format_registry.get('metaweave'),
128
bzrdir.format_registry.get('default'))
130
repository.RepositoryFormat.get_default_format().__class__,
131
repository.RepositoryFormat7)
133
bzrdir.format_registry.set_default_repository(old_default)
55
135
class SampleBranch(bzrlib.branch.Branch):
56
136
"""A dummy branch for guess what, dummy use."""
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())
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)
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'),
258
self.assertTrue(isinstance(repo, repository.Repository))
259
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
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)
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)
263
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
265
self.assertTrue(isinstance(branch, SampleBranch))
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())
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)
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)
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())
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)
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'),
285
branch.bzrdir.open_repository()
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)
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)
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('.',
296
self.assertEqual('A tree', tree)
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())
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)
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',
309
tree.bzrdir.open_repository()
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())
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)
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()
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())
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)
322
format = bzrdir.format_registry.make_bzrdir('knit')
323
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
325
self.assertRaises(errors.NoWorkingTree,
326
branch.bzrdir.open_workingtree)
327
branch.bzrdir.open_repository()
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())
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)
332
format = bzrdir.format_registry.make_bzrdir('knit')
333
self.make_repository('.', shared=True, format=format)
334
branch = bzrdir.BzrDir.create_branch_convenience('child',
336
branch.bzrdir.open_workingtree()
337
self.assertRaises(errors.NoRepositoryPresent,
338
branch.bzrdir.open_repository)
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())
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)
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)
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())
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)
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',
360
self.assertRaises(errors.NoWorkingTree,
361
branch.bzrdir.open_workingtree)
362
self.assertRaises(errors.NoRepositoryPresent,
363
branch.bzrdir.open_repository)
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())
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)
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)
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())
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)
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()
358
388
class ChrootedTests(TestCaseWithTransport):