1163
1163
opened_dir._format)
1164
1164
self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
1166
def test_format_initialize_on_transport_ex(self):
1167
t = self.get_transport('dir')
1168
self.assertInitializeEx(t)
1170
def test_format_initialize_on_transport_ex_use_existing_dir_True(self):
1171
t = self.get_transport('dir')
1173
self.assertInitializeEx(t, use_existing_dir=True)
1175
def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
1176
if not self.bzrdir_format.is_supported():
1177
# Not initializable - not a failure either.
1179
t = self.get_transport('dir')
1181
self.assertRaises(errors.FileExists,
1182
self.bzrdir_format.initialize_on_transport_ex, t,
1183
use_existing_dir=False)
1185
def test_format_initialize_on_transport_ex_create_prefix_True(self):
1186
t = self.get_transport('missing/dir')
1187
self.assertInitializeEx(t, create_prefix=True)
1189
def test_format_initialize_on_transport_ex_create_prefix_False(self):
1190
if not self.bzrdir_format.is_supported():
1191
# Not initializable - not a failure either.
1193
t = self.get_transport('missing/dir')
1194
self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1195
create_prefix=False)
1197
def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1198
t = self.get_transport('repo')
1199
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1200
repo_name = repo_fmt.repository_format.network_name()
1201
repo = repo_fmt.initialize_on_transport_ex(t,
1202
repo_format_name=repo_name, shared_repo=True)[0]
1203
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1204
force_new_repo=True, repo_format_name=repo_name)
1206
# uninitialisable format
1208
self.assertNotEqual(repo.bzrdir.root_transport.base,
1209
made_repo.bzrdir.root_transport.base)
1211
def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1212
t = self.get_transport('repo')
1213
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1214
repo_name = repo_fmt.repository_format.network_name()
1215
repo = repo_fmt.initialize_on_transport_ex(t,
1216
repo_format_name=repo_name, shared_repo=True)[0]
1217
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1218
force_new_repo=False, repo_format_name=repo_name)
1220
# uninitialisable format
1222
if not isinstance(control._format, (bzrdir.BzrDirFormat5,
1223
bzrdir.BzrDirFormat6,)):
1224
self.assertEqual(repo.bzrdir.root_transport.base,
1225
made_repo.bzrdir.root_transport.base)
1227
def test_format_initialize_on_transport_ex_stacked_on(self):
1228
# trunk is a stackable format. Note that its in the same server area
1229
# which is what launchpad does, but not sufficient to exercise the
1231
trunk = self.make_branch('trunk', format='1.9')
1232
t = self.get_transport('stacked')
1233
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1234
repo_name = old_fmt.repository_format.network_name()
1235
# Should end up with a 1.9 format (stackable)
1236
repo, control = self.assertInitializeEx(t, need_meta=True,
1237
repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
1239
# uninitialisable format
1241
self.assertLength(1, repo._fallback_repositories)
1243
def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1244
t = self.get_transport('dir')
1245
repo, control = self.assertInitializeEx(t)
1246
self.assertEqual(None, repo)
1248
def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1249
t = self.get_transport('dir')
1250
# 1.6 is likely to never be default
1251
fmt = bzrdir.format_registry.make_bzrdir('1.6')
1252
repo_name = fmt.repository_format.network_name()
1253
repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1255
# uninitialisable format
1257
if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
1258
bzrdir.BzrDirFormat6)):
1259
# must stay with the all-in-one-format.
1260
repo_name = self.bzrdir_format.network_name()
1261
self.assertEqual(repo_name, repo._format.network_name())
1263
def assertInitializeEx(self, t, need_meta=False, **kwargs):
1264
"""Execute initialize_on_transport_ex and check it succeeded correctly.
1266
This involves checking that the disk objects were created, open with
1267
the same format returned, and had the expected disk format.
1269
:param t: The transport to initialize on.
1270
:param **kwargs: Additional arguments to pass to
1271
initialize_on_transport_ex.
1272
:return: the resulting repo, control dir tuple.
1274
if not self.bzrdir_format.is_supported():
1275
# Not initializable - not a failure either.
1277
repo, control, require_stacking, repo_policy = \
1278
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1279
self.assertIsInstance(control, bzrdir.BzrDir)
1280
opened = bzrdir.BzrDir.open(t.base)
1281
expected_format = self.bzrdir_format
1282
if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
1283
# Current RemoteBzrDirFormat's do not reliably get network_name
1284
# set, so we skip a number of tests for RemoteBzrDirFormat's.
1285
self.assertIsInstance(control, RemoteBzrDir)
1287
if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1288
bzrdir.BzrDirFormat6)):
1289
# Pre-metadir formats change when we are making something that
1290
# needs a metaformat, because clone is used for push.
1291
expected_format = bzrdir.BzrDirMetaFormat1()
1292
self.assertEqual(control._format.network_name(),
1293
expected_format.network_name())
1294
self.assertEqual(control._format.network_name(),
1295
opened._format.network_name())
1296
self.assertEqual(control.__class__, opened.__class__)
1297
return repo, control
1166
1299
def test_format_network_name(self):
1167
1300
# All control formats must have a network name.
1168
1301
dir = self.make_bzrdir('.')