85
85
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
86
86
'Pre-0.8 format. Slower and does not support checkouts or shared'
87
87
' repositories', deprecated=True)
88
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
89
89
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
90
90
my_format_registry.register_metadir('knit',
91
91
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
118
118
my_bzrdir = my_format_registry.make_bzrdir('weave')
119
119
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
120
120
my_bzrdir = my_format_registry.make_bzrdir('default')
121
self.assertIsInstance(my_bzrdir.repository_format,
121
self.assertIsInstance(my_bzrdir.repository_format,
122
122
knitrepo.RepositoryFormatKnit1)
123
123
my_bzrdir = my_format_registry.make_bzrdir('knit')
124
self.assertIsInstance(my_bzrdir.repository_format,
124
self.assertIsInstance(my_bzrdir.repository_format,
125
125
knitrepo.RepositoryFormatKnit1)
126
126
my_bzrdir = my_format_registry.make_bzrdir('branch6')
127
127
self.assertIsInstance(my_bzrdir.get_branch_format(),
131
131
my_format_registry = self.make_format_registry()
132
132
self.assertEqual('Format registered lazily',
133
133
my_format_registry.get_help('lazy'))
134
self.assertEqual('Format using knits',
134
self.assertEqual('Format using knits',
135
135
my_format_registry.get_help('knit'))
136
self.assertEqual('Format using knits',
136
self.assertEqual('Format using knits',
137
137
my_format_registry.get_help('default'))
138
138
self.assertEqual('Pre-0.8 format. Slower and does not support'
139
' checkouts or shared repositories',
139
' checkouts or shared repositories',
140
140
my_format_registry.get_help('weave'))
142
142
def test_help_topic(self):
143
143
topics = help_topics.HelpTopicRegistry()
144
144
registry = self.make_format_registry()
145
topics.register('current-formats', registry.help_topic,
145
topics.register('current-formats', registry.help_topic,
146
146
'Current formats')
147
topics.register('other-formats', registry.help_topic,
147
topics.register('other-formats', registry.help_topic,
149
149
new = topics.get_detail('current-formats')
150
150
rest = topics.get_detail('other-formats')
151
151
experimental, deprecated = rest.split('Deprecated formats')
152
152
self.assertContainsRe(new, 'bzr help formats')
153
self.assertContainsRe(new,
153
self.assertContainsRe(new,
154
154
':knit:\n \(native\) \(default\) Format using knits\n')
155
self.assertContainsRe(experimental,
155
self.assertContainsRe(experimental,
156
156
':branch6:\n \(native\) Experimental successor to knit')
157
self.assertContainsRe(deprecated,
157
self.assertContainsRe(deprecated,
158
158
':lazy:\n \(native\) Format registered lazily\n')
159
159
self.assertNotContainsRe(new, 'hidden')
247
247
def test_find_format(self):
248
248
# is the right format object found for a branch?
249
249
# create a branch with a few known format objects.
250
# this is not quite the same as
250
# this is not quite the same as
251
251
t = get_transport(self.get_url())
252
252
self.build_tree(["foo/", "bar/"], transport=t)
253
253
def check_format(format, url):
257
257
self.failUnless(isinstance(found_format, format.__class__))
258
258
check_format(bzrdir.BzrDirFormat5(), "foo")
259
259
check_format(bzrdir.BzrDirFormat6(), "bar")
261
261
def test_find_format_nothing_there(self):
262
262
self.assertRaises(NotBranchError,
263
263
bzrdir.BzrDirFormat.find_format,
307
307
branch.bzrdir.open_repository)
309
309
def test_create_branch_and_repo_under_shared_force_new(self):
310
# creating a branch and repo in a shared repo can be forced to
310
# creating a branch and repo in a shared repo can be forced to
311
311
# make a new repo
312
312
format = bzrdir.format_registry.make_bzrdir('knit')
313
313
self.make_repository('.', shared=True, format=format)
319
319
def test_create_standalone_working_tree(self):
320
320
format = SampleBzrDirFormat()
321
# note this is deliberately readonly, as this failure should
321
# note this is deliberately readonly, as this failure should
322
322
# occur before any writes.
323
323
self.assertRaises(errors.NotLocalUrl,
324
324
bzrdir.BzrDir.create_standalone_workingtree,
325
325
self.get_readonly_url(), format=format)
326
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
326
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
328
328
self.assertEqual('A tree', tree)
331
331
# create standalone working tree always makes a repo.
332
332
format = bzrdir.format_registry.make_bzrdir('knit')
333
333
self.make_repository('.', shared=True, format=format)
334
# note this is deliberately readonly, as this failure should
334
# note this is deliberately readonly, as this failure should
335
335
# occur before any writes.
336
336
self.assertRaises(errors.NotLocalUrl,
337
337
bzrdir.BzrDir.create_standalone_workingtree,
338
338
self.get_readonly_url('child'), format=format)
339
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
339
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
341
341
tree.bzrdir.open_repository()
361
361
self.vfs_transport_factory = MemoryServer
362
362
# outside a repo the default convenience output is a repo+branch_tree
363
363
format = bzrdir.format_registry.make_bzrdir('knit')
364
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
364
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
366
366
self.assertRaises(errors.NoWorkingTree,
367
367
branch.bzrdir.open_workingtree)
377
377
branch.bzrdir.open_workingtree()
378
378
self.assertRaises(errors.NoRepositoryPresent,
379
379
branch.bzrdir.open_repository)
381
381
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
382
382
# inside a repo the default convenience output is a branch+ follow the
383
383
# repo tree policy but we can override that
389
389
branch.bzrdir.open_workingtree)
390
390
self.assertRaises(errors.NoRepositoryPresent,
391
391
branch.bzrdir.open_repository)
393
393
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
394
394
# inside a repo the default convenience output is a branch+ follow the
395
395
# repo tree policy
396
396
format = bzrdir.format_registry.make_bzrdir('knit')
397
397
repo = self.make_repository('.', shared=True, format=format)
398
398
repo.set_make_working_trees(False)
399
branch = bzrdir.BzrDir.create_branch_convenience('child',
399
branch = bzrdir.BzrDir.create_branch_convenience('child',
401
401
self.assertRaises(errors.NoWorkingTree,
402
402
branch.bzrdir.open_workingtree)
726
726
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
727
727
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
728
728
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
730
730
def test_open_from_transport_no_bzrdir(self):
731
731
transport = get_transport(self.get_url())
732
732
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
907
907
"""Tests specific to the version 5 bzrdir format."""
909
909
def test_same_lockfiles_between_tree_repo_branch(self):
910
# this checks that only a single lockfiles instance is created
910
# this checks that only a single lockfiles instance is created
911
911
# for format 5 objects
912
912
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
913
913
def check_dir_components_use_same_lock(dir):
920
920
# and if we open it normally.
921
921
dir = bzrdir.BzrDir.open(self.get_url())
922
922
check_dir_components_use_same_lock(dir)
924
924
def test_can_convert(self):
925
925
# format 5 dirs are convertable
926
926
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
927
927
self.assertTrue(dir.can_convert_format())
929
929
def test_needs_conversion(self):
930
930
# format 5 dirs need a conversion if they are not the default,
931
931
# and they aren't
941
941
"""Tests specific to the version 6 bzrdir format."""
943
943
def test_same_lockfiles_between_tree_repo_branch(self):
944
# this checks that only a single lockfiles instance is created
944
# this checks that only a single lockfiles instance is created
945
945
# for format 6 objects
946
946
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
947
947
def check_dir_components_use_same_lock(dir):
954
954
# and if we open it normally.
955
955
dir = bzrdir.BzrDir.open(self.get_url())
956
956
check_dir_components_use_same_lock(dir)
958
958
def test_can_convert(self):
959
959
# format 6 dirs are convertable
960
960
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
961
961
self.assertTrue(dir.can_convert_format())
963
963
def test_needs_conversion(self):
964
964
# format 6 dirs need an conversion if they are not the default.
965
965
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1002
1002
class TestNotBzrDir(TestCaseWithTransport):
1003
1003
"""Tests for using the bzrdir api with a non .bzr based disk format.
1005
1005
If/when one of these is in the core, we can let the implementation tests
1006
1006
verify this works.
1009
1009
def test_create_and_find_format(self):
1010
# create a .notbzr dir
1010
# create a .notbzr dir
1011
1011
format = NotBzrDirFormat()
1012
1012
dir = format.initialize(self.get_url())
1013
1013
self.assertIsInstance(dir, NotBzrDir)
1038
1038
def setUp(self):
1039
1039
super(NonLocalTests, self).setUp()
1040
1040
self.vfs_transport_factory = MemoryServer
1042
1042
def test_create_branch_convenience(self):
1043
1043
# outside a repo the default convenience output is a repo+branch_tree
1044
1044
format = bzrdir.format_registry.make_bzrdir('knit')
1090
1090
We can't inherit directly from TestCaseWithTwoWebservers or the
1091
1091
test framework will try to create an instance which cannot
1092
run, its implementation being incomplete.
1092
run, its implementation being incomplete.
1095
1095
def create_transport_readonly_server(self):
1258
1258
Usually, BzrDir.sprout should delegate to the branch's sprout method
1259
1259
for part of the work. This allows the source branch to control the
1260
1260
choice of format for the new branch.
1262
1262
There are exceptions, but this tests avoids them:
1263
1263
- if there's no branch in the source bzrdir,
1264
1264
- or if the stacking has been requested and the format needs to be