118
131
self.assertNotEqual(dir.transport.base, target.transport.base)
119
132
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
134
def test_clone_bzrdir_repository_under_shared(self):
135
dir = self.make_bzrdir('source')
136
repo = dir.create_repository()
137
# add some content to differentiate from an empty repository.
138
repo.control_weaves.add_text('inventory',
142
repo.get_transaction())
144
self.make_repository('target', shared=True)
145
except errors.IncompatibleFormat:
147
target = dir.clone(self.get_url('target/child'))
148
self.assertNotEqual(dir.transport.base, target.transport.base)
149
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
151
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
152
dir = self.make_bzrdir('source')
153
repo = dir.create_repository()
154
# add some content to differentiate from an empty repository.
155
repo.control_weaves.add_text('inventory',
159
repo.get_transaction())
161
self.make_repository('target', shared=True)
162
except errors.IncompatibleFormat:
164
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
165
self.assertNotEqual(dir.transport.base, target.transport.base)
166
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
121
168
def test_clone_bzrdir_repository_revision(self):
122
169
# test for revision limiting, [smoke test, not corner case checks].
123
170
# make a repository with some revisions,
150
197
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
151
198
['./.bzr/stat-cache', './.bzr/checkout/stat-cache'])
200
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
201
# by default cloning into a shared repo uses the shared repo.
202
tree = self.make_branch_and_tree('commit_tree')
203
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
205
tree.commit('revision 1')
206
source = self.make_branch('source')
207
tree.bzrdir.open_repository().copy_content_into(source.repository)
208
tree.bzrdir.open_branch().copy_content_into(source)
210
self.make_repository('target', shared=True)
211
except errors.IncompatibleFormat:
214
target = dir.clone(self.get_url('target/child'))
215
self.assertNotEqual(dir.transport.base, target.transport.base)
216
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
217
self.assertEqual(source.revision_history(),
218
target.open_branch().revision_history())
220
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
221
# by default cloning into a shared repo uses the shared repo.
222
tree = self.make_branch_and_tree('commit_tree')
223
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
225
tree.commit('revision 1')
226
source = self.make_branch('source')
227
tree.bzrdir.open_repository().copy_content_into(source.repository)
228
tree.bzrdir.open_branch().copy_content_into(source)
230
self.make_repository('target', shared=True)
231
except errors.IncompatibleFormat:
234
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
235
self.assertNotEqual(dir.transport.base, target.transport.base)
236
target.open_repository()
237
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
153
239
def test_clone_bzrdir_branch_reference(self):
154
240
# cloning should preserve the reference status of the branch in a bzrdir
155
241
referenced_branch = self.make_branch('referencced')
251
337
target.open_repository()
252
338
target.open_branch()
253
339
target.open_workingtree()
341
def test_sprout_bzrdir_empty_under_shared_repo(self):
342
# sprouting an empty dir into a repo uses the repo
343
dir = self.make_bzrdir('source')
345
self.make_repository('target', shared=True)
346
except errors.IncompatibleFormat:
348
target = dir.sprout(self.get_url('target/child'))
349
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
351
target.open_workingtree()
353
def test_sprout_bzrdir_empty_under_shared_repo(self):
354
# the force_new_repo parameter should force use of a new repo in an empty
355
# bzrdir's sprout logic
356
dir = self.make_bzrdir('source')
358
self.make_repository('target', shared=True)
359
except errors.IncompatibleFormat:
361
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
362
target.open_repository()
364
target.open_workingtree()
255
366
def test_sprout_bzrdir_repository(self):
256
367
dir = self.make_bzrdir('source')
265
376
self.assertNotEqual(dir.transport.base, target.transport.base)
266
377
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
379
def test_sprout_bzrdir_repository_under_shared(self):
380
tree = self.make_branch_and_tree('commit_tree')
381
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
383
tree.commit('revision 1', rev_id='1')
384
tree.bzrdir.open_branch().set_revision_history([])
385
tree.set_last_revision(None)
386
tree.commit('revision 2', rev_id='2')
387
source = self.make_repository('source')
388
tree.bzrdir.open_repository().copy_content_into(source)
391
shared_repo = self.make_repository('target', shared=True)
392
except errors.IncompatibleFormat:
394
target = dir.sprout(self.get_url('target/child'))
395
self.assertNotEqual(dir.transport.base, target.transport.base)
396
self.assertTrue(shared_repo.has_revision('1'))
398
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
399
tree = self.make_branch_and_tree('commit_tree')
400
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
402
tree.commit('revision 1', rev_id='1')
403
tree.bzrdir.open_branch().set_revision_history([])
404
tree.set_last_revision(None)
405
tree.commit('revision 2', rev_id='2')
406
source = self.make_repository('source')
407
tree.bzrdir.open_repository().copy_content_into(source)
410
shared_repo = self.make_repository('target', shared=True)
411
except errors.IncompatibleFormat:
413
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
414
self.assertNotEqual(dir.transport.base, target.transport.base)
415
self.assertFalse(shared_repo.has_revision('1'))
268
417
def test_sprout_bzrdir_repository_revision(self):
269
418
# test for revision limiting, [smoke test, not corner case checks].
270
419
# make a repository with some revisions,
296
445
self.assertNotEqual(dir.transport.base, target.transport.base)
297
446
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
448
def test_sprout_bzrdir_branch_and_repo_shared(self):
449
# sprouting a branch with a repo into a shared repo uses the shared
451
tree = self.make_branch_and_tree('commit_tree')
452
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
454
tree.commit('revision 1', rev_id='1')
455
source = self.make_branch('source')
456
tree.bzrdir.open_repository().copy_content_into(source.repository)
457
tree.bzrdir.open_branch().copy_content_into(source)
460
shared_repo = self.make_repository('target', shared=True)
461
except errors.IncompatibleFormat:
463
target = dir.sprout(self.get_url('target/child'))
464
self.assertTrue(shared_repo.has_revision('1'))
466
def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
467
# sprouting a branch with a repo into a shared repo uses the shared
469
tree = self.make_branch_and_tree('commit_tree')
470
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
472
tree.commit('revision 1', rev_id='1')
473
source = self.make_branch('source')
474
tree.bzrdir.open_repository().copy_content_into(source.repository)
475
tree.bzrdir.open_branch().copy_content_into(source)
478
shared_repo = self.make_repository('target', shared=True)
479
except errors.IncompatibleFormat:
481
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
482
self.assertNotEqual(dir.transport.base, target.transport.base)
483
self.assertFalse(shared_repo.has_revision('1'))
299
485
def test_sprout_bzrdir_branch_reference(self):
300
486
# sprouting should create a repository if needed and a sprouted branch.
301
487
referenced_branch = self.make_branch('referencced')
316
502
target.open_repository()
504
def test_sprout_bzrdir_branch_reference_shared(self):
505
# sprouting should create a repository if needed and a sprouted branch.
506
referenced_tree = self.make_branch_and_tree('referenced')
507
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
508
dir = self.make_bzrdir('source')
510
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
511
referenced_tree.branch)
512
except errors.IncompatibleFormat:
513
# this is ok too, not all formats have to support references.
515
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
517
shared_repo = self.make_repository('target', shared=True)
518
except errors.IncompatibleFormat:
520
target = dir.sprout(self.get_url('target/child'))
521
self.assertNotEqual(dir.transport.base, target.transport.base)
522
# we want target to have a branch that is in-place.
523
self.assertEqual(target, target.open_branch().bzrdir)
524
# and we want no repository as the target is shared
525
self.assertRaises(errors.NoRepositoryPresent,
526
target.open_repository)
527
# and we want revision '1' in the shared repo
528
self.assertTrue(shared_repo.has_revision('1'))
530
def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
531
# sprouting should create a repository if needed and a sprouted branch.
532
referenced_tree = self.make_branch_and_tree('referenced')
533
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
534
dir = self.make_bzrdir('source')
536
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
537
referenced_tree.branch)
538
except errors.IncompatibleFormat:
539
# this is ok too, not all formats have to support references.
541
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
543
shared_repo = self.make_repository('target', shared=True)
544
except errors.IncompatibleFormat:
546
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
547
self.assertNotEqual(dir.transport.base, target.transport.base)
548
# we want target to have a branch that is in-place.
549
self.assertEqual(target, target.open_branch().bzrdir)
550
# and we want revision '1' in the new repo
551
self.assertTrue(target.open_repository().has_revision('1'))
552
# but not the shared one
553
self.assertFalse(shared_repo.has_revision('1'))
318
555
def test_sprout_bzrdir_branch_revision(self):
319
556
# test for revision limiting, [smoke test, not corner case checks].
320
557
# make a repository with some revisions,
628
865
self.assertEqual(dir.root_transport.base,
629
866
get_transport(self.get_url('.')).base)
868
def test_find_repository_no_repo_under_standalone_branch(self):
869
# finding a repo stops at standalone branches even if there is a
870
# higher repository available.
872
repo = self.make_repository('.', shared=True)
873
except errors.IncompatibleFormat:
874
# need a shared repository to test this.
876
url = self.get_url('intermediate')
877
get_transport(self.get_url()).mkdir('intermediate')
878
get_transport(self.get_url()).mkdir('intermediate/child')
879
made_control = self.bzrdir_format.initialize(url)
880
made_control.create_repository()
881
innermost_control = self.bzrdir_format.initialize(
882
self.get_url('intermediate/child'))
884
child_repo = innermost_control.open_repository()
885
# if there is a repository, then the format cannot ever hit this
888
except errors.NoRepositoryPresent:
890
self.assertRaises(errors.NoRepositoryPresent,
891
innermost_control.find_repository)
893
def test_find_repository_containing_shared_repository(self):
894
# find repo inside a shared repo with an empty control dir
895
# returns the shared repo.
897
repo = self.make_repository('.', shared=True)
898
except errors.IncompatibleFormat:
899
# need a shared repository to test this.
901
url = self.get_url('childbzrdir')
902
get_transport(self.get_url()).mkdir('childbzrdir')
903
made_control = self.bzrdir_format.initialize(url)
905
child_repo = made_control.open_repository()
906
# if there is a repository, then the format cannot ever hit this
909
except errors.NoRepositoryPresent:
911
found_repo = made_control.find_repository()
912
self.assertEqual(repo.bzrdir.root_transport.base,
913
found_repo.bzrdir.root_transport.base)
915
def test_find_repository_standalone_with_containing_shared_repository(self):
916
# find repo inside a standalone repo inside a shared repo finds the standalone repo
918
containing_repo = self.make_repository('.', shared=True)
919
except errors.IncompatibleFormat:
920
# need a shared repository to test this.
922
child_repo = self.make_repository('childrepo')
923
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
924
found_repo = opened_control.find_repository()
925
self.assertEqual(child_repo.bzrdir.root_transport.base,
926
found_repo.bzrdir.root_transport.base)
928
def test_find_repository_shared_within_shared_repository(self):
929
# find repo at a shared repo inside a shared repo finds the inner repo
931
containing_repo = self.make_repository('.', shared=True)
932
except errors.IncompatibleFormat:
933
# need a shared repository to test this.
935
url = self.get_url('childrepo')
936
get_transport(self.get_url()).mkdir('childrepo')
937
child_control = self.bzrdir_format.initialize(url)
938
child_repo = child_control.create_repository(shared=True)
939
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
940
found_repo = opened_control.find_repository()
941
self.assertEqual(child_repo.bzrdir.root_transport.base,
942
found_repo.bzrdir.root_transport.base)
943
self.assertNotEqual(child_repo.bzrdir.root_transport.base,
944
containing_repo.bzrdir.root_transport.base)
946
def test_find_repository_with_nested_dirs_works(self):
947
# find repo inside a bzrdir inside a bzrdir inside a shared repo
948
# finds the outer shared repo.
950
repo = self.make_repository('.', shared=True)
951
except errors.IncompatibleFormat:
952
# need a shared repository to test this.
954
url = self.get_url('intermediate')
955
get_transport(self.get_url()).mkdir('intermediate')
956
get_transport(self.get_url()).mkdir('intermediate/child')
957
made_control = self.bzrdir_format.initialize(url)
959
child_repo = made_control.open_repository()
960
# if there is a repository, then the format cannot ever hit this
963
except errors.NoRepositoryPresent:
965
innermost_control = self.bzrdir_format.initialize(
966
self.get_url('intermediate/child'))
968
child_repo = innermost_control.open_repository()
969
# if there is a repository, then the format cannot ever hit this
972
except errors.NoRepositoryPresent:
974
found_repo = innermost_control.find_repository()
975
self.assertEqual(repo.bzrdir.root_transport.base,
976
found_repo.bzrdir.root_transport.base)
980
class ChrootedBzrDirTests(ChrootedTestCase):
982
def test_find_repository_no_repository(self):
983
# loopback test to check the current format fails to find a
984
# share repository correctly.
985
if not self.bzrdir_format.is_supported():
986
# unsupported formats are not loopback testable
987
# because the default open will not open them and
988
# they may not be initializable.
990
# supported formats must be able to init and open
991
url = self.get_url('subdir')
992
get_transport(self.get_url()).mkdir('subdir')
993
made_control = self.bzrdir_format.initialize(url)
995
repo = made_control.open_repository()
996
# if there is a repository, then the format cannot ever hit this
999
except errors.NoRepositoryPresent:
1001
opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1002
self.assertRaises(errors.NoRepositoryPresent,
1003
opened_control.find_repository)