58
59
from bzrlib.transport.memory import MemoryServer
59
60
from bzrlib.transport.nosmart import NoSmartTransportDecorator
60
61
from bzrlib.transport.readonly import ReadonlyTransportDecorator
61
from bzrlib.repofmt import knitrepo, weaverepo
62
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
64
65
class TestDefaultFormat(TestCase):
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)
431
432
"""The default acquisition policy should create a standalone branch."""
432
433
my_bzrdir = self.make_bzrdir('.')
433
434
repo_policy = my_bzrdir.determine_repository_policy()
434
repo = repo_policy.acquire_repository()
435
repo, is_new = repo_policy.acquire_repository()
435
436
self.assertEqual(repo.bzrdir.root_transport.base,
436
437
my_bzrdir.root_transport.base)
437
438
self.assertFalse(repo.is_shared())
440
440
def test_determine_stacking_policy(self):
441
441
parent_bzrdir = self.make_bzrdir('.')
442
442
child_bzrdir = self.make_bzrdir('child')
466
466
self.assertEqual(child_branch.base,
467
467
new_child.open_branch().get_stacked_on_url())
469
def test_default_stacking_with_stackable_branch_unstackable_repo(self):
470
# Make stackable source branch with an unstackable repo format.
471
source_bzrdir = self.make_bzrdir('source')
472
pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
473
source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
474
# Make a directory with a default stacking policy
475
parent_bzrdir = self.make_bzrdir('parent')
476
stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
477
parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
478
# Clone source into directory
479
target = source_bzrdir.clone(self.get_url('parent/target'))
469
481
def test_sprout_obeys_stacking_policy(self):
470
482
child_branch, new_child_transport = self.prepare_default_stacking()
471
483
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
725
737
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
726
738
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
727
739
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
729
741
def test_open_from_transport_no_bzrdir(self):
730
742
transport = get_transport(self.get_url())
731
743
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
742
754
def test_sprout_recursive(self):
743
tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
755
tree = self.make_branch_and_tree('tree1',
756
format='dirstate-with-subtree')
744
757
sub_tree = self.make_branch_and_tree('tree1/subtree',
745
758
format='dirstate-with-subtree')
759
sub_tree.set_root_id('subtree-root')
746
760
tree.add_reference(sub_tree)
747
761
self.build_tree(['tree1/subtree/file'])
748
762
sub_tree.add('file')
749
763
tree.commit('Initial commit')
750
tree.bzrdir.sprout('tree2')
764
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
766
self.addCleanup(tree2.unlock)
751
767
self.failUnlessExists('tree2/subtree/file')
768
self.assertEqual('tree-reference', tree2.kind('subtree-root'))
753
770
def test_cloning_metadir(self):
754
771
"""Ensure that cloning metadir is suitable"""
885
902
self.assertTrue(tree.bzrdir.needs_format_conversion(
905
def test_initialize_on_format_uses_smart_transport(self):
906
self.setup_smart_server_with_call_log()
907
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
908
transport = self.get_transport('target')
909
transport.ensure_base()
910
self.reset_smart_call_log()
911
instance = new_format.initialize_on_transport(transport)
912
self.assertIsInstance(instance, remote.RemoteBzrDir)
913
rpc_count = len(self.hpss_calls)
914
# This figure represent the amount of work to perform this use case. It
915
# is entirely ok to reduce this number if a test fails due to rpc_count
916
# being too low. If rpc_count increases, more network roundtrips have
917
# become necessary for this use case. Please do not adjust this number
918
# upwards without agreement from bzr's network support maintainers.
919
self.assertEqual(2, rpc_count)
889
922
class TestFormat5(TestCaseWithTransport):
890
923
"""Tests specific to the version 5 bzrdir format."""
892
925
def test_same_lockfiles_between_tree_repo_branch(self):
893
# this checks that only a single lockfiles instance is created
926
# this checks that only a single lockfiles instance is created
894
927
# for format 5 objects
895
928
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
896
929
def check_dir_components_use_same_lock(dir):
903
936
# and if we open it normally.
904
937
dir = bzrdir.BzrDir.open(self.get_url())
905
938
check_dir_components_use_same_lock(dir)
907
940
def test_can_convert(self):
908
941
# format 5 dirs are convertable
909
942
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
910
943
self.assertTrue(dir.can_convert_format())
912
945
def test_needs_conversion(self):
913
946
# format 5 dirs need a conversion if they are not the default,
914
947
# and they aren't
924
957
"""Tests specific to the version 6 bzrdir format."""
926
959
def test_same_lockfiles_between_tree_repo_branch(self):
927
# this checks that only a single lockfiles instance is created
960
# this checks that only a single lockfiles instance is created
928
961
# for format 6 objects
929
962
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
930
963
def check_dir_components_use_same_lock(dir):
937
970
# and if we open it normally.
938
971
dir = bzrdir.BzrDir.open(self.get_url())
939
972
check_dir_components_use_same_lock(dir)
941
974
def test_can_convert(self):
942
975
# format 6 dirs are convertable
943
976
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
944
977
self.assertTrue(dir.can_convert_format())
946
979
def test_needs_conversion(self):
947
980
# format 6 dirs need an conversion if they are not the default.
948
981
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
985
1018
class TestNotBzrDir(TestCaseWithTransport):
986
1019
"""Tests for using the bzrdir api with a non .bzr based disk format.
988
1021
If/when one of these is in the core, we can let the implementation tests
989
1022
verify this works.
992
1025
def test_create_and_find_format(self):
993
# create a .notbzr dir
1026
# create a .notbzr dir
994
1027
format = NotBzrDirFormat()
995
1028
dir = format.initialize(self.get_url())
996
1029
self.assertIsInstance(dir, NotBzrDir)
1021
1054
def setUp(self):
1022
1055
super(NonLocalTests, self).setUp()
1023
1056
self.vfs_transport_factory = MemoryServer
1025
1058
def test_create_branch_convenience(self):
1026
1059
# outside a repo the default convenience output is a repo+branch_tree
1027
1060
format = bzrdir.format_registry.make_bzrdir('knit')
1073
1106
We can't inherit directly from TestCaseWithTwoWebservers or the
1074
1107
test framework will try to create an instance which cannot
1075
run, its implementation being incomplete.
1108
run, its implementation being incomplete.
1078
1111
def create_transport_readonly_server(self):
1211
1244
return _TestBzrDirFormat()
1247
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1248
"""Test Branch format for TestBzrDirSprout."""
1214
1251
class _TestBranch(bzrlib.branch.Branch):
1215
1252
"""Test Branch implementation for TestBzrDirSprout."""
1217
1254
def __init__(self, *args, **kwargs):
1255
self._format = _TestBranchFormat()
1218
1256
super(_TestBranch, self).__init__(*args, **kwargs)
1219
1257
self.calls = []
1220
1258
self._parent = None
1241
1279
Usually, BzrDir.sprout should delegate to the branch's sprout method
1242
1280
for part of the work. This allows the source branch to control the
1243
1281
choice of format for the new branch.
1245
1283
There are exceptions, but this tests avoids them:
1246
1284
- if there's no branch in the source bzrdir,
1247
1285
- or if the stacking has been requested and the format needs to be