42
59
old_format = bzrdir.BzrDirFormat.get_default_format()
43
60
# default is BzrDirFormat6
44
61
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
45
bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
62
self.applyDeprecated(symbol_versioning.zero_fourteen,
63
bzrdir.BzrDirFormat.set_default_format,
46
65
# creating a bzr dir should now create an instrumented dir.
48
67
result = bzrdir.BzrDir.create('memory:///')
49
68
self.failUnless(isinstance(result, SampleBzrDir))
51
bzrdir.BzrDirFormat.set_default_format(old_format)
70
self.applyDeprecated(symbol_versioning.zero_fourteen,
71
bzrdir.BzrDirFormat.set_default_format, old_format)
52
72
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
75
class TestFormatRegistry(TestCase):
77
def make_format_registry(self):
78
my_format_registry = bzrdir.BzrDirFormatRegistry()
79
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
80
'Pre-0.8 format. Slower and does not support checkouts or shared'
81
' repositories', deprecated=True)
82
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
83
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
84
my_format_registry.register_metadir('knit',
85
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
88
my_format_registry.set_default('knit')
89
my_format_registry.register_metadir(
91
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
92
'Experimental successor to knit. Use at your own risk.',
93
branch_format='bzrlib.branch.BzrBranchFormat6')
94
my_format_registry.register_metadir(
96
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
97
'Experimental successor to knit. Use at your own risk.',
98
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
99
my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
100
'Pre-0.8 format. Slower and does not support checkouts or shared'
101
' repositories', hidden=True)
102
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
103
'BzrDirFormat6', 'Format registered lazily', deprecated=True,
105
return my_format_registry
107
def test_format_registry(self):
108
my_format_registry = self.make_format_registry()
109
my_bzrdir = my_format_registry.make_bzrdir('lazy')
110
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
111
my_bzrdir = my_format_registry.make_bzrdir('weave')
112
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
113
my_bzrdir = my_format_registry.make_bzrdir('default')
114
self.assertIsInstance(my_bzrdir.repository_format,
115
knitrepo.RepositoryFormatKnit1)
116
my_bzrdir = my_format_registry.make_bzrdir('knit')
117
self.assertIsInstance(my_bzrdir.repository_format,
118
knitrepo.RepositoryFormatKnit1)
119
my_bzrdir = my_format_registry.make_bzrdir('branch6')
120
self.assertIsInstance(my_bzrdir.get_branch_format(),
121
bzrlib.branch.BzrBranchFormat6)
123
def test_get_help(self):
124
my_format_registry = self.make_format_registry()
125
self.assertEqual('Format registered lazily',
126
my_format_registry.get_help('lazy'))
127
self.assertEqual('Format using knits',
128
my_format_registry.get_help('knit'))
129
self.assertEqual('Format using knits',
130
my_format_registry.get_help('default'))
131
self.assertEqual('Pre-0.8 format. Slower and does not support'
132
' checkouts or shared repositories',
133
my_format_registry.get_help('weave'))
135
def test_help_topic(self):
136
topics = help_topics.HelpTopicRegistry()
137
topics.register('formats', self.make_format_registry().help_topic,
139
topic = topics.get_detail('formats')
140
new, deprecated = topic.split('Deprecated formats')
141
self.assertContainsRe(new, 'Bazaar directory formats')
142
self.assertContainsRe(new,
143
' knit/default:\n \(native\) Format using knits\n')
144
self.assertContainsRe(deprecated,
145
' lazy:\n \(native\) Format registered lazily\n')
146
self.assertNotContainsRe(new, 'hidden')
148
def test_set_default_repository(self):
149
default_factory = bzrdir.format_registry.get('default')
150
old_default = [k for k, v in bzrdir.format_registry.iteritems()
151
if v == default_factory and k != 'default'][0]
152
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
154
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
155
bzrdir.format_registry.get('default'))
157
repository.RepositoryFormat.get_default_format().__class__,
158
knitrepo.RepositoryFormatKnit3)
160
bzrdir.format_registry.set_default_repository(old_default)
55
163
class SampleBranch(bzrlib.branch.Branch):
56
164
"""A dummy branch for guess what, dummy use."""
176
279
def test_create_repository_under_shared(self):
177
280
# an explicit create_repository always does so.
178
281
# 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)
282
format = bzrdir.format_registry.make_bzrdir('knit')
283
self.make_repository('.', shared=True, format=format)
284
repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
286
self.assertTrue(isinstance(repo, repository.Repository))
287
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
189
289
def test_create_branch_and_repo_uses_default(self):
190
290
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)
291
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
293
self.assertTrue(isinstance(branch, SampleBranch))
199
295
def test_create_branch_and_repo_under_shared(self):
200
296
# creating a branch and repo in a shared repo uses the
201
297
# 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)
298
format = bzrdir.format_registry.make_bzrdir('knit')
299
self.make_repository('.', shared=True, format=format)
300
branch = bzrdir.BzrDir.create_branch_and_repo(
301
self.get_url('child'), format=format)
302
self.assertRaises(errors.NoRepositoryPresent,
303
branch.bzrdir.open_repository)
212
305
def test_create_branch_and_repo_under_shared_force_new(self):
213
306
# creating a branch and repo in a shared repo can be forced to
214
307
# 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)
308
format = bzrdir.format_registry.make_bzrdir('knit')
309
self.make_repository('.', shared=True, format=format)
310
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
313
branch.bzrdir.open_repository()
225
315
def test_create_standalone_working_tree(self):
226
316
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)
317
# note this is deliberately readonly, as this failure should
318
# occur before any writes.
319
self.assertRaises(errors.NotLocalUrl,
320
bzrdir.BzrDir.create_standalone_workingtree,
321
self.get_readonly_url(), format=format)
322
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
324
self.assertEqual('A tree', tree)
240
326
def test_create_standalone_working_tree_under_shared_repo(self):
241
327
# 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)
328
format = bzrdir.format_registry.make_bzrdir('knit')
329
self.make_repository('.', shared=True, format=format)
330
# note this is deliberately readonly, as this failure should
331
# occur before any writes.
332
self.assertRaises(errors.NotLocalUrl,
333
bzrdir.BzrDir.create_standalone_workingtree,
334
self.get_readonly_url('child'), format=format)
335
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
337
tree.bzrdir.open_repository()
256
339
def test_create_branch_convenience(self):
257
340
# 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)
341
format = bzrdir.format_registry.make_bzrdir('knit')
342
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
343
branch.bzrdir.open_workingtree()
344
branch.bzrdir.open_repository()
267
346
def test_create_branch_convenience_root(self):
268
347
"""Creating a branch at the root of a fs should work."""
269
self.transport_server = MemoryServer
348
self.vfs_transport_factory = MemoryServer
270
349
# 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)
350
format = bzrdir.format_registry.make_bzrdir('knit')
351
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
353
self.assertRaises(errors.NoWorkingTree,
354
branch.bzrdir.open_workingtree)
355
branch.bzrdir.open_repository()
281
357
def test_create_branch_convenience_under_shared_repo(self):
282
358
# inside a repo the default convenience output is a branch+ follow the
283
359
# 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)
360
format = bzrdir.format_registry.make_bzrdir('knit')
361
self.make_repository('.', shared=True, format=format)
362
branch = bzrdir.BzrDir.create_branch_convenience('child',
364
branch.bzrdir.open_workingtree()
365
self.assertRaises(errors.NoRepositoryPresent,
366
branch.bzrdir.open_repository)
295
368
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
296
369
# inside a repo the default convenience output is a branch+ follow the
297
370
# 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)
371
format = bzrdir.format_registry.make_bzrdir('knit')
372
self.make_repository('.', shared=True, format=format)
373
branch = bzrdir.BzrDir.create_branch_convenience('child',
374
force_new_tree=False, format=format)
375
self.assertRaises(errors.NoWorkingTree,
376
branch.bzrdir.open_workingtree)
377
self.assertRaises(errors.NoRepositoryPresent,
378
branch.bzrdir.open_repository)
311
380
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
312
381
# inside a repo the default convenience output is a branch+ follow the
313
382
# 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)
383
format = bzrdir.format_registry.make_bzrdir('knit')
384
repo = self.make_repository('.', shared=True, format=format)
385
repo.set_make_working_trees(False)
386
branch = bzrdir.BzrDir.create_branch_convenience('child',
388
self.assertRaises(errors.NoWorkingTree,
389
branch.bzrdir.open_workingtree)
390
self.assertRaises(errors.NoRepositoryPresent,
391
branch.bzrdir.open_repository)
327
393
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
328
394
# inside a repo the default convenience output is a branch+ follow the
329
395
# 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)
396
format = bzrdir.format_registry.make_bzrdir('knit')
397
repo = self.make_repository('.', shared=True, format=format)
398
repo.set_make_working_trees(False)
399
branch = bzrdir.BzrDir.create_branch_convenience('child',
400
force_new_tree=True, format=format)
401
branch.bzrdir.open_workingtree()
402
self.assertRaises(errors.NoRepositoryPresent,
403
branch.bzrdir.open_repository)
343
405
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
344
406
# inside a repo the default convenience output is overridable to give
345
407
# 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)
408
format = bzrdir.format_registry.make_bzrdir('knit')
409
self.make_repository('.', shared=True, format=format)
410
branch = bzrdir.BzrDir.create_branch_convenience('child',
411
force_new_repo=True, format=format)
412
branch.bzrdir.open_repository()
413
branch.bzrdir.open_workingtree()
358
416
class ChrootedTests(TestCaseWithTransport):
624
766
result.open_branch()
625
767
result.open_repository()
769
def test_checkout_metadir(self):
770
# checkout_metadir has reasonable working tree format even when no
771
# working tree is present
772
self.make_branch('branch-knit2', format='dirstate-with-subtree')
773
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
774
checkout_format = my_bzrdir.checkout_metadir()
775
self.assertIsInstance(checkout_format.workingtree_format,
776
workingtree.WorkingTreeFormat3)
779
class TestHTTPRedirectionLoop(object):
780
"""Test redirection loop between two http servers.
782
This MUST be used by daughter classes that also inherit from
783
TestCaseWithTwoWebservers.
785
We can't inherit directly from TestCaseWithTwoWebservers or the
786
test framework will try to create an instance which cannot
787
run, its implementation being incomplete.
790
# Should be defined by daughter classes to ensure redirection
791
# still use the same transport implementation (not currently
792
# enforced as it's a bit tricky to get right (see the FIXME
793
# in BzrDir.open_from_transport for the unique use case so
797
def create_transport_readonly_server(self):
798
return HTTPServerRedirecting()
800
def create_transport_secondary_server(self):
801
return HTTPServerRedirecting()
804
# Both servers redirect to each server creating a loop
805
super(TestHTTPRedirectionLoop, self).setUp()
806
# The redirections will point to the new server
807
self.new_server = self.get_readonly_server()
808
# The requests to the old server will be redirected
809
self.old_server = self.get_secondary_server()
810
# Configure the redirections
811
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
812
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
814
def _qualified_url(self, host, port):
815
return 'http+%s://%s:%s' % (self._qualifier, host, port)
818
# Starting from either server should loop
819
old_url = self._qualified_url(self.old_server.host,
820
self.old_server.port)
821
oldt = self._transport(old_url)
822
self.assertRaises(errors.NotBranchError,
823
bzrdir.BzrDir.open_from_transport, oldt)
824
new_url = self._qualified_url(self.new_server.host,
825
self.new_server.port)
826
newt = self._transport(new_url)
827
self.assertRaises(errors.NotBranchError,
828
bzrdir.BzrDir.open_from_transport, newt)
831
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
832
TestCaseWithTwoWebservers):
833
"""Tests redirections for urllib implementation"""
835
_qualifier = 'urllib'
836
_transport = HttpTransport_urllib
840
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
841
TestHTTPRedirectionLoop,
842
TestCaseWithTwoWebservers):
843
"""Tests redirections for pycurl implementation"""
845
_qualifier = 'pycurl'