84
85
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
86
'Pre-0.8 format. Slower and does not support checkouts or shared'
86
87
' repositories', deprecated=True)
87
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
89
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
90
my_format_registry.register_metadir('knit',
90
91
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
117
118
my_bzrdir = my_format_registry.make_bzrdir('weave')
118
119
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
119
120
my_bzrdir = my_format_registry.make_bzrdir('default')
120
self.assertIsInstance(my_bzrdir.repository_format,
121
self.assertIsInstance(my_bzrdir.repository_format,
121
122
knitrepo.RepositoryFormatKnit1)
122
123
my_bzrdir = my_format_registry.make_bzrdir('knit')
123
self.assertIsInstance(my_bzrdir.repository_format,
124
self.assertIsInstance(my_bzrdir.repository_format,
124
125
knitrepo.RepositoryFormatKnit1)
125
126
my_bzrdir = my_format_registry.make_bzrdir('branch6')
126
127
self.assertIsInstance(my_bzrdir.get_branch_format(),
130
131
my_format_registry = self.make_format_registry()
131
132
self.assertEqual('Format registered lazily',
132
133
my_format_registry.get_help('lazy'))
133
self.assertEqual('Format using knits',
134
self.assertEqual('Format using knits',
134
135
my_format_registry.get_help('knit'))
135
self.assertEqual('Format using knits',
136
self.assertEqual('Format using knits',
136
137
my_format_registry.get_help('default'))
137
138
self.assertEqual('Pre-0.8 format. Slower and does not support'
138
' checkouts or shared repositories',
139
' checkouts or shared repositories',
139
140
my_format_registry.get_help('weave'))
141
142
def test_help_topic(self):
142
143
topics = help_topics.HelpTopicRegistry()
143
144
registry = self.make_format_registry()
144
topics.register('current-formats', registry.help_topic,
145
topics.register('current-formats', registry.help_topic,
145
146
'Current formats')
146
topics.register('other-formats', registry.help_topic,
147
topics.register('other-formats', registry.help_topic,
148
149
new = topics.get_detail('current-formats')
149
150
rest = topics.get_detail('other-formats')
150
151
experimental, deprecated = rest.split('Deprecated formats')
151
152
self.assertContainsRe(new, 'bzr help formats')
152
self.assertContainsRe(new,
153
self.assertContainsRe(new,
153
154
':knit:\n \(native\) \(default\) Format using knits\n')
154
self.assertContainsRe(experimental,
155
self.assertContainsRe(experimental,
155
156
':branch6:\n \(native\) Experimental successor to knit')
156
self.assertContainsRe(deprecated,
157
self.assertContainsRe(deprecated,
157
158
':lazy:\n \(native\) Format registered lazily\n')
158
159
self.assertNotContainsRe(new, 'hidden')
246
247
def test_find_format(self):
247
248
# is the right format object found for a branch?
248
249
# create a branch with a few known format objects.
249
# this is not quite the same as
250
# this is not quite the same as
250
251
t = get_transport(self.get_url())
251
252
self.build_tree(["foo/", "bar/"], transport=t)
252
253
def check_format(format, url):
256
257
self.failUnless(isinstance(found_format, format.__class__))
257
258
check_format(bzrdir.BzrDirFormat5(), "foo")
258
259
check_format(bzrdir.BzrDirFormat6(), "bar")
260
261
def test_find_format_nothing_there(self):
261
262
self.assertRaises(NotBranchError,
262
263
bzrdir.BzrDirFormat.find_format,
306
307
branch.bzrdir.open_repository)
308
309
def test_create_branch_and_repo_under_shared_force_new(self):
309
# 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
310
311
# make a new repo
311
312
format = bzrdir.format_registry.make_bzrdir('knit')
312
313
self.make_repository('.', shared=True, format=format)
318
319
def test_create_standalone_working_tree(self):
319
320
format = SampleBzrDirFormat()
320
# note this is deliberately readonly, as this failure should
321
# note this is deliberately readonly, as this failure should
321
322
# occur before any writes.
322
323
self.assertRaises(errors.NotLocalUrl,
323
324
bzrdir.BzrDir.create_standalone_workingtree,
324
325
self.get_readonly_url(), format=format)
325
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
326
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
327
328
self.assertEqual('A tree', tree)
330
331
# create standalone working tree always makes a repo.
331
332
format = bzrdir.format_registry.make_bzrdir('knit')
332
333
self.make_repository('.', shared=True, format=format)
333
# note this is deliberately readonly, as this failure should
334
# note this is deliberately readonly, as this failure should
334
335
# occur before any writes.
335
336
self.assertRaises(errors.NotLocalUrl,
336
337
bzrdir.BzrDir.create_standalone_workingtree,
337
338
self.get_readonly_url('child'), format=format)
338
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
339
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
340
341
tree.bzrdir.open_repository()
360
361
self.vfs_transport_factory = MemoryServer
361
362
# outside a repo the default convenience output is a repo+branch_tree
362
363
format = bzrdir.format_registry.make_bzrdir('knit')
363
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
364
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
365
366
self.assertRaises(errors.NoWorkingTree,
366
367
branch.bzrdir.open_workingtree)
376
377
branch.bzrdir.open_workingtree()
377
378
self.assertRaises(errors.NoRepositoryPresent,
378
379
branch.bzrdir.open_repository)
380
381
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
381
382
# inside a repo the default convenience output is a branch+ follow the
382
383
# repo tree policy but we can override that
388
389
branch.bzrdir.open_workingtree)
389
390
self.assertRaises(errors.NoRepositoryPresent,
390
391
branch.bzrdir.open_repository)
392
393
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
393
394
# inside a repo the default convenience output is a branch+ follow the
394
395
# repo tree policy
395
396
format = bzrdir.format_registry.make_bzrdir('knit')
396
397
repo = self.make_repository('.', shared=True, format=format)
397
398
repo.set_make_working_trees(False)
398
branch = bzrdir.BzrDir.create_branch_convenience('child',
399
branch = bzrdir.BzrDir.create_branch_convenience('child',
400
401
self.assertRaises(errors.NoWorkingTree,
401
402
branch.bzrdir.open_workingtree)
725
726
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
726
727
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
727
728
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
729
730
def test_open_from_transport_no_bzrdir(self):
730
731
transport = get_transport(self.get_url())
731
732
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
885
886
self.assertTrue(tree.bzrdir.needs_format_conversion(
889
def test_initialize_on_format_uses_smart_transport(self):
890
self.setup_smart_server_with_call_log()
891
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
892
transport = self.get_transport('target')
893
transport.ensure_base()
894
self.reset_smart_call_log()
895
instance = new_format.initialize_on_transport(transport)
896
self.assertIsInstance(instance, remote.RemoteBzrDir)
897
rpc_count = len(self.hpss_calls)
898
# This figure represent the amount of work to perform this use case. It
899
# is entirely ok to reduce this number if a test fails due to rpc_count
900
# being too low. If rpc_count increases, more network roundtrips have
901
# become necessary for this use case. Please do not adjust this number
902
# upwards without agreement from bzr's network support maintainers.
903
self.assertEqual(2, rpc_count)
889
906
class TestFormat5(TestCaseWithTransport):
890
907
"""Tests specific to the version 5 bzrdir format."""
892
909
def test_same_lockfiles_between_tree_repo_branch(self):
893
# this checks that only a single lockfiles instance is created
910
# this checks that only a single lockfiles instance is created
894
911
# for format 5 objects
895
912
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
896
913
def check_dir_components_use_same_lock(dir):
903
920
# and if we open it normally.
904
921
dir = bzrdir.BzrDir.open(self.get_url())
905
922
check_dir_components_use_same_lock(dir)
907
924
def test_can_convert(self):
908
925
# format 5 dirs are convertable
909
926
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
910
927
self.assertTrue(dir.can_convert_format())
912
929
def test_needs_conversion(self):
913
930
# format 5 dirs need a conversion if they are not the default,
914
931
# and they aren't
924
941
"""Tests specific to the version 6 bzrdir format."""
926
943
def test_same_lockfiles_between_tree_repo_branch(self):
927
# this checks that only a single lockfiles instance is created
944
# this checks that only a single lockfiles instance is created
928
945
# for format 6 objects
929
946
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
930
947
def check_dir_components_use_same_lock(dir):
937
954
# and if we open it normally.
938
955
dir = bzrdir.BzrDir.open(self.get_url())
939
956
check_dir_components_use_same_lock(dir)
941
958
def test_can_convert(self):
942
959
# format 6 dirs are convertable
943
960
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
944
961
self.assertTrue(dir.can_convert_format())
946
963
def test_needs_conversion(self):
947
964
# format 6 dirs need an conversion if they are not the default.
948
965
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
985
1002
class TestNotBzrDir(TestCaseWithTransport):
986
1003
"""Tests for using the bzrdir api with a non .bzr based disk format.
988
1005
If/when one of these is in the core, we can let the implementation tests
989
1006
verify this works.
992
1009
def test_create_and_find_format(self):
993
# create a .notbzr dir
1010
# create a .notbzr dir
994
1011
format = NotBzrDirFormat()
995
1012
dir = format.initialize(self.get_url())
996
1013
self.assertIsInstance(dir, NotBzrDir)
1021
1038
def setUp(self):
1022
1039
super(NonLocalTests, self).setUp()
1023
1040
self.vfs_transport_factory = MemoryServer
1025
1042
def test_create_branch_convenience(self):
1026
1043
# outside a repo the default convenience output is a repo+branch_tree
1027
1044
format = bzrdir.format_registry.make_bzrdir('knit')
1073
1090
We can't inherit directly from TestCaseWithTwoWebservers or the
1074
1091
test framework will try to create an instance which cannot
1075
run, its implementation being incomplete.
1092
run, its implementation being incomplete.
1078
1095
def create_transport_readonly_server(self):
1241
1258
Usually, BzrDir.sprout should delegate to the branch's sprout method
1242
1259
for part of the work. This allows the source branch to control the
1243
1260
choice of format for the new branch.
1245
1262
There are exceptions, but this tests avoids them:
1246
1263
- if there's no branch in the source bzrdir,
1247
1264
- or if the stacking has been requested and the format needs to be