136
137
raise TestSkipped("cannot make working tree with transport %r"
137
138
% a_bzrdir.transport)
139
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
140
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
140
141
force_new_repo=False):
141
142
"""Sprout from_bzrdir into to_url, or raise TestSkipped.
232
232
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
234
234
def test_clone_bzrdir_repository_branch_both_under_shared(self):
235
# Create a shared repository
236
237
shared_repo = self.make_repository('shared', shared=True)
237
238
except errors.IncompatibleFormat:
240
# Make a branch, 'commit_tree', and working tree outside of the shared
241
# repository, and commit some revisions to it.
239
242
tree = self.make_branch_and_tree('commit_tree')
240
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
243
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
242
245
tree.commit('revision 1', rev_id='1')
243
246
tree.bzrdir.open_branch().set_revision_history([])
244
247
tree.set_parent_trees([])
245
248
tree.commit('revision 2', rev_id='2')
246
tree.bzrdir.open_repository().copy_content_into(shared_repo)
249
# Copy the content (i.e. revisions) from the 'commit_tree' branch's
250
# repository into the shared repository.
251
tree.branch.repository.copy_content_into(shared_repo)
252
# Make a branch 'source' inside the shared repository.
247
253
dir = self.make_bzrdir('shared/source')
248
254
dir.create_branch()
255
# Clone 'source' to 'target', also inside the shared repository.
249
256
target = dir.clone(self.get_url('shared/target'))
257
# 'source', 'target', and the shared repo all have distinct bzrdirs.
250
258
self.assertNotEqual(dir.transport.base, target.transport.base)
251
259
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
260
# The shared repository will contain revisions from the 'commit_tree'
261
# repository, even revisions that are not part of the history of the
262
# 'commit_tree' branch.
252
263
self.assertTrue(shared_repo.has_revision('1'))
254
265
def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
257
268
except errors.IncompatibleFormat:
259
270
tree = self.make_branch_and_tree('commit_tree')
260
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
271
self.build_tree(['commit_tree/foo'])
262
273
tree.commit('revision 1', rev_id='1')
263
tree.bzrdir.open_branch().set_revision_history([])
274
tree.branch.bzrdir.open_branch().set_revision_history([])
264
275
tree.set_parent_trees([])
265
276
tree.commit('revision 2', rev_id='2')
266
tree.bzrdir.open_repository().copy_content_into(shared_repo)
267
shared_repo.set_make_working_trees(False)
268
self.assertFalse(shared_repo.make_working_trees())
277
tree.branch.repository.copy_content_into(shared_repo)
278
if shared_repo.make_working_trees():
279
shared_repo.set_make_working_trees(False)
280
self.assertFalse(shared_repo.make_working_trees())
269
281
self.assertTrue(shared_repo.has_revision('1'))
270
282
dir = self.make_bzrdir('shared/source')
271
283
dir.create_branch()
280
292
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
281
293
tree = self.make_branch_and_tree('commit_tree')
282
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
294
self.build_tree(['commit_tree/foo'])
284
296
tree.commit('revision 1', rev_id='1')
285
297
dir = self.make_bzrdir('source')
302
314
# and clone it with a revision limit.
304
316
tree = self.make_branch_and_tree('commit_tree')
305
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
317
self.build_tree(['commit_tree/foo'])
307
319
tree.commit('revision 1', rev_id='1')
308
tree.bzrdir.open_branch().set_revision_history([])
320
tree.branch.bzrdir.open_branch().set_revision_history([])
309
321
tree.set_parent_trees([])
310
322
tree.commit('revision 2', rev_id='2')
311
323
source = self.make_repository('source')
312
tree.bzrdir.open_repository().copy_content_into(source)
324
tree.branch.repository.copy_content_into(source)
313
325
dir = source.bzrdir
314
326
target = dir.clone(self.get_url('target'), revision_id='2')
315
327
raise TestSkipped('revision limiting not strict yet')
317
329
def test_clone_bzrdir_branch_and_repo(self):
318
330
tree = self.make_branch_and_tree('commit_tree')
319
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
331
self.build_tree(['commit_tree/foo'])
321
333
tree.commit('revision 1')
322
334
source = self.make_branch('source')
337
349
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
338
350
# by default cloning into a shared repo uses the shared repo.
339
351
tree = self.make_branch_and_tree('commit_tree')
340
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
352
self.build_tree(['commit_tree/foo'])
342
354
tree.commit('revision 1')
343
355
source = self.make_branch('source')
357
369
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
358
370
# by default cloning into a shared repo uses the shared repo.
359
371
tree = self.make_branch_and_tree('commit_tree')
360
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
372
self.build_tree(['commit_tree/foo'])
362
374
tree.commit('revision 1')
363
375
source = self.make_branch('source')
397
409
# and clone it with a revision limit.
399
411
tree = self.make_branch_and_tree('commit_tree')
400
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
412
self.build_tree(['commit_tree/foo'])
402
414
tree.commit('revision 1', rev_id='1')
403
415
tree.commit('revision 2', rev_id='2', allow_pointless=True)
409
421
self.assertEqual('1', target.open_branch().last_revision())
411
423
def test_clone_bzrdir_tree_branch_repo(self):
412
tree = self.make_branch_and_tree('sourcce')
413
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
424
tree = self.make_branch_and_tree('source')
425
self.build_tree(['source/foo'])
415
427
tree.commit('revision 1')
416
428
dir = tree.bzrdir
429
441
target.open_workingtree().revert([])
431
443
def test_revert_inventory(self):
432
tree = self.make_branch_and_tree('sourcce')
433
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
444
tree = self.make_branch_and_tree('source')
445
self.build_tree(['source/foo'])
435
447
tree.commit('revision 1')
436
448
dir = tree.bzrdir
485
497
# This smoke test just checks the revision-id is right. Tree specific
486
498
# tests will check corner cases.
487
499
tree = self.make_branch_and_tree('source')
488
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
500
self.build_tree(['source/foo'])
490
502
tree.commit('revision 1', rev_id='1')
491
503
tree.commit('revision 2', rev_id='2', allow_pointless=True)
494
506
self.skipIfNoWorkingTree(target)
495
507
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
497
def test_clone_bzrdir_incomplete_source_with_basis(self):
498
# ensure that basis really does grab from the basis by having incomplete source
499
tree = self.make_branch_and_tree('commit_tree')
500
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
502
tree.commit('revision 1', rev_id='1')
503
source = self.make_branch_and_tree('source')
504
# this gives us an incomplete repository
505
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
506
tree.commit('revision 2', rev_id='2', allow_pointless=True)
507
tree.bzrdir.open_branch().copy_content_into(source.branch)
508
tree.copy_content_into(source)
509
self.assertFalse(source.branch.repository.has_revision('2'))
511
target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
512
self.assertEqual('2', target.open_branch().last_revision())
509
def test_get_branch_reference_on_reference(self):
510
"""get_branch_reference should return the right url."""
511
referenced_branch = self.make_branch('referenced')
512
dir = self.make_bzrdir('source')
514
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
515
except errors.NoWorkingTree:
516
# It should have a working tree if it's able to have one, so if
517
# we're here make sure it really can't have one.
518
self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
519
self.assertTrue(target.open_branch().repository.has_revision('2'))
514
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
516
except errors.IncompatibleFormat:
517
# this is ok too, not all formats have to support references.
519
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
520
dir.get_branch_reference())
522
def test_get_branch_reference_on_non_reference(self):
523
"""get_branch_reference should return None for non-reference branches."""
524
branch = self.make_branch('referenced')
525
self.assertEqual(None, branch.bzrdir.get_branch_reference())
527
def test_get_branch_reference_no_branch(self):
528
"""get_branch_reference should not mask NotBranchErrors."""
529
dir = self.make_bzrdir('source')
531
# this format does not support branchless bzrdirs.
533
self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
521
535
def test_sprout_bzrdir_empty(self):
522
536
dir = self.make_bzrdir('source')
537
551
target = self.sproutOrSkip(dir, self.get_url('target/child'))
538
552
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
539
553
target.open_branch()
540
target.open_workingtree()
555
target.open_workingtree()
556
except errors.NotLocalUrl:
557
# bzrdir's that test against non-local urls are allowed to pass:
558
# whitelist them for now
559
self.assertIsInstance(target, RemoteBzrDir)
542
561
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
543
562
# the force_new_repo parameter should force use of a new repo in an empty
592
611
def test_sprout_bzrdir_with_repository_to_shared(self):
593
612
tree = self.make_branch_and_tree('commit_tree')
594
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
613
self.build_tree(['commit_tree/foo'])
596
615
tree.commit('revision 1', rev_id='1')
597
616
tree.bzrdir.open_branch().set_revision_history([])
598
617
tree.set_parent_trees([])
599
618
tree.commit('revision 2', rev_id='2')
600
619
source = self.make_repository('source')
601
tree.bzrdir.open_repository().copy_content_into(source)
620
tree.branch.repository.copy_content_into(source)
602
621
dir = source.bzrdir
604
623
shared_repo = self.make_repository('target', shared=True)
614
633
except errors.IncompatibleFormat:
616
635
tree = self.make_branch_and_tree('commit_tree')
617
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
636
self.build_tree(['commit_tree/foo'])
619
638
tree.commit('revision 1', rev_id='1')
620
639
tree.bzrdir.open_branch().set_revision_history([])
621
640
tree.set_parent_trees([])
622
641
tree.commit('revision 2', rev_id='2')
623
tree.bzrdir.open_repository().copy_content_into(shared_repo)
642
tree.branch.repository.copy_content_into(shared_repo)
624
643
dir = self.make_bzrdir('shared/source')
625
644
dir.create_branch()
626
645
target = self.sproutOrSkip(dir, self.get_url('shared/target'))
634
653
except errors.IncompatibleFormat:
636
655
tree = self.make_branch_and_tree('commit_tree')
637
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
656
self.build_tree(['commit_tree/foo'])
639
658
tree.commit('revision 1', rev_id='1')
640
659
tree.bzrdir.open_branch().set_revision_history([])
641
660
tree.set_parent_trees([])
642
661
tree.commit('revision 2', rev_id='2')
643
tree.bzrdir.open_repository().copy_content_into(shared_repo)
644
shared_repo.set_make_working_trees(False)
645
self.assertFalse(shared_repo.make_working_trees())
662
tree.branch.repository.copy_content_into(shared_repo)
663
if shared_repo.make_working_trees():
664
shared_repo.set_make_working_trees(False)
665
self.assertFalse(shared_repo.make_working_trees())
646
666
self.assertTrue(shared_repo.has_revision('1'))
647
667
dir = self.make_bzrdir('shared/source')
648
668
dir.create_branch()
651
671
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
652
672
branch = target.open_branch()
653
673
self.assertTrue(branch.repository.has_revision('1'))
654
self.assertTrue(branch.repository.make_working_trees())
674
if not isinstance(branch.bzrdir, RemoteBzrDir):
675
self.assertTrue(branch.repository.make_working_trees())
655
676
self.assertFalse(branch.repository.is_shared())
657
678
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
658
679
tree = self.make_branch_and_tree('commit_tree')
659
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
680
self.build_tree(['commit_tree/foo'])
661
682
tree.commit('revision 1', rev_id='1')
662
683
tree.bzrdir.open_branch().set_revision_history([])
663
684
tree.set_parent_trees([])
664
685
tree.commit('revision 2', rev_id='2')
665
686
source = self.make_repository('source')
666
tree.bzrdir.open_repository().copy_content_into(source)
687
tree.branch.repository.copy_content_into(source)
667
688
dir = source.bzrdir
669
690
shared_repo = self.make_repository('target', shared=True)
680
701
# and sprout it with a revision limit.
682
703
tree = self.make_branch_and_tree('commit_tree')
683
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
704
self.build_tree(['commit_tree/foo'])
685
706
tree.commit('revision 1', rev_id='1')
686
707
tree.bzrdir.open_branch().set_revision_history([])
687
708
tree.set_parent_trees([])
688
709
tree.commit('revision 2', rev_id='2')
689
710
source = self.make_repository('source')
690
tree.bzrdir.open_repository().copy_content_into(source)
711
tree.branch.repository.copy_content_into(source)
691
712
dir = source.bzrdir
692
713
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
693
714
raise TestSkipped('revision limiting not strict yet')
695
716
def test_sprout_bzrdir_branch_and_repo(self):
696
717
tree = self.make_branch_and_tree('commit_tree')
697
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
718
self.build_tree(['commit_tree/foo'])
699
720
tree.commit('revision 1')
700
721
source = self.make_branch('source')
701
tree.bzrdir.open_repository().copy_content_into(source.repository)
722
tree.branch.repository.copy_content_into(source.repository)
702
723
tree.bzrdir.open_branch().copy_content_into(source)
703
724
dir = source.bzrdir
704
725
target = self.sproutOrSkip(dir, self.get_url('target'))
722
743
# sprouting a branch with a repo into a shared repo uses the shared
724
745
tree = self.make_branch_and_tree('commit_tree')
725
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
746
self.build_tree(['commit_tree/foo'])
727
748
tree.commit('revision 1', rev_id='1')
728
749
source = self.make_branch('source')
729
tree.bzrdir.open_repository().copy_content_into(source.repository)
750
tree.branch.repository.copy_content_into(source.repository)
730
751
tree.bzrdir.open_branch().copy_content_into(source)
731
752
dir = source.bzrdir
740
761
# sprouting a branch with a repo into a shared repo uses the shared
742
763
tree = self.make_branch_and_tree('commit_tree')
743
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
764
self.build_tree(['commit_tree/foo'])
745
766
tree.commit('revision 1', rev_id='1')
746
767
source = self.make_branch('source')
747
tree.bzrdir.open_repository().copy_content_into(source.repository)
768
tree.branch.repository.copy_content_into(source.repository)
748
769
tree.bzrdir.open_branch().copy_content_into(source)
749
770
dir = source.bzrdir
833
854
# and sprout it with a revision limit.
835
856
tree = self.make_branch_and_tree('commit_tree')
836
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
857
self.build_tree(['commit_tree/foo'])
838
859
tree.commit('revision 1', rev_id='1')
839
860
tree.commit('revision 2', rev_id='2', allow_pointless=True)
840
861
source = self.make_branch('source')
841
tree.bzrdir.open_repository().copy_content_into(source.repository)
862
tree.branch.repository.copy_content_into(source.repository)
842
863
tree.bzrdir.open_branch().copy_content_into(source)
843
864
dir = source.bzrdir
844
865
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
845
866
self.assertEqual('1', target.open_branch().last_revision())
847
868
def test_sprout_bzrdir_tree_branch_repo(self):
848
tree = self.make_branch_and_tree('sourcce')
869
tree = self.make_branch_and_tree('source')
849
870
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
851
872
tree.commit('revision 1')
935
956
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
936
957
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
938
def test_sprout_bzrdir_incomplete_source_with_basis(self):
939
# ensure that basis really does grab from the basis by having incomplete source
940
tree = self.make_branch_and_tree('commit_tree')
941
self.build_tree(['commit_tree/foo'])
943
tree.commit('revision 1', rev_id='1')
944
source = self.make_branch_and_tree('source')
945
# this gives us an incomplete repository
946
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
947
tree.commit('revision 2', rev_id='2', allow_pointless=True)
948
tree.bzrdir.open_branch().copy_content_into(source.branch)
949
tree.copy_content_into(source)
950
self.assertFalse(source.branch.repository.has_revision('2'))
952
target = self.sproutOrSkip(dir, self.get_url('target'),
954
self.assertEqual('2', target.open_branch().last_revision())
955
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
956
self.assertTrue(target.open_branch().repository.has_revision('2'))
958
959
def test_format_initialize_find_open(self):
959
960
# loopback test to check the current format initializes to itself.
960
961
if not self.bzrdir_format.is_supported():
1091
1092
source = self.make_branch_and_tree('source')
1092
1093
source.commit('a', rev_id='a', allow_pointless=True)
1093
1094
source.commit('b', rev_id='b', allow_pointless=True)
1094
self.build_tree(['new/'])
1095
1096
t_new = t.clone('new')
1096
1097
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1097
1098
source.branch.repository.clone(made_control)
1340
1341
def test_retire_bzrdir(self):
1341
1342
bd = self.make_bzrdir('.')
1343
transport = bd.root_transport
1342
1344
# must not overwrite existing directories
1343
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1344
self.failUnlessExists('.bzr')
1345
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1346
transport=transport)
1347
self.failUnless(transport.has('.bzr'))
1345
1348
bd.retire_bzrdir()
1346
self.failIfExists('.bzr')
1347
self.failUnlessExists('.bzr.retired.1')
1349
self.failIf(transport.has('.bzr'))
1350
self.failUnless(transport.has('.bzr.retired.1'))
1349
1352
class TestBreakLock(TestCaseWithBzrDir):