118
133
self.assertNotEqual(dir.transport.base, target.transport.base)
119
134
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
136
def test_clone_bzrdir_repository_under_shared(self):
137
dir = self.make_bzrdir('source')
138
repo = dir.create_repository()
139
# add some content to differentiate from an empty repository.
140
repo.control_weaves.add_text('inventory',
144
repo.get_transaction())
146
self.make_repository('target', shared=True)
147
except errors.IncompatibleFormat:
149
target = dir.clone(self.get_url('target/child'))
150
self.assertNotEqual(dir.transport.base, target.transport.base)
151
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
153
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
154
dir = self.make_bzrdir('source')
155
repo = dir.create_repository()
156
# add some content to differentiate from an empty repository.
157
repo.control_weaves.add_text('inventory',
161
repo.get_transaction())
163
self.make_repository('target', shared=True)
164
except errors.IncompatibleFormat:
166
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
167
self.assertNotEqual(dir.transport.base, target.transport.base)
168
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
121
170
def test_clone_bzrdir_repository_revision(self):
122
171
# test for revision limiting, [smoke test, not corner case checks].
123
172
# make a repository with some revisions,
150
199
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
151
200
['./.bzr/stat-cache', './.bzr/checkout/stat-cache'])
202
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
203
# by default cloning into a shared repo uses the shared repo.
204
tree = self.make_branch_and_tree('commit_tree')
205
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
207
tree.commit('revision 1')
208
source = self.make_branch('source')
209
tree.bzrdir.open_repository().copy_content_into(source.repository)
210
tree.bzrdir.open_branch().copy_content_into(source)
212
self.make_repository('target', shared=True)
213
except errors.IncompatibleFormat:
216
target = dir.clone(self.get_url('target/child'))
217
self.assertNotEqual(dir.transport.base, target.transport.base)
218
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
219
self.assertEqual(source.revision_history(),
220
target.open_branch().revision_history())
222
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
223
# by default cloning into a shared repo uses the shared repo.
224
tree = self.make_branch_and_tree('commit_tree')
225
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
227
tree.commit('revision 1')
228
source = self.make_branch('source')
229
tree.bzrdir.open_repository().copy_content_into(source.repository)
230
tree.bzrdir.open_branch().copy_content_into(source)
232
self.make_repository('target', shared=True)
233
except errors.IncompatibleFormat:
236
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
237
self.assertNotEqual(dir.transport.base, target.transport.base)
238
target.open_repository()
239
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
153
241
def test_clone_bzrdir_branch_reference(self):
154
242
# cloning should preserve the reference status of the branch in a bzrdir
155
243
referenced_branch = self.make_branch('referencced')
265
378
self.assertNotEqual(dir.transport.base, target.transport.base)
266
379
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
381
def test_sprout_bzrdir_repository_under_shared(self):
382
tree = self.make_branch_and_tree('commit_tree')
383
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
385
tree.commit('revision 1', rev_id='1')
386
tree.bzrdir.open_branch().set_revision_history([])
387
tree.set_last_revision(None)
388
tree.commit('revision 2', rev_id='2')
389
source = self.make_repository('source')
390
tree.bzrdir.open_repository().copy_content_into(source)
393
shared_repo = self.make_repository('target', shared=True)
394
except errors.IncompatibleFormat:
396
target = dir.sprout(self.get_url('target/child'))
397
self.assertNotEqual(dir.transport.base, target.transport.base)
398
self.assertTrue(shared_repo.has_revision('1'))
400
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
401
tree = self.make_branch_and_tree('commit_tree')
402
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
404
tree.commit('revision 1', rev_id='1')
405
tree.bzrdir.open_branch().set_revision_history([])
406
tree.set_last_revision(None)
407
tree.commit('revision 2', rev_id='2')
408
source = self.make_repository('source')
409
tree.bzrdir.open_repository().copy_content_into(source)
412
shared_repo = self.make_repository('target', shared=True)
413
except errors.IncompatibleFormat:
415
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
416
self.assertNotEqual(dir.transport.base, target.transport.base)
417
self.assertFalse(shared_repo.has_revision('1'))
268
419
def test_sprout_bzrdir_repository_revision(self):
269
420
# test for revision limiting, [smoke test, not corner case checks].
270
421
# make a repository with some revisions,
296
447
self.assertNotEqual(dir.transport.base, target.transport.base)
297
448
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
450
def test_sprout_bzrdir_branch_and_repo_shared(self):
451
# sprouting a branch with a repo into a shared repo uses the shared
453
tree = self.make_branch_and_tree('commit_tree')
454
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
456
tree.commit('revision 1', rev_id='1')
457
source = self.make_branch('source')
458
tree.bzrdir.open_repository().copy_content_into(source.repository)
459
tree.bzrdir.open_branch().copy_content_into(source)
462
shared_repo = self.make_repository('target', shared=True)
463
except errors.IncompatibleFormat:
465
target = dir.sprout(self.get_url('target/child'))
466
self.assertTrue(shared_repo.has_revision('1'))
468
def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
469
# sprouting a branch with a repo into a shared repo uses the shared
471
tree = self.make_branch_and_tree('commit_tree')
472
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
474
tree.commit('revision 1', rev_id='1')
475
source = self.make_branch('source')
476
tree.bzrdir.open_repository().copy_content_into(source.repository)
477
tree.bzrdir.open_branch().copy_content_into(source)
480
shared_repo = self.make_repository('target', shared=True)
481
except errors.IncompatibleFormat:
483
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
484
self.assertNotEqual(dir.transport.base, target.transport.base)
485
self.assertFalse(shared_repo.has_revision('1'))
299
487
def test_sprout_bzrdir_branch_reference(self):
300
488
# sprouting should create a repository if needed and a sprouted branch.
301
489
referenced_branch = self.make_branch('referencced')
316
504
target.open_repository()
506
def test_sprout_bzrdir_branch_reference_shared(self):
507
# sprouting should create a repository if needed and a sprouted branch.
508
referenced_tree = self.make_branch_and_tree('referenced')
509
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
510
dir = self.make_bzrdir('source')
512
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
513
referenced_tree.branch)
514
except errors.IncompatibleFormat:
515
# this is ok too, not all formats have to support references.
517
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
519
shared_repo = self.make_repository('target', shared=True)
520
except errors.IncompatibleFormat:
522
target = dir.sprout(self.get_url('target/child'))
523
self.assertNotEqual(dir.transport.base, target.transport.base)
524
# we want target to have a branch that is in-place.
525
self.assertEqual(target, target.open_branch().bzrdir)
526
# and we want no repository as the target is shared
527
self.assertRaises(errors.NoRepositoryPresent,
528
target.open_repository)
529
# and we want revision '1' in the shared repo
530
self.assertTrue(shared_repo.has_revision('1'))
532
def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
533
# sprouting should create a repository if needed and a sprouted branch.
534
referenced_tree = self.make_branch_and_tree('referenced')
535
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
536
dir = self.make_bzrdir('source')
538
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
539
referenced_tree.branch)
540
except errors.IncompatibleFormat:
541
# this is ok too, not all formats have to support references.
543
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
545
shared_repo = self.make_repository('target', shared=True)
546
except errors.IncompatibleFormat:
548
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
549
self.assertNotEqual(dir.transport.base, target.transport.base)
550
# we want target to have a branch that is in-place.
551
self.assertEqual(target, target.open_branch().bzrdir)
552
# and we want revision '1' in the new repo
553
self.assertTrue(target.open_repository().has_revision('1'))
554
# but not the shared one
555
self.assertFalse(shared_repo.has_revision('1'))
318
557
def test_sprout_bzrdir_branch_revision(self):
319
558
# test for revision limiting, [smoke test, not corner case checks].
320
559
# make a repository with some revisions,
628
867
self.assertEqual(dir.root_transport.base,
629
868
get_transport(self.get_url('.')).base)
870
def test_find_repository_no_repo_under_standalone_branch(self):
871
# finding a repo stops at standalone branches even if there is a
872
# higher repository available.
874
repo = self.make_repository('.', shared=True)
875
except errors.IncompatibleFormat:
876
# need a shared repository to test this.
878
url = self.get_url('intermediate')
879
get_transport(self.get_url()).mkdir('intermediate')
880
get_transport(self.get_url()).mkdir('intermediate/child')
881
made_control = self.bzrdir_format.initialize(url)
882
made_control.create_repository()
883
innermost_control = self.bzrdir_format.initialize(
884
self.get_url('intermediate/child'))
886
child_repo = innermost_control.open_repository()
887
# if there is a repository, then the format cannot ever hit this
890
except errors.NoRepositoryPresent:
892
self.assertRaises(errors.NoRepositoryPresent,
893
innermost_control.find_repository)
895
def test_find_repository_containing_shared_repository(self):
896
# find repo inside a shared repo with an empty control dir
897
# returns the shared repo.
899
repo = self.make_repository('.', shared=True)
900
except errors.IncompatibleFormat:
901
# need a shared repository to test this.
903
url = self.get_url('childbzrdir')
904
get_transport(self.get_url()).mkdir('childbzrdir')
905
made_control = self.bzrdir_format.initialize(url)
907
child_repo = made_control.open_repository()
908
# if there is a repository, then the format cannot ever hit this
911
except errors.NoRepositoryPresent:
913
found_repo = made_control.find_repository()
914
self.assertEqual(repo.bzrdir.root_transport.base,
915
found_repo.bzrdir.root_transport.base)
917
def test_find_repository_standalone_with_containing_shared_repository(self):
918
# find repo inside a standalone repo inside a shared repo finds the standalone repo
920
containing_repo = self.make_repository('.', shared=True)
921
except errors.IncompatibleFormat:
922
# need a shared repository to test this.
924
child_repo = self.make_repository('childrepo')
925
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
926
found_repo = opened_control.find_repository()
927
self.assertEqual(child_repo.bzrdir.root_transport.base,
928
found_repo.bzrdir.root_transport.base)
930
def test_find_repository_shared_within_shared_repository(self):
931
# find repo at a shared repo inside a shared repo finds the inner repo
933
containing_repo = self.make_repository('.', shared=True)
934
except errors.IncompatibleFormat:
935
# need a shared repository to test this.
937
url = self.get_url('childrepo')
938
get_transport(self.get_url()).mkdir('childrepo')
939
child_control = self.bzrdir_format.initialize(url)
940
child_repo = child_control.create_repository(shared=True)
941
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
942
found_repo = opened_control.find_repository()
943
self.assertEqual(child_repo.bzrdir.root_transport.base,
944
found_repo.bzrdir.root_transport.base)
945
self.assertNotEqual(child_repo.bzrdir.root_transport.base,
946
containing_repo.bzrdir.root_transport.base)
948
def test_find_repository_with_nested_dirs_works(self):
949
# find repo inside a bzrdir inside a bzrdir inside a shared repo
950
# finds the outer shared repo.
952
repo = self.make_repository('.', shared=True)
953
except errors.IncompatibleFormat:
954
# need a shared repository to test this.
956
url = self.get_url('intermediate')
957
get_transport(self.get_url()).mkdir('intermediate')
958
get_transport(self.get_url()).mkdir('intermediate/child')
959
made_control = self.bzrdir_format.initialize(url)
961
child_repo = made_control.open_repository()
962
# if there is a repository, then the format cannot ever hit this
965
except errors.NoRepositoryPresent:
967
innermost_control = self.bzrdir_format.initialize(
968
self.get_url('intermediate/child'))
970
child_repo = innermost_control.open_repository()
971
# if there is a repository, then the format cannot ever hit this
974
except errors.NoRepositoryPresent:
976
found_repo = innermost_control.find_repository()
977
self.assertEqual(repo.bzrdir.root_transport.base,
978
found_repo.bzrdir.root_transport.base)
980
def test_can_and_needs_format_conversion(self):
981
# check that we can ask an instance if its upgradable
982
dir = self.make_bzrdir('.')
983
if dir.can_convert_format():
984
# if its updatable there must be an updater
985
self.assertTrue(isinstance(dir._format.get_converter(),
987
dir.needs_format_conversion(None)
989
def test_upgrade_new_instance(self):
990
"""Does an available updater work ?."""
991
dir = self.make_bzrdir('.')
992
if dir.can_convert_format():
993
dir._format.get_converter(None).convert(dir, ui.ui_factory.progress_bar())
994
# and it should pass 'check' now.
995
check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
998
class ChrootedBzrDirTests(ChrootedTestCase):
1000
def test_find_repository_no_repository(self):
1001
# loopback test to check the current format fails to find a
1002
# share repository correctly.
1003
if not self.bzrdir_format.is_supported():
1004
# unsupported formats are not loopback testable
1005
# because the default open will not open them and
1006
# they may not be initializable.
1008
# supported formats must be able to init and open
1009
url = self.get_url('subdir')
1010
get_transport(self.get_url()).mkdir('subdir')
1011
made_control = self.bzrdir_format.initialize(url)
1013
repo = made_control.open_repository()
1014
# if there is a repository, then the format cannot ever hit this
1017
except errors.NoRepositoryPresent:
1019
opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1020
self.assertRaises(errors.NoRepositoryPresent,
1021
opened_control.find_repository)