108
108
self.assertRaises(errors.UninitializableFormat,
109
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, '.')
111
122
def test_create_null_workingtree(self):
112
123
dir = self.make_bzrdir('dir1')
113
124
dir.create_repository()
114
125
dir.create_branch()
116
wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
127
wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
117
128
except (errors.NotLocalUrl, errors.UnsupportedOperation):
118
129
raise TestSkipped("cannot make working tree with transport %r"
148
159
bzrdir.create_branch()
149
160
bzrdir.open_branch()
162
def test_destroy_branch_no_branch(self):
163
branch = self.make_repository('branch')
164
bzrdir = branch.bzrdir
166
self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
167
except (errors.UnsupportedOperation, errors.TransportNotPossible):
168
raise TestNotApplicable('Format does not support destroying branch')
151
170
def test_destroy_repository(self):
152
171
repo = self.make_repository('repository')
153
172
bzrdir = repo.bzrdir
212
233
tree.commit('revision 1', rev_id='1')
213
234
tree.bzrdir.open_branch().generate_revision_history(
214
bzrlib.revision.NULL_REVISION)
235
_mod_revision.NULL_REVISION)
215
236
tree.set_parent_trees([])
216
237
tree.commit('revision 2', rev_id='2')
217
238
# Copy the content (i.e. revisions) from the 'commit_tree' branch's
323
344
target = dir.clone(self.get_url('target/child'))
324
345
self.assertNotEqual(dir.transport.base, target.transport.base)
325
346
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
326
self.assertEqual(source.revision_history(),
327
target.open_branch().revision_history())
347
self.assertEqual(source.last_revision(),
348
target.open_branch().last_revision())
329
350
def test_clone_bzrdir_branch_revision(self):
330
351
# test for revision limiting, [smoke test, not corner case checks].
393
414
repo.set_make_working_trees(False)
394
415
self.assertFalse(repo.make_working_trees())
397
a_dir = dir.clone(self.get_url('repo/a'))
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')
399
423
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
401
425
def test_clone_respects_stacked(self):
406
430
stacked_on=branch.base)
407
431
except (errors.UnstackableBranchFormat,
408
432
errors.UnstackableRepositoryFormat):
409
raise TestNotApplicable("branch or repository format do "
433
raise TestNotApplicable("branch or repository format does "
410
434
"not support stacking")
411
435
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())
413
481
def test_get_branch_reference_on_reference(self):
414
482
"""get_branch_reference should return the right url."""
415
483
referenced_branch = self.make_branch('referenced')
416
484
dir = self.make_bzrdir('source')
418
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
419
target_branch=referenced_branch)
486
dir.set_branch_reference(referenced_branch)
420
487
except errors.IncompatibleFormat:
421
488
# this is ok too, not all formats have to support references.
422
489
raise TestNotApplicable("control directory does not "
462
529
target.open_workingtree()
463
530
except errors.NoWorkingTree:
464
531
# Some bzrdirs can never have working trees.
465
self.assertFalse(target._format.supports_workingtrees)
532
repo = target.find_repository()
533
self.assertFalse(repo.bzrdir._format.supports_workingtrees)
467
535
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
468
536
# the force_new_repo parameter should force use of a new repo in an empty
594
662
tree.commit('revision 1', rev_id='1')
595
663
br = tree.bzrdir.open_branch()
596
br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
664
br.set_last_revision_info(0, _mod_revision.NULL_REVISION)
597
665
tree.set_parent_trees([])
598
666
tree.commit('revision 2', rev_id='2')
599
667
source = self.make_repository('source')
666
733
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
667
734
dir = self.make_bzrdir('source')
669
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
670
target_branch=referenced_tree.branch)
736
dir.set_branch_reference(referenced_tree.branch)
671
737
except errors.IncompatibleFormat:
672
738
raise TestNotApplicable("format does not support branch "
693
759
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
694
760
dir = self.make_bzrdir('source')
696
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
697
target_branch=referenced_tree.branch)
762
dir.set_branch_reference(referenced_tree.branch)
698
763
except errors.IncompatibleFormat:
699
764
# this is ok too, not all formats have to support references.
700
765
raise TestNotApplicable("format does not support "
740
805
source.tags.set_tag('tag-a', 'rev-2')
741
806
except errors.TagsNotSupported:
742
807
raise TestNotApplicable('Branch format does not support tags.')
743
source.get_config().set_user_option('branch.fetch_tags', 'True')
808
source.get_config_stack().set('branch.fetch_tags', True)
744
809
# Now source has a tag not in its ancestry. Sprout its controldir.
745
810
dir = source.bzrdir
746
811
target = dir.sprout(self.get_url('target'))
845
910
referenced_branch = self.make_branch('referencced')
846
911
dir = self.make_bzrdir('source')
848
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
849
target_branch=referenced_branch)
913
dir.set_branch_reference(referenced_branch)
850
914
except errors.IncompatibleFormat:
851
915
# this is ok too, not all formats have to support references.
852
916
raise TestNotApplicable("format does not support "
872
936
referenced_branch = self.make_branch('referencced')
873
937
dir = self.make_bzrdir('source')
875
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
876
target_branch=referenced_branch)
939
dir.set_branch_reference(referenced_branch)
877
940
except errors.IncompatibleFormat:
878
941
# this is ok too, not all formats have to support references.
879
942
raise TestNotApplicable("format does not support "
985
1048
self.assertEqual(self.bzrdir_format,
986
1049
controldir.ControlDirFormat.find_format(readonly_t))
987
1050
direct_opened_dir = self.bzrdir_format.open(readonly_t)
988
opened_dir = bzrdir.BzrDir.open(t.base)
1051
opened_dir = controldir.ControlDir.open(t.base)
989
1052
self.assertEqual(made_control._format,
990
1053
opened_dir._format)
991
1054
self.assertEqual(direct_opened_dir._format,
1024
1087
def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1025
1088
t = self.get_transport('repo')
1026
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1089
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1027
1090
repo_name = repo_fmt.repository_format.network_name()
1028
1091
repo = repo_fmt.initialize_on_transport_ex(t,
1029
1092
repo_format_name=repo_name, shared_repo=True)[0]
1035
1098
def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1036
1099
t = self.get_transport('repo')
1037
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1100
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1038
1101
repo_name = repo_fmt.repository_format.network_name()
1039
1102
repo = repo_fmt.initialize_on_transport_ex(t,
1040
1103
repo_format_name=repo_name, shared_repo=True)[0]
1044
1107
self.assertEqual(repo.bzrdir.root_transport.base,
1045
1108
made_repo.bzrdir.root_transport.base)
1047
def test_format_initialize_on_transport_ex_stacked_on(self):
1048
if not self.bzrdir_format.is_initializable():
1049
raise TestNotApplicable("format is not initializable")
1050
# trunk is a stackable format. Note that its in the same server area
1051
# which is what launchpad does, but not sufficient to exercise the
1053
trunk = self.make_branch('trunk', format='1.9')
1054
t = self.get_transport('stacked')
1055
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1056
repo_name = old_fmt.repository_format.network_name()
1057
# Should end up with a 1.9 format (stackable)
1058
repo, control = self.assertInitializeEx(t, need_meta=True,
1059
repo_format_name=repo_name, stacked_on='../trunk',
1060
stack_on_pwd=t.base)
1061
self.assertLength(1, repo._fallback_repositories)
1063
def test_format_initialize_on_transport_ex_default_stack_on(self):
1064
# When initialize_on_transport_ex uses a stacked-on branch because of
1065
# a stacking policy on the target, the location of the fallback
1066
# repository is the same as the external location of the stacked-on
1068
balloon = self.make_bzrdir('balloon')
1069
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1070
stack_on = self.make_branch('stack-on', format='1.9')
1072
stack_on = self.make_branch('stack-on')
1073
config = self.make_bzrdir('.').get_config()
1075
config.set_default_stack_on('stack-on')
1076
except errors.BzrError:
1077
raise TestNotApplicable('Only relevant for stackable formats.')
1078
# Initialize a bzrdir subject to the policy.
1079
t = self.get_transport('stacked')
1080
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1081
repo_name = repo_fmt.repository_format.network_name()
1082
repo, control = self.assertInitializeEx(
1083
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1084
# self.addCleanup(repo.unlock)
1085
# There's one fallback repo, with a public location.
1086
self.assertLength(1, repo._fallback_repositories)
1087
fallback_repo = repo._fallback_repositories[0]
1089
stack_on.base, fallback_repo.bzrdir.root_transport.base)
1090
# The bzrdir creates a branch in stacking-capable format.
1091
new_branch = control.create_branch()
1092
self.assertTrue(new_branch._format.supports_stacking())
1094
1110
def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1095
1111
t = self.get_transport('dir')
1096
1112
repo, control = self.assertInitializeEx(t)
1099
1115
def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1100
1116
t = self.get_transport('dir')
1101
1117
# 1.6 is likely to never be default
1102
fmt = bzrdir.format_registry.make_bzrdir('1.6')
1118
fmt = controldir.format_registry.make_bzrdir('1.6')
1103
1119
repo_name = fmt.repository_format.network_name()
1104
1120
repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1105
1121
if self.bzrdir_format.fixed_components:
1107
1123
repo_name = self.bzrdir_format.network_name()
1108
1124
self.assertEqual(repo_name, repo._format.network_name())
1110
def assertInitializeEx(self, t, need_meta=False, **kwargs):
1126
def assertInitializeEx(self, t, **kwargs):
1111
1127
"""Execute initialize_on_transport_ex and check it succeeded correctly.
1113
1129
This involves checking that the disk objects were created, open with
1128
1144
self.assertTrue(repo.is_write_locked())
1129
1145
self.addCleanup(repo.unlock)
1130
1146
self.assertIsInstance(control, controldir.ControlDir)
1131
opened = bzrdir.BzrDir.open(t.base)
1147
opened = controldir.ControlDir.open(t.base)
1132
1148
expected_format = self.bzrdir_format
1133
if need_meta and expected_format.fixed_components:
1134
# Pre-metadir formats change when we are making something that
1135
# needs a metaformat, because clone is used for push.
1136
expected_format = bzrdir.BzrDirMetaFormat1()
1137
1149
if not isinstance(expected_format, RemoteBzrDirFormat):
1138
1150
self.assertEqual(control._format.network_name(),
1139
1151
expected_format.network_name())
1202
1214
raise TestNotApplicable("format does not support "
1203
1215
"append_revisions_only setting")
1204
1216
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1205
self.assertEquals(True, made_branch.get_append_revisions_only())
1217
self.assertEqual(True, made_branch.get_append_revisions_only())
1206
1218
self.assertEqual(made_control, made_branch.bzrdir)
1208
1220
def test_open_branch(self):
1228
1240
made_repo = made_control.create_repository()
1229
1241
made_branch = made_control.create_branch()
1230
1242
branches = made_control.list_branches()
1231
self.assertEquals(1, len(branches))
1232
self.assertEquals(made_branch.base, branches[0].base)
1243
self.assertEqual(1, len(branches))
1244
self.assertEqual(made_branch.base, branches[0].base)
1234
1246
made_control.destroy_branch()
1235
1247
except errors.UnsupportedOperation:
1236
1248
pass # Not all bzrdirs support destroying directories
1238
self.assertEquals([], made_control.list_branches())
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())
1240
1257
def test_create_repository(self):
1241
1258
# a bzrdir can construct a repository for itself.
1366
1383
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1367
1384
raise TestSkipped("Can't initialize %r on transport %r"
1368
1385
% (self.bzrdir_format, t))
1369
dir = bzrdir.BzrDir.open(t.base+",branch=foo")
1370
self.assertEquals({"branch": "foo"},
1386
dir = controldir.ControlDir.open(t.base+",branch=foo")
1387
self.assertEqual({"branch": "foo"},
1371
1388
dir.user_transport.get_segment_parameters())
1372
self.assertEquals("foo", dir._get_selected_branch())
1389
self.assertEqual("foo", dir._get_selected_branch())
1374
1391
def test_get_selected_branch_none_selected(self):
1375
1392
# _get_selected_branch defaults to None
1381
1398
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1382
1399
raise TestSkipped("Can't initialize %r on transport %r"
1383
1400
% (self.bzrdir_format, t))
1384
dir = bzrdir.BzrDir.open(t.base)
1385
self.assertIs(None, dir._get_selected_branch())
1401
dir = controldir.ControlDir.open(t.base)
1402
self.assertEqual(u"", dir._get_selected_branch())
1387
1404
def test_root_transport(self):
1388
1405
dir = self.make_bzrdir('.')
1476
1493
self.get_transport().mkdir('childrepo')
1477
1494
child_control = self.bzrdir_format.initialize(url)
1478
1495
child_repo = child_control.create_repository(shared=True)
1479
opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1496
opened_control = controldir.ControlDir.open(self.get_url('childrepo'))
1480
1497
found_repo = opened_control.find_repository()
1481
1498
self.assertEqual(child_repo.bzrdir.root_transport.base,
1482
1499
found_repo.bzrdir.root_transport.base)
1546
1563
((dir_relpath2, _), entries2)) in izip(
1547
1564
osutils.walkdirs(old_path),
1548
1565
osutils.walkdirs(new_path)):
1549
self.assertEquals(dir_relpath1, dir_relpath2)
1566
self.assertEqual(dir_relpath1, dir_relpath2)
1550
1567
for f1, f2 in zip(entries1, entries2):
1551
self.assertEquals(f1[0], f2[0])
1552
self.assertEquals(f1[2], f2[2])
1568
self.assertEqual(f1[0], f2[0])
1569
self.assertEqual(f1[2], f2[2])
1553
1570
if f1[2] == "file":
1554
1571
osutils.compare_files(open(f1[4]), open(f2[4]))
1697
1713
except errors.BzrError, e:
1698
1714
if 'Cannot set config' in str(e):
1699
1715
self.assertFalse(
1700
isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1716
isinstance(my_dir, (_mod_bzrdir.BzrDirMeta1, RemoteBzrDir)),
1701
1717
"%r should support configs" % my_dir)
1702
1718
raise TestNotApplicable(
1703
1719
'This BzrDir format does not support configs.')
1706
1722
self.assertEqual('http://example.com', config.get_default_stack_on())
1707
my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
1723
my_dir2 = controldir.ControlDir.open(self.get_url('.'))
1708
1724
config2 = my_dir2.get_config()
1709
1725
self.assertEqual('http://example.com', config2.get_default_stack_on())