53
53
class TestControlDir(TestCaseWithControlDir):
55
def skipIfNoWorkingTree(self, a_bzrdir):
56
"""Raises TestSkipped if a_bzrdir doesn't have a working tree.
55
def skipIfNoWorkingTree(self, a_controldir):
56
"""Raises TestSkipped if a_controldir doesn't have a working tree.
58
58
If the bzrdir does have a workingtree, this is a no-op.
61
a_bzrdir.open_workingtree()
61
a_controldir.open_workingtree()
62
62
except (errors.NotLocalUrl, errors.NoWorkingTree):
63
63
raise TestSkipped("bzrdir on transport %r has no working tree"
64
% a_controldir.transport)
66
def openWorkingTreeIfLocal(self, a_bzrdir):
67
"""If a_bzrdir is on a local transport, call open_workingtree() on it.
66
def openWorkingTreeIfLocal(self, a_controldir):
67
"""If a_controldir is on a local transport, call open_workingtree() on it.
69
if not isinstance(a_bzrdir.root_transport, LocalTransport):
69
if not isinstance(a_controldir.root_transport, LocalTransport):
70
70
# it's not local, but that's ok
72
a_bzrdir.open_workingtree()
72
a_controldir.open_workingtree()
74
def createWorkingTreeOrSkip(self, a_bzrdir):
75
"""Create a working tree on a_bzrdir, or raise TestSkipped.
74
def createWorkingTreeOrSkip(self, a_controldir):
75
"""Create a working tree on a_controldir, or raise TestSkipped.
77
77
A simple wrapper for create_workingtree that translates NotLocalUrl into
78
78
TestSkipped. Returns the newly created working tree.
81
return a_bzrdir.create_workingtree()
81
return a_controldir.create_workingtree()
82
82
except (errors.NotLocalUrl, errors.UnsupportedOperation):
83
83
raise TestSkipped("cannot make working tree with transport %r"
84
% a_controldir.transport)
86
86
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
87
87
force_new_repo=False, accelerator_tree=None,
162
162
def test_destroy_branch_no_branch(self):
163
163
branch = self.make_repository('branch')
164
bzrdir = branch.bzrdir
164
bzrdir = branch.controldir
166
166
self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
167
167
except (errors.UnsupportedOperation, errors.TransportNotPossible):
185
185
"""ControlDir.open_workingtree() should raise NoWorkingTree (rather than
186
186
e.g. NotLocalUrl) if there is no working tree.
188
dir = self.make_bzrdir('source')
188
dir = self.make_controldir('source')
189
189
vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
190
190
if vfs_dir.has_workingtree():
191
191
# This ControlDir format doesn't support ControlDirs without
197
197
def test_clone_bzrdir_repository_under_shared(self):
198
198
tree = self.make_branch_and_tree('commit_tree')
199
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
199
self.build_tree(['foo'], transport=tree.controldir.transport.clone('..'))
201
201
tree.commit('revision 1', rev_id='1')
202
dir = self.make_bzrdir('source')
202
dir = self.make_controldir('source')
203
203
repo = dir.create_repository()
204
204
if not repo._format.supports_nesting_repositories:
205
205
raise TestNotApplicable("repository format does not support "
228
228
# Make a branch, 'commit_tree', and working tree outside of the shared
229
229
# repository, and commit some revisions to it.
230
230
tree = self.make_branch_and_tree('commit_tree')
231
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
231
self.build_tree(['foo'], transport=tree.controldir.root_transport)
233
233
tree.commit('revision 1', rev_id='1')
234
tree.bzrdir.open_branch().generate_revision_history(
234
tree.controldir.open_branch().generate_revision_history(
235
235
_mod_revision.NULL_REVISION)
236
236
tree.set_parent_trees([])
237
237
tree.commit('revision 2', rev_id='2')
239
239
# repository into the shared repository.
240
240
tree.branch.repository.copy_content_into(shared_repo)
241
241
# Make a branch 'source' inside the shared repository.
242
dir = self.make_bzrdir('shared/source')
242
dir = self.make_controldir('shared/source')
243
243
dir.create_branch()
244
244
# Clone 'source' to 'target', also inside the shared repository.
245
245
target = dir.clone(self.get_url('shared/target'))
246
246
# 'source', 'target', and the shared repo all have distinct bzrdirs.
247
247
self.assertNotEqual(dir.transport.base, target.transport.base)
248
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
248
self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
249
249
# The shared repository will contain revisions from the 'commit_tree'
250
250
# repository, even revisions that are not part of the history of the
251
251
# 'commit_tree' branch.
264
264
self.build_tree(['commit_tree/foo'])
266
266
tree.commit('revision 1', rev_id='1')
267
tree.branch.bzrdir.open_branch().generate_revision_history(
267
tree.branch.controldir.open_branch().generate_revision_history(
268
268
_mod_revision.NULL_REVISION)
269
269
tree.set_parent_trees([])
270
270
tree.commit('revision 2', rev_id='2')
273
273
shared_repo.set_make_working_trees(False)
274
274
self.assertFalse(shared_repo.make_working_trees())
275
275
self.assertTrue(shared_repo.has_revision('1'))
276
dir = self.make_bzrdir('shared/source')
276
dir = self.make_controldir('shared/source')
277
277
dir.create_branch()
278
278
target = dir.clone(self.get_url('target'))
279
279
self.assertNotEqual(dir.transport.base, target.transport.base)
280
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
280
self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
281
281
branch = target.open_branch()
282
282
self.assertTrue(branch.repository.has_revision('1'))
283
283
self.assertFalse(branch.repository.make_working_trees())
292
292
self.build_tree(['commit_tree/foo'])
294
294
tree.commit('revision 1', rev_id='1')
295
tree.branch.bzrdir.open_branch().generate_revision_history(
295
tree.branch.controldir.open_branch().generate_revision_history(
296
296
_mod_revision.NULL_REVISION)
297
297
tree.set_parent_trees([])
298
298
tree.commit('revision 2', rev_id='2')
299
299
source = self.make_repository('source')
300
300
tree.branch.repository.copy_content_into(source)
301
dir = source.controldir
302
302
target = dir.clone(self.get_url('target'), revision_id='2')
303
303
raise TestSkipped('revision limiting not strict yet')
340
340
if not shared_repo._format.supports_nesting_repositories:
341
341
raise TestNotApplicable("format does not support nesting "
343
dir = source.controldir
344
344
target = dir.clone(self.get_url('target/child'))
345
345
self.assertNotEqual(dir.transport.base, target.transport.base)
346
346
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
360
360
source = self.make_branch('source')
361
361
tree.branch.repository.copy_content_into(source.repository)
362
362
tree.branch.copy_content_into(source)
363
dir = source.controldir
364
364
target = dir.clone(self.get_url('target'), revision_id='1')
365
365
self.assertEqual('1', target.open_branch().last_revision())
367
367
def test_clone_on_transport_preserves_repo_format(self):
368
if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
368
if self.bzrdir_format == controldir.format_registry.make_controldir('default'):
372
372
source_branch = self.make_branch('source', format=format)
373
373
# Ensure no format data is cached
374
374
a_dir = breezy.branch.Branch.open_from_transport(
375
self.get_transport('source')).bzrdir
375
self.get_transport('source')).controldir
376
376
target_transport = self.get_transport('target')
377
377
target_bzrdir = a_dir.clone_on_transport(target_transport)
378
378
target_repo = target_bzrdir.open_repository()
395
395
tree.commit('revision 1', rev_id='1')
396
396
tree.commit('revision 2', rev_id='2', allow_pointless=True)
397
dir = tree.controldir
398
398
target = dir.clone(self.get_url('target'), revision_id='1')
399
399
self.skipIfNoWorkingTree(target)
400
400
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
414
414
repo.set_make_working_trees(False)
415
415
self.assertFalse(repo.make_working_trees())
417
a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
417
a_dir = tree.controldir.clone(self.get_url('repo/a'))
418
418
a_branch = a_dir.open_branch()
419
419
# If the new control dir actually uses the repository, it should
420
420
# not have a working tree.
426
426
branch = self.make_branch('parent')
427
427
child_transport = self.get_transport('child')
429
child = branch.bzrdir.clone_on_transport(child_transport,
429
child = branch.controldir.clone_on_transport(child_transport,
430
430
stacked_on=branch.base)
431
431
except (errors.UnstackableBranchFormat,
432
432
errors.UnstackableRepositoryFormat):
437
437
def test_set_branch_reference(self):
438
438
"""set_branch_reference creates a branch reference"""
439
439
referenced_branch = self.make_branch('referenced')
440
dir = self.make_bzrdir('source')
440
dir = self.make_controldir('source')
442
442
reference = dir.set_branch_reference(referenced_branch)
443
443
except errors.IncompatibleFormat:
445
445
raise TestNotApplicable("control directory does not "
446
446
"support branch references")
447
447
self.assertEqual(
448
referenced_branch.bzrdir.root_transport.abspath('') + '/',
448
referenced_branch.controldir.root_transport.abspath('') + '/',
449
449
dir.get_branch_reference())
451
451
def test_set_branch_reference_on_existing_reference(self):
452
452
"""set_branch_reference creates a branch reference"""
453
453
referenced_branch1 = self.make_branch('old-referenced')
454
454
referenced_branch2 = self.make_branch('new-referenced')
455
dir = self.make_bzrdir('source')
455
dir = self.make_controldir('source')
457
457
reference = dir.set_branch_reference(referenced_branch1)
458
458
except errors.IncompatibleFormat:
461
461
"support branch references")
462
462
reference = dir.set_branch_reference(referenced_branch2)
463
463
self.assertEqual(
464
referenced_branch2.bzrdir.root_transport.abspath('') + '/',
464
referenced_branch2.controldir.root_transport.abspath('') + '/',
465
465
dir.get_branch_reference())
467
467
def test_set_branch_reference_on_existing_branch(self):
468
468
"""set_branch_reference creates a branch reference"""
469
469
referenced_branch = self.make_branch('referenced')
470
dir = self.make_branch('source').bzrdir
470
dir = self.make_branch('source').controldir
472
472
reference = dir.set_branch_reference(referenced_branch)
473
473
except errors.IncompatibleFormat:
475
475
raise TestNotApplicable("control directory does not "
476
476
"support branch references")
477
477
self.assertEqual(
478
referenced_branch.bzrdir.root_transport.abspath('') + '/',
478
referenced_branch.controldir.root_transport.abspath('') + '/',
479
479
dir.get_branch_reference())
481
481
def test_get_branch_reference_on_reference(self):
482
482
"""get_branch_reference should return the right url."""
483
483
referenced_branch = self.make_branch('referenced')
484
dir = self.make_bzrdir('source')
484
dir = self.make_controldir('source')
486
486
dir.set_branch_reference(referenced_branch)
487
487
except errors.IncompatibleFormat:
488
488
# this is ok too, not all formats have to support references.
489
489
raise TestNotApplicable("control directory does not "
490
490
"support branch references")
491
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
491
self.assertEqual(referenced_branch.controldir.root_transport.abspath('') + '/',
492
492
dir.get_branch_reference())
494
494
def test_get_branch_reference_on_non_reference(self):
495
495
"""get_branch_reference should return None for non-reference branches."""
496
496
branch = self.make_branch('referenced')
497
self.assertEqual(None, branch.bzrdir.get_branch_reference())
497
self.assertEqual(None, branch.controldir.get_branch_reference())
499
499
def test_get_branch_reference_no_branch(self):
500
500
"""get_branch_reference should not mask NotBranchErrors."""
501
dir = self.make_bzrdir('source')
501
dir = self.make_controldir('source')
502
502
if dir.has_branch():
503
503
# this format does not support branchless bzrdirs.
504
504
raise TestNotApplicable("format does not support "
506
506
self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
508
508
def test_sprout_bzrdir_empty(self):
509
dir = self.make_bzrdir('source')
509
dir = self.make_controldir('source')
510
510
target = dir.sprout(self.get_url('target'))
511
511
self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
512
512
# creates a new repository branch and tree
517
517
def test_sprout_bzrdir_empty_under_shared_repo(self):
518
518
# sprouting an empty dir into a repo uses the repo
519
dir = self.make_bzrdir('source')
519
dir = self.make_controldir('source')
521
521
self.make_repository('target', shared=True)
522
522
except errors.IncompatibleFormat:
530
530
except errors.NoWorkingTree:
531
531
# Some bzrdirs can never have working trees.
532
532
repo = target.find_repository()
533
self.assertFalse(repo.bzrdir._format.supports_workingtrees)
533
self.assertFalse(repo.controldir._format.supports_workingtrees)
535
535
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
536
536
# the force_new_repo parameter should force use of a new repo in an empty
537
537
# bzrdir's sprout logic
538
dir = self.make_bzrdir('source')
538
dir = self.make_controldir('source')
540
540
self.make_repository('target', shared=True)
541
541
except errors.IncompatibleFormat:
551
551
self.build_tree(['commit_tree/foo'])
553
553
tree.commit('revision 1', rev_id='1')
554
tree.bzrdir.open_branch().generate_revision_history(
554
tree.controldir.open_branch().generate_revision_history(
555
555
_mod_revision.NULL_REVISION)
556
556
tree.set_parent_trees([])
557
557
tree.commit('revision 2', rev_id='2')
558
558
source = self.make_repository('source')
559
559
tree.branch.repository.copy_content_into(source)
560
dir = source.controldir
562
562
shared_repo = self.make_repository('target', shared=True)
563
563
except errors.IncompatibleFormat:
580
580
self.build_tree(['commit_tree/foo'])
582
582
tree.commit('revision 1', rev_id='1')
583
tree.bzrdir.open_branch().generate_revision_history(
583
tree.controldir.open_branch().generate_revision_history(
584
584
_mod_revision.NULL_REVISION)
585
585
tree.set_parent_trees([])
586
586
tree.commit('revision 2', rev_id='2')
587
587
tree.branch.repository.copy_content_into(shared_repo)
588
dir = self.make_bzrdir('shared/source')
588
dir = self.make_controldir('shared/source')
589
589
dir.create_branch()
590
590
target = dir.sprout(self.get_url('shared/target'))
591
591
self.assertNotEqual(dir.transport.base, target.transport.base)
592
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
592
self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
593
593
self.assertTrue(shared_repo.has_revision('1'))
595
595
def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
605
605
self.build_tree(['commit_tree/foo'])
607
607
tree.commit('revision 1', rev_id='1')
608
tree.bzrdir.open_branch().generate_revision_history(
608
tree.controldir.open_branch().generate_revision_history(
609
609
_mod_revision.NULL_REVISION)
610
610
tree.set_parent_trees([])
611
611
tree.commit('revision 2', rev_id='2')
614
614
shared_repo.set_make_working_trees(False)
615
615
self.assertFalse(shared_repo.make_working_trees())
616
616
self.assertTrue(shared_repo.has_revision('1'))
617
dir = self.make_bzrdir('shared/source')
617
dir = self.make_controldir('shared/source')
618
618
dir.create_branch()
619
619
target = dir.sprout(self.get_url('target'))
620
620
self.assertNotEqual(dir.transport.base, target.transport.base)
621
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
621
self.assertNotEqual(dir.transport.base, shared_repo.controldir.transport.base)
622
622
branch = target.open_branch()
623
623
# The sprouted bzrdir has a branch, so only revisions referenced by
624
624
# that branch are copied, rather than the whole repository. It's an
625
625
# empty branch, so none are copied.
626
626
self.assertEqual([], branch.repository.all_revision_ids())
627
if branch.bzrdir._format.supports_workingtrees:
627
if branch.controldir._format.supports_workingtrees:
628
628
self.assertTrue(branch.repository.make_working_trees())
629
629
self.assertFalse(branch.repository.is_shared())
633
633
self.build_tree(['commit_tree/foo'])
635
635
tree.commit('revision 1', rev_id='1')
636
tree.bzrdir.open_branch().generate_revision_history(
636
tree.controldir.open_branch().generate_revision_history(
637
637
_mod_revision.NULL_REVISION)
638
638
tree.set_parent_trees([])
639
639
tree.commit('revision 2', rev_id='2')
640
640
source = self.make_repository('source')
641
641
tree.branch.repository.copy_content_into(source)
642
dir = source.controldir
644
644
shared_repo = self.make_repository('target', shared=True)
645
645
except errors.IncompatibleFormat:
660
660
self.build_tree(['commit_tree/foo'])
662
662
tree.commit('revision 1', rev_id='1')
663
br = tree.bzrdir.open_branch()
663
br = tree.controldir.open_branch()
664
664
br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
665
665
tree.set_parent_trees([])
666
666
tree.commit('revision 2', rev_id='2')
667
667
source = self.make_repository('source')
668
668
tree.branch.repository.copy_content_into(source)
669
dir = source.controldir
670
670
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
671
671
raise TestSkipped('revision limiting not strict yet')
679
679
tree.commit('revision 1', rev_id='1')
680
680
source = self.make_branch('source')
681
681
tree.branch.repository.copy_content_into(source.repository)
682
tree.bzrdir.open_branch().copy_content_into(source)
682
tree.controldir.open_branch().copy_content_into(source)
683
dir = source.controldir
685
685
shared_repo = self.make_repository('target', shared=True)
686
686
except errors.IncompatibleFormat:
698
698
tree.commit('revision 1', rev_id='1')
699
699
source = self.make_branch('source')
700
700
tree.branch.repository.copy_content_into(source.repository)
701
tree.bzrdir.open_branch().copy_content_into(source)
701
tree.controldir.open_branch().copy_content_into(source)
702
dir = source.controldir
704
704
shared_repo = self.make_repository('target', shared=True)
705
705
except errors.IncompatibleFormat:
712
712
def test_sprout_bzrdir_branch_reference(self):
713
713
# sprouting should create a repository if needed and a sprouted branch.
714
714
referenced_branch = self.make_branch('referenced')
715
dir = self.make_bzrdir('source')
715
dir = self.make_controldir('source')
717
717
dir.set_branch_reference(referenced_branch)
718
718
except errors.IncompatibleFormat:
722
722
target = dir.sprout(self.get_url('target'))
723
723
self.assertNotEqual(dir.transport.base, target.transport.base)
724
724
# we want target to have a branch that is in-place.
725
self.assertEqual(target, target.open_branch().bzrdir)
725
self.assertEqual(target, target.open_branch().controldir)
726
726
# and as we dont support repositories being detached yet, a repo in
728
728
target.open_repository()
731
731
# sprouting should create a repository if needed and a sprouted branch.
732
732
referenced_tree = self.make_branch_and_tree('referenced')
733
733
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
734
dir = self.make_bzrdir('source')
734
dir = self.make_controldir('source')
736
736
dir.set_branch_reference(referenced_tree.branch)
737
737
except errors.IncompatibleFormat:
746
746
target = dir.sprout(self.get_url('target/child'))
747
747
self.assertNotEqual(dir.transport.base, target.transport.base)
748
748
# we want target to have a branch that is in-place.
749
self.assertEqual(target, target.open_branch().bzrdir)
749
self.assertEqual(target, target.open_branch().controldir)
750
750
# and we want no repository as the target is shared
751
751
self.assertRaises(errors.NoRepositoryPresent,
752
752
target.open_repository)
757
757
# sprouting should create a repository if needed and a sprouted branch.
758
758
referenced_tree = self.make_branch_and_tree('referenced')
759
759
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
760
dir = self.make_bzrdir('source')
760
dir = self.make_controldir('source')
762
762
dir.set_branch_reference(referenced_tree.branch)
763
763
except errors.IncompatibleFormat:
773
773
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
774
774
self.assertNotEqual(dir.transport.base, target.transport.base)
775
775
# we want target to have a branch that is in-place.
776
self.assertEqual(target, target.open_branch().bzrdir)
776
self.assertEqual(target, target.open_branch().controldir)
777
777
# and we want revision '1' in the new repo
778
778
self.assertTrue(target.open_repository().has_revision('1'))
779
779
# but not the shared one
791
791
tree.commit('revision 2', rev_id='2', allow_pointless=True)
792
792
source = self.make_branch('source')
793
793
tree.branch.repository.copy_content_into(source.repository)
794
tree.bzrdir.open_branch().copy_content_into(source)
794
tree.controldir.open_branch().copy_content_into(source)
795
dir = source.controldir
796
796
target = dir.sprout(self.get_url('target'), revision_id='1')
797
797
self.assertEqual('1', target.open_branch().last_revision())
807
807
raise TestNotApplicable('Branch format does not support tags.')
808
808
source.get_config_stack().set('branch.fetch_tags', True)
809
809
# Now source has a tag not in its ancestry. Sprout its controldir.
810
dir = source.controldir
811
811
target = dir.sprout(self.get_url('target'))
812
812
# The tag is present, and so is its revision.
813
813
new_branch = target.open_branch()
846
846
'or tags referencing missing revisions.')
847
847
# Now source has a tag pointing to an absent revision. Sprout its
849
dir = source.controldir
850
850
target = dir.sprout(self.get_url('target'), source_branch=source)
851
851
# The tag is present in the target
852
852
new_branch = target.open_branch()
908
908
# sprouting should create a repository if needed and a sprouted branch.
909
909
# the tree state should not be copied.
910
910
referenced_branch = self.make_branch('referencced')
911
dir = self.make_bzrdir('source')
911
dir = self.make_controldir('source')
913
913
dir.set_branch_reference(referenced_branch)
914
914
except errors.IncompatibleFormat:
922
922
target = dir.sprout(self.get_url('target'))
923
923
self.assertNotEqual(dir.transport.base, target.transport.base)
924
924
# we want target to have a branch that is in-place.
925
self.assertEqual(target, target.open_branch().bzrdir)
925
self.assertEqual(target, target.open_branch().controldir)
926
926
# and as we dont support repositories being detached yet, a repo in
928
928
target.open_repository()
934
934
# the tree state should not be copied but the revision changed,
935
935
# and the likewise the new branch should be truncated too
936
936
referenced_branch = self.make_branch('referencced')
937
dir = self.make_bzrdir('source')
937
dir = self.make_controldir('source')
939
939
dir.set_branch_reference(referenced_branch)
940
940
except errors.IncompatibleFormat:
951
951
self.skipIfNoWorkingTree(target)
952
952
self.assertNotEqual(dir.transport.base, target.transport.base)
953
953
# we want target to have a branch that is in-place.
954
self.assertEqual(target, target.open_branch().bzrdir)
954
self.assertEqual(target, target.open_branch().controldir)
955
955
# and as we dont support repositories being detached yet, a repo in
957
957
target.open_repository()
971
971
tree.commit('revision 1', rev_id='1')
972
972
tree.commit('revision 2', rev_id='2', allow_pointless=True)
973
dir = tree.controldir
974
974
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
975
975
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
981
981
tree.commit('revision 1', rev_id='1')
982
982
tree.commit('revision 2', rev_id='2', allow_pointless=True)
983
dir = tree.controldir
984
984
target = self.sproutOrSkip(dir, self.get_url('target'),
985
985
accelerator_tree=tree)
986
986
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
992
992
tree.commit('revision 1', rev_id='1')
993
993
tree.commit('revision 2', rev_id='2', allow_pointless=True)
994
dir = tree.controldir
996
996
target = dir.sprout(self.get_url('target'),
997
997
create_tree_if_local=False)
1011
1011
builder.finish_series()
1012
1012
stack_on = builder.get_branch()
1013
1013
# Make a bzrdir with a default stacking policy to stack on that branch.
1014
config = self.make_bzrdir('policy-dir').get_config()
1014
config = self.make_controldir('policy-dir').get_config()
1016
1016
config.set_default_stack_on(self.get_url('stack-on'))
1017
1017
except errors.BzrError:
1018
1018
raise TestNotApplicable('Only relevant for stackable formats.')
1019
1019
# Sprout the stacked-on branch into the bzrdir.
1020
sprouted = stack_on.bzrdir.sprout(
1020
sprouted = stack_on.controldir.sprout(
1021
1021
self.get_url('policy-dir/sprouted'), revision_id='rev-3')
1022
1022
# Not all revisions are copied into the sprouted repository.
1023
1023
repo = sprouted.open_repository()
1087
1087
def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1088
1088
t = self.get_transport('repo')
1089
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1089
repo_fmt = controldir.format_registry.make_controldir('1.9')
1090
1090
repo_name = repo_fmt.repository_format.network_name()
1091
1091
repo = repo_fmt.initialize_on_transport_ex(t,
1092
1092
repo_format_name=repo_name, shared_repo=True)[0]
1093
1093
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1094
1094
force_new_repo=True, repo_format_name=repo_name)
1095
self.assertNotEqual(repo.bzrdir.root_transport.base,
1096
made_repo.bzrdir.root_transport.base)
1095
self.assertNotEqual(repo.controldir.root_transport.base,
1096
made_repo.controldir.root_transport.base)
1098
1098
def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1099
1099
t = self.get_transport('repo')
1100
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1100
repo_fmt = controldir.format_registry.make_controldir('1.9')
1101
1101
repo_name = repo_fmt.repository_format.network_name()
1102
1102
repo = repo_fmt.initialize_on_transport_ex(t,
1103
1103
repo_format_name=repo_name, shared_repo=True)[0]
1104
1104
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1105
1105
force_new_repo=False, repo_format_name=repo_name)
1106
1106
if not control._format.fixed_components:
1107
self.assertEqual(repo.bzrdir.root_transport.base,
1108
made_repo.bzrdir.root_transport.base)
1107
self.assertEqual(repo.controldir.root_transport.base,
1108
made_repo.controldir.root_transport.base)
1110
1110
def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1111
1111
t = self.get_transport('dir')
1115
1115
def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1116
1116
t = self.get_transport('dir')
1117
1117
# 1.6 is likely to never be default
1118
fmt = controldir.format_registry.make_bzrdir('1.6')
1118
fmt = controldir.format_registry.make_controldir('1.6')
1119
1119
repo_name = fmt.repository_format.network_name()
1120
1120
repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1121
1121
if self.bzrdir_format.fixed_components:
1157
1157
def test_format_network_name(self):
1158
1158
# All control formats must have a network name.
1159
dir = self.make_bzrdir('.')
1159
dir = self.make_controldir('.')
1160
1160
format = dir._format
1161
1161
# We want to test that the network_name matches the actual format on
1162
1162
# disk. For local control dirsthat means that using network_name as a
1195
1195
made_repo = made_control.create_repository()
1196
1196
made_branch = made_control.create_branch()
1197
1197
self.assertIsInstance(made_branch, breezy.branch.Branch)
1198
self.assertEqual(made_control, made_branch.bzrdir)
1198
self.assertEqual(made_control, made_branch.controldir)
1200
1200
def test_create_branch_append_revisions_only(self):
1201
1201
# a bzrdir can construct a branch and repository for itself.
1215
1215
"append_revisions_only setting")
1216
1216
self.assertIsInstance(made_branch, breezy.branch.Branch)
1217
1217
self.assertEqual(True, made_branch.get_append_revisions_only())
1218
self.assertEqual(made_control, made_branch.bzrdir)
1218
self.assertEqual(made_control, made_branch.controldir)
1220
1220
def test_open_branch(self):
1221
1221
if not self.bzrdir_format.is_initializable():
1228
1228
made_repo = made_control.create_repository()
1229
1229
made_branch = made_control.create_branch()
1230
1230
opened_branch = made_control.open_branch()
1231
self.assertEqual(made_control, opened_branch.bzrdir)
1231
self.assertEqual(made_control, opened_branch.controldir)
1232
1232
self.assertIsInstance(opened_branch, made_branch.__class__)
1233
1233
self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1252
1252
def test_get_branches(self):
1253
1253
repo = self.make_repository('branch-1')
1254
target_branch = repo.bzrdir.create_branch()
1255
self.assertEqual([""], list(repo.bzrdir.get_branches()))
1254
target_branch = repo.controldir.create_branch()
1255
self.assertEqual([""], list(repo.controldir.get_branches()))
1257
1257
def test_create_repository(self):
1258
1258
# a bzrdir can construct a repository for itself.
1266
1266
made_repo = made_control.create_repository()
1267
1267
# Check that we have a repository object.
1268
1268
made_repo.has_revision('foo')
1269
self.assertEqual(made_control, made_repo.bzrdir)
1269
self.assertEqual(made_control, made_repo.controldir)
1271
1271
def test_create_repository_shared(self):
1272
1272
# a bzrdir can create a shared repository or
1315
1315
made_control = self.bzrdir_format.initialize(t.base)
1316
1316
made_repo = made_control.create_repository()
1317
1317
opened_repo = made_control.open_repository()
1318
self.assertEqual(made_control, opened_repo.bzrdir)
1318
self.assertEqual(made_control, opened_repo.controldir)
1319
1319
self.assertIsInstance(opened_repo, made_repo.__class__)
1320
1320
self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1332
1332
made_branch = made_control.create_branch()
1333
1333
made_tree = self.createWorkingTreeOrSkip(made_control)
1334
1334
self.assertIsInstance(made_tree, workingtree.WorkingTree)
1335
self.assertEqual(made_control, made_tree.bzrdir)
1335
self.assertEqual(made_control, made_tree.controldir)
1337
1337
def test_create_workingtree_revision(self):
1338
1338
# a bzrdir can construct a working tree for itself @ a specific revision.
1368
1368
raise TestSkipped("Can't initialize %r on transport %r"
1369
1369
% (self.bzrdir_format, t))
1370
1370
opened_tree = made_control.open_workingtree()
1371
self.assertEqual(made_control, opened_tree.bzrdir)
1371
self.assertEqual(made_control, opened_tree.controldir)
1372
1372
self.assertIsInstance(opened_tree, made_tree.__class__)
1373
1373
self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1402
1402
self.assertEqual(u"", dir._get_selected_branch())
1404
1404
def test_root_transport(self):
1405
dir = self.make_bzrdir('.')
1405
dir = self.make_controldir('.')
1406
1406
self.assertEqual(dir.root_transport.base,
1407
1407
self.get_transport().base)
1457
1457
except errors.NoRepositoryPresent:
1459
1459
found_repo = made_control.find_repository()
1460
self.assertEqual(repo.bzrdir.root_transport.base,
1461
found_repo.bzrdir.root_transport.base)
1460
self.assertEqual(repo.controldir.root_transport.base,
1461
found_repo.controldir.root_transport.base)
1463
1463
def test_find_repository_standalone_with_containing_shared_repository(self):
1464
1464
# find repo inside a standalone repo inside a shared repo finds the
1475
1475
child_repo = self.make_repository('childrepo')
1476
1476
opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1477
1477
found_repo = opened_control.find_repository()
1478
self.assertEqual(child_repo.bzrdir.root_transport.base,
1479
found_repo.bzrdir.root_transport.base)
1478
self.assertEqual(child_repo.controldir.root_transport.base,
1479
found_repo.controldir.root_transport.base)
1481
1481
def test_find_repository_shared_within_shared_repository(self):
1482
1482
# find repo at a shared repo inside a shared repo finds the inner repo
1495
1495
child_repo = child_control.create_repository(shared=True)
1496
1496
opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1497
1497
found_repo = opened_control.find_repository()
1498
self.assertEqual(child_repo.bzrdir.root_transport.base,
1499
found_repo.bzrdir.root_transport.base)
1500
self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1501
containing_repo.bzrdir.root_transport.base)
1498
self.assertEqual(child_repo.controldir.root_transport.base,
1499
found_repo.controldir.root_transport.base)
1500
self.assertNotEqual(child_repo.controldir.root_transport.base,
1501
containing_repo.controldir.root_transport.base)
1503
1503
def test_find_repository_with_nested_dirs_works(self):
1504
1504
# find repo inside a bzrdir inside a bzrdir inside a shared repo
1534
1534
except errors.NoRepositoryPresent:
1536
1536
found_repo = innermost_control.find_repository()
1537
self.assertEqual(repo.bzrdir.root_transport.base,
1538
found_repo.bzrdir.root_transport.base)
1537
self.assertEqual(repo.controldir.root_transport.base,
1538
found_repo.controldir.root_transport.base)
1540
1540
def test_can_and_needs_format_conversion(self):
1541
1541
# check that we can ask an instance if its upgradable
1542
dir = self.make_bzrdir('.')
1542
dir = self.make_controldir('.')
1543
1543
if dir.can_convert_format():
1544
1544
# if its default updatable there must be an updater
1545
1545
# (we force the latest known format as downgrades may not be
1554
1554
self.build_tree(['test/a'])
1555
1555
tree.add(['a'], ['a-id'])
1556
1556
tree.commit('some data to be copied.')
1557
old_url, new_url = tree.bzrdir.backup_bzrdir()
1557
old_url, new_url = tree.controldir.backup_bzrdir()
1558
1558
old_path = urlutils.local_path_from_url(old_url)
1559
1559
new_path = urlutils.local_path_from_url(new_url)
1560
1560
self.assertPathExists(old_path)
1573
1573
def test_upgrade_new_instance(self):
1574
1574
"""Does an available updater work?"""
1575
dir = self.make_bzrdir('.')
1575
dir = self.make_controldir('.')
1576
1576
# for now, upgrade is not ready for partial bzrdirs.
1577
1577
dir.create_repository()
1578
1578
dir.create_branch()
1590
1590
check.check_dwim(self.get_url('.'), False, True, True)
1592
1592
def test_format_description(self):
1593
dir = self.make_bzrdir('.')
1593
dir = self.make_controldir('.')
1594
1594
text = dir._format.get_format_description()
1595
1595
self.assertTrue(len(text))
1609
1609
# break lock with just a repo should unlock the repo.
1610
1610
repo = self.make_repository('.')
1611
1611
repo.lock_write()
1612
lock_repo = repo.bzrdir.open_repository()
1612
lock_repo = repo.controldir.open_repository()
1613
1613
if not lock_repo.get_physical_lock_status():
1614
1614
# This bzrdir's default repository does not physically lock things
1615
1615
# and thus this interaction cannot be tested at the interface
1636
1636
# and repository in another bzrdir
1637
1637
# for pre-metadir formats this will fail, thats ok.
1638
1638
master = self.make_branch('branch')
1639
thisdir = self.make_bzrdir('this')
1639
thisdir = self.make_controldir('this')
1641
1641
thisdir.set_branch_reference(master)
1642
1642
except errors.IncompatibleFormat:
1663
1663
self.assertEqual([True, True],
1664
1664
breezy.ui.ui_factory.responses)
1665
1665
# we should be able to lock a newly opened branch now
1666
branch = master.bzrdir.open_branch()
1666
branch = master.controldir.open_branch()
1667
1667
branch.lock_write()
1668
1668
branch.unlock()
1669
1669
if this_repo_locked:
1687
1687
# three yes's : tree, branch and repository.
1688
1688
breezy.ui.ui_factory = CannedInputUIFactory([True, True, True])
1690
tree.bzrdir.break_lock()
1690
tree.controldir.break_lock()
1691
1691
except (NotImplementedError, errors.LockActive):
1692
1692
# bzrdir does not support break_lock
1693
1693
# or one of the locked objects (currently only tree does this)
1697
1697
raise TestNotApplicable("format does not support breaking locks")
1698
1698
self.assertEqual([True],
1699
1699
breezy.ui.ui_factory.responses)
1700
lock_tree = tree.bzrdir.open_workingtree()
1700
lock_tree = tree.controldir.open_workingtree()
1701
1701
lock_tree.lock_write()
1702
1702
lock_tree.unlock()
1703
1703
self.assertRaises(errors.LockBroken, tree.unlock)
1706
1706
class TestTransportConfig(TestCaseWithControlDir):
1708
1708
def test_get_config(self):
1709
my_dir = self.make_bzrdir('.')
1709
my_dir = self.make_controldir('.')
1710
1710
config = my_dir.get_config()
1712
1712
config.set_default_stack_on('http://example.com')
1757
1757
"""ControlDir implementations adequately implement ControlComponent."""
1759
1759
def test_urls(self):
1760
bd = self.make_bzrdir('bd')
1760
bd = self.make_controldir('bd')
1761
1761
self.assertIsInstance(bd.user_url, str)
1762
1762
self.assertEqual(bd.user_url, bd.user_transport.base)
1763
1763
# for all current bzrdir implementations the user dir must be