42
48
old_format = bzrdir.BzrDirFormat.get_default_format()
43
49
# default is BzrDirFormat6
44
50
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
45
bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
51
self.applyDeprecated(symbol_versioning.zero_fourteen,
52
bzrdir.BzrDirFormat.set_default_format,
46
54
# creating a bzr dir should now create an instrumented dir.
48
56
result = bzrdir.BzrDir.create('memory:///')
49
57
self.failUnless(isinstance(result, SampleBzrDir))
51
bzrdir.BzrDirFormat.set_default_format(old_format)
59
self.applyDeprecated(symbol_versioning.zero_fourteen,
60
bzrdir.BzrDirFormat.set_default_format, old_format)
52
61
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
64
class TestFormatRegistry(TestCase):
66
def make_format_registry(self):
67
my_format_registry = bzrdir.BzrDirFormatRegistry()
68
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
69
'Pre-0.8 format. Slower and does not support checkouts or shared'
70
' repositories', deprecated=True)
71
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
72
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
73
my_format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
75
my_format_registry.set_default('knit')
76
my_format_registry.register_metadir('metaweave', 'RepositoryFormat7',
77
'Transitional format in 0.8. Slower than knit.', deprecated=True)
78
my_format_registry.register_metadir('experimental-knit2',
79
'RepositoryFormatKnit2',
80
'Experimental successor to knit. Use at your own risk.')
81
return my_format_registry
83
def test_format_registry(self):
84
my_format_registry = self.make_format_registry()
85
my_bzrdir = my_format_registry.make_bzrdir('lazy')
86
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
87
my_bzrdir = my_format_registry.make_bzrdir('weave')
88
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
89
my_bzrdir = my_format_registry.make_bzrdir('default')
90
self.assertIsInstance(my_bzrdir.repository_format,
91
repository.RepositoryFormatKnit1)
92
my_bzrdir = my_format_registry.make_bzrdir('knit')
93
self.assertIsInstance(my_bzrdir.repository_format,
94
repository.RepositoryFormatKnit1)
95
my_bzrdir = my_format_registry.make_bzrdir('metaweave')
96
self.assertIsInstance(my_bzrdir.repository_format,
97
repository.RepositoryFormat7)
99
def test_get_help(self):
100
my_format_registry = self.make_format_registry()
101
self.assertEqual('Format registered lazily',
102
my_format_registry.get_help('lazy'))
103
self.assertEqual('Format using knits',
104
my_format_registry.get_help('knit'))
105
self.assertEqual('Format using knits',
106
my_format_registry.get_help('default'))
107
self.assertEqual('Pre-0.8 format. Slower and does not support'
108
' checkouts or shared repositories',
109
my_format_registry.get_help('weave'))
111
def test_help_topic(self):
112
topics = help_topics.HelpTopicRegistry()
113
topics.register('formats', self.make_format_registry().help_topic,
115
topic = topics.get_detail('formats')
116
new, deprecated = topic.split('Deprecated formats')
117
self.assertContainsRe(new, 'Bazaar directory formats')
118
self.assertContainsRe(new,
119
' knit/default:\n \(native\) Format using knits\n')
120
self.assertContainsRe(deprecated,
121
' lazy:\n \(native\) Format registered lazily\n')
123
def test_set_default_repository(self):
124
default_factory = bzrdir.format_registry.get('default')
125
old_default = [k for k, v in bzrdir.format_registry.iteritems()
126
if v == default_factory and k != 'default'][0]
127
bzrdir.format_registry.set_default_repository('metaweave')
129
self.assertIs(bzrdir.format_registry.get('metaweave'),
130
bzrdir.format_registry.get('default'))
132
repository.RepositoryFormat.get_default_format().__class__,
133
repository.RepositoryFormat7)
135
bzrdir.format_registry.set_default_repository(old_default)
55
137
class SampleBranch(bzrlib.branch.Branch):
56
138
"""A dummy branch for guess what, dummy use."""
176
253
def test_create_repository_under_shared(self):
177
254
# an explicit create_repository always does so.
178
255
# 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)
256
format = bzrdir.format_registry.make_bzrdir('knit')
257
self.make_repository('.', shared=True, format=format)
258
repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
260
self.assertTrue(isinstance(repo, repository.Repository))
261
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
189
263
def test_create_branch_and_repo_uses_default(self):
190
264
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)
265
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
267
self.assertTrue(isinstance(branch, SampleBranch))
199
269
def test_create_branch_and_repo_under_shared(self):
200
270
# creating a branch and repo in a shared repo uses the
201
271
# 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)
272
format = bzrdir.format_registry.make_bzrdir('knit')
273
self.make_repository('.', shared=True, format=format)
274
branch = bzrdir.BzrDir.create_branch_and_repo(
275
self.get_url('child'), format=format)
276
self.assertRaises(errors.NoRepositoryPresent,
277
branch.bzrdir.open_repository)
212
279
def test_create_branch_and_repo_under_shared_force_new(self):
213
280
# creating a branch and repo in a shared repo can be forced to
214
281
# 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)
282
format = bzrdir.format_registry.make_bzrdir('knit')
283
self.make_repository('.', shared=True, format=format)
284
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
287
branch.bzrdir.open_repository()
225
289
def test_create_standalone_working_tree(self):
226
290
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)
291
# note this is deliberately readonly, as this failure should
292
# occur before any writes.
293
self.assertRaises(errors.NotLocalUrl,
294
bzrdir.BzrDir.create_standalone_workingtree,
295
self.get_readonly_url(), format=format)
296
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
298
self.assertEqual('A tree', tree)
240
300
def test_create_standalone_working_tree_under_shared_repo(self):
241
301
# 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)
302
format = bzrdir.format_registry.make_bzrdir('knit')
303
self.make_repository('.', shared=True, format=format)
304
# note this is deliberately readonly, as this failure should
305
# occur before any writes.
306
self.assertRaises(errors.NotLocalUrl,
307
bzrdir.BzrDir.create_standalone_workingtree,
308
self.get_readonly_url('child'), format=format)
309
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
311
tree.bzrdir.open_repository()
256
313
def test_create_branch_convenience(self):
257
314
# 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)
315
format = bzrdir.format_registry.make_bzrdir('knit')
316
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
317
branch.bzrdir.open_workingtree()
318
branch.bzrdir.open_repository()
267
320
def test_create_branch_convenience_root(self):
268
321
"""Creating a branch at the root of a fs should work."""
269
322
self.transport_server = MemoryServer
270
323
# 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)
324
format = bzrdir.format_registry.make_bzrdir('knit')
325
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
327
self.assertRaises(errors.NoWorkingTree,
328
branch.bzrdir.open_workingtree)
329
branch.bzrdir.open_repository()
281
331
def test_create_branch_convenience_under_shared_repo(self):
282
332
# inside a repo the default convenience output is a branch+ follow the
283
333
# 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)
334
format = bzrdir.format_registry.make_bzrdir('knit')
335
self.make_repository('.', shared=True, format=format)
336
branch = bzrdir.BzrDir.create_branch_convenience('child',
338
branch.bzrdir.open_workingtree()
339
self.assertRaises(errors.NoRepositoryPresent,
340
branch.bzrdir.open_repository)
295
342
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
296
343
# inside a repo the default convenience output is a branch+ follow the
297
344
# 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)
345
format = bzrdir.format_registry.make_bzrdir('knit')
346
self.make_repository('.', shared=True, format=format)
347
branch = bzrdir.BzrDir.create_branch_convenience('child',
348
force_new_tree=False, format=format)
349
self.assertRaises(errors.NoWorkingTree,
350
branch.bzrdir.open_workingtree)
351
self.assertRaises(errors.NoRepositoryPresent,
352
branch.bzrdir.open_repository)
311
354
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
312
355
# inside a repo the default convenience output is a branch+ follow the
313
356
# 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)
357
format = bzrdir.format_registry.make_bzrdir('knit')
358
repo = self.make_repository('.', shared=True, format=format)
359
repo.set_make_working_trees(False)
360
branch = bzrdir.BzrDir.create_branch_convenience('child',
362
self.assertRaises(errors.NoWorkingTree,
363
branch.bzrdir.open_workingtree)
364
self.assertRaises(errors.NoRepositoryPresent,
365
branch.bzrdir.open_repository)
327
367
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
328
368
# inside a repo the default convenience output is a branch+ follow the
329
369
# 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)
370
format = bzrdir.format_registry.make_bzrdir('knit')
371
repo = self.make_repository('.', shared=True, format=format)
372
repo.set_make_working_trees(False)
373
branch = bzrdir.BzrDir.create_branch_convenience('child',
374
force_new_tree=True, format=format)
375
branch.bzrdir.open_workingtree()
376
self.assertRaises(errors.NoRepositoryPresent,
377
branch.bzrdir.open_repository)
343
379
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
344
380
# inside a repo the default convenience output is overridable to give
345
381
# 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)
382
format = bzrdir.format_registry.make_bzrdir('knit')
383
self.make_repository('.', shared=True, format=format)
384
branch = bzrdir.BzrDir.create_branch_convenience('child',
385
force_new_repo=True, format=format)
386
branch.bzrdir.open_repository()
387
branch.bzrdir.open_workingtree()
358
390
class ChrootedTests(TestCaseWithTransport):