101
98
create_tree_if_local=create_tree_if_local)
104
def test_uninitializable(self):
105
if self.bzrdir_format.is_initializable():
106
raise TestNotApplicable("format is initializable")
107
t = self.get_transport()
108
self.assertRaises(errors.UninitializableFormat,
109
self.bzrdir_format.initialize, t.base)
111
def test_multiple_initialization(self):
112
# loopback test to check the current format initializes to itself.
113
if not self.bzrdir_format.is_initializable():
114
# unsupported formats are not loopback testable
115
# because the default open will not open them and
116
# they may not be initializable.
117
raise TestNotApplicable("format is not initializable")
118
self.bzrdir_format.initialize('.')
119
self.assertRaises(errors.AlreadyControlDirError,
120
self.bzrdir_format.initialize, '.')
122
101
def test_create_null_workingtree(self):
123
102
dir = self.make_bzrdir('dir1')
124
103
dir.create_repository()
125
104
dir.create_branch()
127
wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
106
wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
128
107
except (errors.NotLocalUrl, errors.UnsupportedOperation):
129
108
raise TestSkipped("cannot make working tree with transport %r"
333
286
tree.branch.repository.copy_content_into(source.repository)
334
287
tree.branch.copy_content_into(source)
336
shared_repo = self.make_repository('target', shared=True)
289
self.make_repository('target', shared=True)
337
290
except errors.IncompatibleFormat:
338
raise TestNotApplicable("repository format does not support "
339
"shared repositories")
340
if not shared_repo._format.supports_nesting_repositories:
341
raise TestNotApplicable("format does not support nesting "
343
292
dir = source.bzrdir
344
293
target = dir.clone(self.get_url('target/child'))
345
294
self.assertNotEqual(dir.transport.base, target.transport.base)
346
295
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
347
self.assertEqual(source.last_revision(),
348
target.open_branch().last_revision())
296
self.assertEqual(source.revision_history(),
297
target.open_branch().revision_history())
350
299
def test_clone_bzrdir_branch_revision(self):
351
300
# test for revision limiting, [smoke test, not corner case checks].
414
363
repo.set_make_working_trees(False)
415
364
self.assertFalse(repo.make_working_trees())
417
a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
418
a_branch = a_dir.open_branch()
419
# If the new control dir actually uses the repository, it should
420
# not have a working tree.
421
if not a_branch.repository.has_same_location(repo):
422
raise TestNotApplicable('new control dir does not use repository')
367
a_dir = dir.clone(self.get_url('repo/a'))
423
369
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
425
371
def test_clone_respects_stacked(self):
426
372
branch = self.make_branch('parent')
427
373
child_transport = self.get_transport('child')
429
child = branch.bzrdir.clone_on_transport(child_transport,
430
stacked_on=branch.base)
431
except (errors.UnstackableBranchFormat,
432
errors.UnstackableRepositoryFormat):
433
raise TestNotApplicable("branch or repository format does "
434
"not support stacking")
374
child = branch.bzrdir.clone_on_transport(child_transport,
375
stacked_on=branch.base)
435
376
self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
437
def test_set_branch_reference(self):
438
"""set_branch_reference creates a branch reference"""
439
referenced_branch = self.make_branch('referenced')
440
dir = self.make_bzrdir('source')
442
reference = dir.set_branch_reference(referenced_branch)
443
except errors.IncompatibleFormat:
444
# this is ok too, not all formats have to support references.
445
raise TestNotApplicable("control directory does not "
446
"support branch references")
448
referenced_branch.bzrdir.root_transport.abspath('') + '/',
449
dir.get_branch_reference())
451
def test_set_branch_reference_on_existing_reference(self):
452
"""set_branch_reference creates a branch reference"""
453
referenced_branch1 = self.make_branch('old-referenced')
454
referenced_branch2 = self.make_branch('new-referenced')
455
dir = self.make_bzrdir('source')
457
reference = dir.set_branch_reference(referenced_branch1)
458
except errors.IncompatibleFormat:
459
# this is ok too, not all formats have to support references.
460
raise TestNotApplicable("control directory does not "
461
"support branch references")
462
reference = dir.set_branch_reference(referenced_branch2)
464
referenced_branch2.bzrdir.root_transport.abspath('') + '/',
465
dir.get_branch_reference())
467
def test_set_branch_reference_on_existing_branch(self):
468
"""set_branch_reference creates a branch reference"""
469
referenced_branch = self.make_branch('referenced')
470
dir = self.make_branch('source').bzrdir
472
reference = dir.set_branch_reference(referenced_branch)
473
except errors.IncompatibleFormat:
474
# this is ok too, not all formats have to support references.
475
raise TestNotApplicable("control directory does not "
476
"support branch references")
478
referenced_branch.bzrdir.root_transport.abspath('') + '/',
479
dir.get_branch_reference())
481
378
def test_get_branch_reference_on_reference(self):
482
379
"""get_branch_reference should return the right url."""
483
380
referenced_branch = self.make_branch('referenced')
484
381
dir = self.make_bzrdir('source')
486
dir.set_branch_reference(referenced_branch)
383
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
384
target_branch=referenced_branch)
487
385
except errors.IncompatibleFormat:
488
386
# this is ok too, not all formats have to support references.
489
raise TestNotApplicable("control directory does not "
490
"support branch references")
491
388
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
492
389
dir.get_branch_reference())
562
454
shared_repo = self.make_repository('target', shared=True)
563
455
except errors.IncompatibleFormat:
564
raise TestNotApplicable("format does not support "
565
"shared repositories")
566
457
target = dir.sprout(self.get_url('target/child'))
567
self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
458
self.assertNotEqual(dir.transport.base, target.transport.base)
568
459
self.assertTrue(shared_repo.has_revision('1'))
570
461
def test_sprout_bzrdir_repository_branch_both_under_shared(self):
572
463
shared_repo = self.make_repository('shared', shared=True)
573
464
except errors.IncompatibleFormat:
574
raise TestNotApplicable("format does not support shared "
576
if not shared_repo._format.supports_nesting_repositories:
577
raise TestNotApplicable("format does not support nesting "
579
466
tree = self.make_branch_and_tree('commit_tree')
580
467
self.build_tree(['commit_tree/foo'])
582
469
tree.commit('revision 1', rev_id='1')
583
tree.bzrdir.open_branch().generate_revision_history(
584
_mod_revision.NULL_REVISION)
470
tree.bzrdir.open_branch().set_revision_history([])
585
471
tree.set_parent_trees([])
586
472
tree.commit('revision 2', rev_id='2')
587
473
tree.branch.repository.copy_content_into(shared_repo)
796
667
target = dir.sprout(self.get_url('target'), revision_id='1')
797
668
self.assertEqual('1', target.open_branch().last_revision())
799
def test_sprout_bzrdir_branch_with_tags(self):
800
# when sprouting a branch all revisions named in the tags are copied
802
builder = self.make_branch_builder('source')
803
source = fixtures.build_branch_with_non_ancestral_rev(builder)
805
source.tags.set_tag('tag-a', 'rev-2')
806
except errors.TagsNotSupported:
807
raise TestNotApplicable('Branch format does not support tags.')
808
source.get_config_stack().set('branch.fetch_tags', True)
809
# Now source has a tag not in its ancestry. Sprout its controldir.
811
target = dir.sprout(self.get_url('target'))
812
# The tag is present, and so is its revision.
813
new_branch = target.open_branch()
814
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
815
new_branch.repository.get_revision('rev-2')
817
def test_sprout_bzrdir_branch_with_absent_tag(self):
818
# tags referencing absent revisions are copied (and those absent
819
# revisions do not prevent the sprout.)
820
builder = self.make_branch_builder('source')
821
builder.build_commit(message="Rev 1", rev_id='rev-1')
822
source = builder.get_branch()
824
source.tags.set_tag('tag-a', 'missing-rev')
825
except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
826
raise TestNotApplicable('Branch format does not support tags '
827
'or tags referencing ghost revisions.')
828
# Now source has a tag pointing to an absent revision. Sprout its
831
target = dir.sprout(self.get_url('target'))
832
# The tag is present in the target
833
new_branch = target.open_branch()
834
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
836
def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
837
# tags referencing absent revisions are copied (and those absent
838
# revisions do not prevent the sprout.)
839
builder = self.make_branch_builder('source')
840
builder.build_commit(message="Rev 1", rev_id='rev-1')
841
source = builder.get_branch()
843
source.tags.set_tag('tag-a', 'missing-rev')
844
except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
845
raise TestNotApplicable('Branch format does not support tags '
846
'or tags referencing missing revisions.')
847
# Now source has a tag pointing to an absent revision. Sprout its
850
target = dir.sprout(self.get_url('target'), source_branch=source)
851
# The tag is present in the target
852
new_branch = target.open_branch()
853
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
855
def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
856
# dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
857
# the branch at that bzrdir, the ancestry of all of those, but no other
858
# revs (not even the tip of the source branch).
859
builder = self.make_branch_builder('source')
860
builder.build_commit(message="Base", rev_id='base-rev')
861
# Make three parallel lines of ancestry off this base.
862
source = builder.get_branch()
863
builder.build_commit(message="Rev A1", rev_id='rev-a1')
864
builder.build_commit(message="Rev A2", rev_id='rev-a2')
865
builder.build_commit(message="Rev A3", rev_id='rev-a3')
866
source.set_last_revision_info(1, 'base-rev')
867
builder.build_commit(message="Rev B1", rev_id='rev-b1')
868
builder.build_commit(message="Rev B2", rev_id='rev-b2')
869
builder.build_commit(message="Rev B3", rev_id='rev-b3')
870
source.set_last_revision_info(1, 'base-rev')
871
builder.build_commit(message="Rev C1", rev_id='rev-c1')
872
builder.build_commit(message="Rev C2", rev_id='rev-c2')
873
builder.build_commit(message="Rev C3", rev_id='rev-c3')
874
# Set the branch tip to A2
875
source.set_last_revision_info(3, 'rev-a2')
877
# Create a tag for B2, and for an absent rev
878
source.tags.set_tag('tag-non-ancestry', 'rev-b2')
879
except errors.TagsNotSupported:
880
raise TestNotApplicable('Branch format does not support tags ')
882
source.tags.set_tag('tag-absent', 'absent-rev')
883
except errors.GhostTagsNotSupported:
884
has_ghost_tag = False
887
source.get_config_stack().set('branch.fetch_tags', True)
888
# And ask sprout for C2
890
target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
891
# The tags are present
892
new_branch = target.open_branch()
895
{'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
896
new_branch.tags.get_tag_dict())
899
{'tag-non-ancestry': 'rev-b2'},
900
new_branch.tags.get_tag_dict())
901
# And the revs for A2, B2 and C2's ancestries are present, but no
904
['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
905
sorted(new_branch.repository.all_revision_ids()))
907
670
def test_sprout_bzrdir_tree_branch_reference(self):
908
671
# sprouting should create a repository if needed and a sprouted branch.
909
672
# the tree state should not be copied.
910
673
referenced_branch = self.make_branch('referencced')
911
674
dir = self.make_bzrdir('source')
913
dir.set_branch_reference(referenced_branch)
676
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
677
target_branch=referenced_branch)
914
678
except errors.IncompatibleFormat:
915
679
# this is ok too, not all formats have to support references.
916
raise TestNotApplicable("format does not support "
918
681
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
919
682
tree = self.createWorkingTreeOrSkip(dir)
920
683
self.build_tree(['source/subdir/'])
1027
791
def test_format_initialize_find_open(self):
1028
792
# loopback test to check the current format initializes to itself.
1029
if not self.bzrdir_format.is_initializable():
793
if not self.bzrdir_format.is_supported():
1030
794
# unsupported formats are not loopback testable
1031
795
# because the default open will not open them and
1032
796
# they may not be initializable.
1033
raise TestNotApplicable("format is not initializable")
1034
798
# for remote formats, there must be no prior assumption about the
1035
799
# network name to use - it's possible that this may somehow have got
1036
800
# in through an unisolated test though - see
1037
801
# <https://bugs.launchpad.net/bzr/+bug/504102>
1038
self.assertEqual(getattr(self.bzrdir_format,
802
self.assertEquals(getattr(self.bzrdir_format,
1039
803
'_network_name', None),
1041
805
# supported formats must be able to init and open
1042
t = self.get_transport()
1043
readonly_t = self.get_readonly_transport()
806
t = transport.get_transport(self.get_url())
807
readonly_t = transport.get_transport(self.get_readonly_url())
1044
808
made_control = self.bzrdir_format.initialize(t.base)
1045
self.assertIsInstance(made_control, controldir.ControlDir)
1046
if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
809
self.failUnless(isinstance(made_control, controldir.ControlDir))
1048
810
self.assertEqual(self.bzrdir_format,
1049
811
controldir.ControlDirFormat.find_format(readonly_t))
1050
812
direct_opened_dir = self.bzrdir_format.open(readonly_t)
1051
opened_dir = controldir.ControlDir.open(t.base)
813
opened_dir = bzrdir.BzrDir.open(t.base)
1052
814
self.assertEqual(made_control._format,
1053
815
opened_dir._format)
1054
816
self.assertEqual(direct_opened_dir._format,
1055
817
opened_dir._format)
1056
self.assertIsInstance(opened_dir, controldir.ControlDir)
818
self.failUnless(isinstance(opened_dir, controldir.ControlDir))
1058
820
def test_format_initialize_on_transport_ex(self):
1059
821
t = self.get_transport('dir')
1078
841
self.assertInitializeEx(t, create_prefix=True)
1080
843
def test_format_initialize_on_transport_ex_create_prefix_False(self):
1081
if not self.bzrdir_format.is_initializable():
1082
raise TestNotApplicable("format is not initializable")
844
if not self.bzrdir_format.is_supported():
845
# Not initializable - not a failure either.
1083
847
t = self.get_transport('missing/dir')
1084
848
self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1085
849
create_prefix=False)
1087
851
def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1088
852
t = self.get_transport('repo')
1089
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
853
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1090
854
repo_name = repo_fmt.repository_format.network_name()
1091
855
repo = repo_fmt.initialize_on_transport_ex(t,
1092
856
repo_format_name=repo_name, shared_repo=True)[0]
1093
857
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1094
858
force_new_repo=True, repo_format_name=repo_name)
860
# uninitialisable format
1095
862
self.assertNotEqual(repo.bzrdir.root_transport.base,
1096
863
made_repo.bzrdir.root_transport.base)
1098
865
def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1099
866
t = self.get_transport('repo')
1100
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
867
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1101
868
repo_name = repo_fmt.repository_format.network_name()
1102
869
repo = repo_fmt.initialize_on_transport_ex(t,
1103
870
repo_format_name=repo_name, shared_repo=True)[0]
1104
871
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1105
872
force_new_repo=False, repo_format_name=repo_name)
1106
if not control._format.fixed_components:
874
# uninitialisable format
876
if not isinstance(control._format, (bzrdir.BzrDirFormat5,
877
bzrdir.BzrDirFormat6,)):
1107
878
self.assertEqual(repo.bzrdir.root_transport.base,
1108
879
made_repo.bzrdir.root_transport.base)
881
def test_format_initialize_on_transport_ex_stacked_on(self):
882
# trunk is a stackable format. Note that its in the same server area
883
# which is what launchpad does, but not sufficient to exercise the
885
trunk = self.make_branch('trunk', format='1.9')
886
t = self.get_transport('stacked')
887
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
888
repo_name = old_fmt.repository_format.network_name()
889
# Should end up with a 1.9 format (stackable)
890
repo, control = self.assertInitializeEx(t, need_meta=True,
891
repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
893
# uninitialisable format
895
self.assertLength(1, repo._fallback_repositories)
897
def test_format_initialize_on_transport_ex_default_stack_on(self):
898
# When initialize_on_transport_ex uses a stacked-on branch because of
899
# a stacking policy on the target, the location of the fallback
900
# repository is the same as the external location of the stacked-on
902
balloon = self.make_bzrdir('balloon')
903
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
904
stack_on = self.make_branch('stack-on', format='1.9')
906
stack_on = self.make_branch('stack-on')
907
config = self.make_bzrdir('.').get_config()
909
config.set_default_stack_on('stack-on')
910
except errors.BzrError:
911
raise TestNotApplicable('Only relevant for stackable formats.')
912
# Initialize a bzrdir subject to the policy.
913
t = self.get_transport('stacked')
914
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
915
repo_name = repo_fmt.repository_format.network_name()
916
repo, control = self.assertInitializeEx(
917
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
918
# self.addCleanup(repo.unlock)
920
# uninitialisable format
922
# There's one fallback repo, with a public location.
923
self.assertLength(1, repo._fallback_repositories)
924
fallback_repo = repo._fallback_repositories[0]
926
stack_on.base, fallback_repo.bzrdir.root_transport.base)
927
# The bzrdir creates a branch in stacking-capable format.
928
new_branch = control.create_branch()
929
self.assertTrue(new_branch._format.supports_stacking())
1110
931
def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1111
932
t = self.get_transport('dir')
1112
933
repo, control = self.assertInitializeEx(t)
1115
936
def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1116
937
t = self.get_transport('dir')
1117
938
# 1.6 is likely to never be default
1118
fmt = controldir.format_registry.make_bzrdir('1.6')
939
fmt = bzrdir.format_registry.make_bzrdir('1.6')
1119
940
repo_name = fmt.repository_format.network_name()
1120
941
repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1121
if self.bzrdir_format.fixed_components:
943
# uninitialisable format
945
if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
946
bzrdir.BzrDirFormat6)):
1122
947
# must stay with the all-in-one-format.
1123
948
repo_name = self.bzrdir_format.network_name()
1124
949
self.assertEqual(repo_name, repo._format.network_name())
1126
def assertInitializeEx(self, t, **kwargs):
951
def assertInitializeEx(self, t, need_meta=False, **kwargs):
1127
952
"""Execute initialize_on_transport_ex and check it succeeded correctly.
1129
954
This involves checking that the disk objects were created, open with
1134
959
initialize_on_transport_ex.
1135
960
:return: the resulting repo, control dir tuple.
1137
if not self.bzrdir_format.is_initializable():
1138
raise TestNotApplicable("control dir format is not "
962
if not self.bzrdir_format.is_supported():
963
# Not initializable - not a failure either.
1140
965
repo, control, require_stacking, repo_policy = \
1141
966
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1142
967
if repo is not None:
1143
968
# Repositories are open write-locked
1144
969
self.assertTrue(repo.is_write_locked())
1145
970
self.addCleanup(repo.unlock)
1146
self.assertIsInstance(control, controldir.ControlDir)
1147
opened = controldir.ControlDir.open(t.base)
971
self.assertIsInstance(control, bzrdir.BzrDir)
972
opened = bzrdir.BzrDir.open(t.base)
1148
973
expected_format = self.bzrdir_format
1149
if not isinstance(expected_format, RemoteBzrDirFormat):
974
if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
975
# Current RemoteBzrDirFormat's do not reliably get network_name
976
# set, so we skip a number of tests for RemoteBzrDirFormat's.
977
self.assertIsInstance(control, RemoteBzrDir)
979
if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
980
bzrdir.BzrDirFormat6)):
981
# Pre-metadir formats change when we are making something that
982
# needs a metaformat, because clone is used for push.
983
expected_format = bzrdir.BzrDirMetaFormat1()
1150
984
self.assertEqual(control._format.network_name(),
1151
985
expected_format.network_name())
1152
986
self.assertEqual(control._format.network_name(),
1181
1015
# test the formats specific behaviour for no-content or similar dirs.
1182
1016
self.assertRaises(errors.NotBranchError,
1183
1017
self.bzrdir_format.open,
1184
transport.get_transport_from_url(self.get_readonly_url()))
1018
transport.get_transport(self.get_readonly_url()))
1186
1020
def test_create_branch(self):
1187
1021
# a bzrdir can construct a branch and repository for itself.
1188
if not self.bzrdir_format.is_initializable():
1022
if not self.bzrdir_format.is_supported():
1189
1023
# unsupported formats are not loopback testable
1190
1024
# because the default open will not open them and
1191
1025
# they may not be initializable.
1192
raise TestNotApplicable("format is not initializable")
1193
t = self.get_transport()
1027
t = transport.get_transport(self.get_url())
1194
1028
made_control = self.bzrdir_format.initialize(t.base)
1195
1029
made_repo = made_control.create_repository()
1196
1030
made_branch = made_control.create_branch()
1197
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1198
self.assertEqual(made_control, made_branch.bzrdir)
1200
def test_create_branch_append_revisions_only(self):
1201
# a bzrdir can construct a branch and repository for itself.
1202
if not self.bzrdir_format.is_initializable():
1203
# unsupported formats are not loopback testable
1204
# because the default open will not open them and
1205
# they may not be initializable.
1206
raise TestNotApplicable("format is not initializable")
1207
t = self.get_transport()
1208
made_control = self.bzrdir_format.initialize(t.base)
1209
made_repo = made_control.create_repository()
1211
made_branch = made_control.create_branch(
1212
append_revisions_only=True)
1213
except errors.UpgradeRequired:
1214
raise TestNotApplicable("format does not support "
1215
"append_revisions_only setting")
1216
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1217
self.assertEqual(True, made_branch.get_append_revisions_only())
1031
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1218
1032
self.assertEqual(made_control, made_branch.bzrdir)
1220
1034
def test_open_branch(self):
1221
if not self.bzrdir_format.is_initializable():
1035
if not self.bzrdir_format.is_supported():
1222
1036
# unsupported formats are not loopback testable
1223
1037
# because the default open will not open them and
1224
1038
# they may not be initializable.
1225
raise TestNotApplicable("format is not initializable")
1226
t = self.get_transport()
1040
t = transport.get_transport(self.get_url())
1227
1041
made_control = self.bzrdir_format.initialize(t.base)
1228
1042
made_repo = made_control.create_repository()
1229
1043
made_branch = made_control.create_branch()
1230
1044
opened_branch = made_control.open_branch()
1231
1045
self.assertEqual(made_control, opened_branch.bzrdir)
1232
self.assertIsInstance(opened_branch, made_branch.__class__)
1233
self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1046
self.failUnless(isinstance(opened_branch, made_branch.__class__))
1047
self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1235
1049
def test_list_branches(self):
1236
if not self.bzrdir_format.is_initializable():
1237
raise TestNotApplicable("format is not initializable")
1238
t = self.get_transport()
1050
if not self.bzrdir_format.is_supported():
1051
# unsupported formats are not loopback testable
1052
# because the default open will not open them and
1053
# they may not be initializable.
1055
t = transport.get_transport(self.get_url())
1239
1056
made_control = self.bzrdir_format.initialize(t.base)
1240
1057
made_repo = made_control.create_repository()
1241
1058
made_branch = made_control.create_branch()
1242
1059
branches = made_control.list_branches()
1243
self.assertEqual(1, len(branches))
1244
self.assertEqual(made_branch.base, branches[0].base)
1060
self.assertEquals(1, len(branches))
1061
self.assertEquals(made_branch.base, branches[0].base)
1246
1063
made_control.destroy_branch()
1247
1064
except errors.UnsupportedOperation:
1248
1065
pass # Not all bzrdirs support destroying directories
1250
self.assertEqual([], made_control.list_branches())
1252
def test_get_branches(self):
1253
repo = self.make_repository('branch-1')
1254
target_branch = repo.bzrdir.create_branch()
1255
self.assertEqual([""], repo.bzrdir.get_branches().keys())
1067
self.assertEquals([], made_control.list_branches())
1257
1069
def test_create_repository(self):
1258
1070
# a bzrdir can construct a repository for itself.
1259
if not self.bzrdir_format.is_initializable():
1071
if not self.bzrdir_format.is_supported():
1260
1072
# unsupported formats are not loopback testable
1261
1073
# because the default open will not open them and
1262
1074
# they may not be initializable.
1263
raise TestNotApplicable("format is not initializable")
1264
t = self.get_transport()
1076
t = transport.get_transport(self.get_url())
1265
1077
made_control = self.bzrdir_format.initialize(t.base)
1266
1078
made_repo = made_control.create_repository()
1267
1079
# Check that we have a repository object.
1271
1083
def test_create_repository_shared(self):
1272
1084
# a bzrdir can create a shared repository or
1273
1085
# fail appropriately
1274
if not self.bzrdir_format.is_initializable():
1086
if not self.bzrdir_format.is_supported():
1275
1087
# unsupported formats are not loopback testable
1276
1088
# because the default open will not open them and
1277
1089
# they may not be initializable.
1278
raise TestNotApplicable("format is not initializable")
1279
t = self.get_transport()
1091
t = transport.get_transport(self.get_url())
1280
1092
made_control = self.bzrdir_format.initialize(t.base)
1282
1094
made_repo = made_control.create_repository(shared=True)
1283
1095
except errors.IncompatibleFormat:
1284
1096
# Old bzrdir formats don't support shared repositories
1285
1097
# and should raise IncompatibleFormat
1286
raise TestNotApplicable("format does not support shared "
1288
1099
self.assertTrue(made_repo.is_shared())
1290
1101
def test_create_repository_nonshared(self):
1291
1102
# a bzrdir can create a non-shared repository
1292
if not self.bzrdir_format.is_initializable():
1103
if not self.bzrdir_format.is_supported():
1293
1104
# unsupported formats are not loopback testable
1294
1105
# because the default open will not open them and
1295
1106
# they may not be initializable.
1296
raise TestNotApplicable("format is not initializable")
1297
t = self.get_transport()
1108
t = transport.get_transport(self.get_url())
1298
1109
made_control = self.bzrdir_format.initialize(t.base)
1300
made_repo = made_control.create_repository(shared=False)
1301
except errors.IncompatibleFormat:
1302
# Some control dir formats don't support non-shared repositories
1303
# and should raise IncompatibleFormat
1304
raise TestNotApplicable("format does not support shared "
1110
made_repo = made_control.create_repository(shared=False)
1306
1111
self.assertFalse(made_repo.is_shared())
1308
1113
def test_open_repository(self):
1309
if not self.bzrdir_format.is_initializable():
1114
if not self.bzrdir_format.is_supported():
1310
1115
# unsupported formats are not loopback testable
1311
1116
# because the default open will not open them and
1312
1117
# they may not be initializable.
1313
raise TestNotApplicable("format is not initializable")
1314
t = self.get_transport()
1119
t = transport.get_transport(self.get_url())
1315
1120
made_control = self.bzrdir_format.initialize(t.base)
1316
1121
made_repo = made_control.create_repository()
1317
1122
opened_repo = made_control.open_repository()
1318
1123
self.assertEqual(made_control, opened_repo.bzrdir)
1319
self.assertIsInstance(opened_repo, made_repo.__class__)
1320
self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1124
self.failUnless(isinstance(opened_repo, made_repo.__class__))
1125
self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1322
1127
def test_create_workingtree(self):
1323
1128
# a bzrdir can construct a working tree for itself.
1324
if not self.bzrdir_format.is_initializable():
1129
if not self.bzrdir_format.is_supported():
1325
1130
# unsupported formats are not loopback testable
1326
1131
# because the default open will not open them and
1327
1132
# they may not be initializable.
1328
raise TestNotApplicable("format is not initializable")
1329
1134
t = self.get_transport()
1330
1135
made_control = self.bzrdir_format.initialize(t.base)
1331
1136
made_repo = made_control.create_repository()
1332
1137
made_branch = made_control.create_branch()
1333
1138
made_tree = self.createWorkingTreeOrSkip(made_control)
1334
self.assertIsInstance(made_tree, workingtree.WorkingTree)
1139
self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1335
1140
self.assertEqual(made_control, made_tree.bzrdir)
1337
1142
def test_create_workingtree_revision(self):
1338
1143
# a bzrdir can construct a working tree for itself @ a specific revision.
1339
if not self.bzrdir_format.is_initializable():
1340
raise TestNotApplicable("format is not initializable")
1341
1144
t = self.get_transport()
1342
1145
source = self.make_branch_and_tree('source')
1343
1146
source.commit('a', rev_id='a', allow_pointless=True)
1369
1175
% (self.bzrdir_format, t))
1370
1176
opened_tree = made_control.open_workingtree()
1371
1177
self.assertEqual(made_control, opened_tree.bzrdir)
1372
self.assertIsInstance(opened_tree, made_tree.__class__)
1373
self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1375
def test_get_selected_branch(self):
1376
# The segment parameters are accessible from the root transport
1377
# if a URL with segment parameters is opened.
1378
if not self.bzrdir_format.is_initializable():
1379
raise TestNotApplicable("format is not initializable")
1380
t = self.get_transport()
1382
made_control = self.bzrdir_format.initialize(t.base)
1383
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1384
raise TestSkipped("Can't initialize %r on transport %r"
1385
% (self.bzrdir_format, t))
1386
dir = controldir.ControlDir.open(t.base+",branch=foo")
1387
self.assertEqual({"branch": "foo"},
1388
dir.user_transport.get_segment_parameters())
1389
self.assertEqual("foo", dir._get_selected_branch())
1391
def test_get_selected_branch_none_selected(self):
1392
# _get_selected_branch defaults to None
1393
if not self.bzrdir_format.is_initializable():
1394
raise TestNotApplicable("format is not initializable")
1395
t = self.get_transport()
1397
made_control = self.bzrdir_format.initialize(t.base)
1398
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1399
raise TestSkipped("Can't initialize %r on transport %r"
1400
% (self.bzrdir_format, t))
1401
dir = controldir.ControlDir.open(t.base)
1402
self.assertEqual(u"", dir._get_selected_branch())
1178
self.failUnless(isinstance(opened_tree, made_tree.__class__))
1179
self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1181
def test_get_branch_transport(self):
1182
dir = self.make_bzrdir('.')
1183
# without a format, get_branch_transport gives use a transport
1184
# which -may- point to an existing dir.
1185
self.assertTrue(isinstance(dir.get_branch_transport(None),
1186
transport.Transport))
1187
# with a given format, either the bzr dir supports identifiable
1188
# branches, or it supports anonymous branch formats, but not both.
1189
anonymous_format = bzrlib.branch.BzrBranchFormat4()
1190
identifiable_format = bzrlib.branch.BzrBranchFormat5()
1192
found_transport = dir.get_branch_transport(anonymous_format)
1193
self.assertRaises(errors.IncompatibleFormat,
1194
dir.get_branch_transport,
1195
identifiable_format)
1196
except errors.IncompatibleFormat:
1197
found_transport = dir.get_branch_transport(identifiable_format)
1198
self.assertTrue(isinstance(found_transport, transport.Transport))
1199
# and the dir which has been initialized for us must exist.
1200
found_transport.list_dir('.')
1202
def test_get_repository_transport(self):
1203
dir = self.make_bzrdir('.')
1204
# without a format, get_repository_transport gives use a transport
1205
# which -may- point to an existing dir.
1206
self.assertTrue(isinstance(dir.get_repository_transport(None),
1207
transport.Transport))
1208
# with a given format, either the bzr dir supports identifiable
1209
# repositories, or it supports anonymous repository formats, but not both.
1210
anonymous_format = weaverepo.RepositoryFormat6()
1211
identifiable_format = weaverepo.RepositoryFormat7()
1213
found_transport = dir.get_repository_transport(anonymous_format)
1214
self.assertRaises(errors.IncompatibleFormat,
1215
dir.get_repository_transport,
1216
identifiable_format)
1217
except errors.IncompatibleFormat:
1218
found_transport = dir.get_repository_transport(identifiable_format)
1219
self.assertTrue(isinstance(found_transport, transport.Transport))
1220
# and the dir which has been initialized for us must exist.
1221
found_transport.list_dir('.')
1223
def test_get_workingtree_transport(self):
1224
dir = self.make_bzrdir('.')
1225
# without a format, get_workingtree_transport gives use a transport
1226
# which -may- point to an existing dir.
1227
self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1228
transport.Transport))
1229
# with a given format, either the bzr dir supports identifiable
1230
# trees, or it supports anonymous tree formats, but not both.
1231
anonymous_format = workingtree.WorkingTreeFormat2()
1232
identifiable_format = workingtree.WorkingTreeFormat3()
1234
found_transport = dir.get_workingtree_transport(anonymous_format)
1235
self.assertRaises(errors.IncompatibleFormat,
1236
dir.get_workingtree_transport,
1237
identifiable_format)
1238
except errors.IncompatibleFormat:
1239
found_transport = dir.get_workingtree_transport(identifiable_format)
1240
self.assertTrue(isinstance(found_transport, transport.Transport))
1241
# and the dir which has been initialized for us must exist.
1242
found_transport.list_dir('.')
1404
1244
def test_root_transport(self):
1405
1245
dir = self.make_bzrdir('.')
1406
1246
self.assertEqual(dir.root_transport.base,
1407
self.get_transport().base)
1247
transport.get_transport(self.get_url('.')).base)
1409
1249
def test_find_repository_no_repo_under_standalone_branch(self):
1410
1250
# finding a repo stops at standalone branches even if there is a
1557
1376
old_url, new_url = tree.bzrdir.backup_bzrdir()
1558
1377
old_path = urlutils.local_path_from_url(old_url)
1559
1378
new_path = urlutils.local_path_from_url(new_url)
1560
self.assertPathExists(old_path)
1561
self.assertPathExists(new_path)
1379
self.failUnlessExists(old_path)
1380
self.failUnlessExists(new_path)
1562
1381
for (((dir_relpath1, _), entries1),
1563
1382
((dir_relpath2, _), entries2)) in izip(
1564
1383
osutils.walkdirs(old_path),
1565
1384
osutils.walkdirs(new_path)):
1566
self.assertEqual(dir_relpath1, dir_relpath2)
1385
self.assertEquals(dir_relpath1, dir_relpath2)
1567
1386
for f1, f2 in zip(entries1, entries2):
1568
self.assertEqual(f1[0], f2[0])
1569
self.assertEqual(f1[2], f2[2])
1387
self.assertEquals(f1[0], f2[0])
1388
self.assertEquals(f1[2], f2[2])
1570
1389
if f1[2] == "file":
1571
1390
osutils.compare_files(open(f1[4]), open(f2[4]))