162
162
if vfs_dir.has_workingtree():
163
163
# This ControlDir format doesn't support ControlDirs without
164
164
# working trees, so this test is irrelevant.
165
raise TestNotApplicable("format does not support "
166
"control directories without working tree")
166
167
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
168
169
def test_clone_bzrdir_repository_under_shared(self):
181
182
self.make_repository('target', shared=True)
182
183
except errors.IncompatibleFormat:
184
raise TestNotApplicable("repository format does not support "
185
"shared repositories")
184
186
target = dir.clone(self.get_url('target/child'))
185
187
self.assertNotEqual(dir.transport.base, target.transport.base)
186
188
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
407
412
target_branch=referenced_branch)
408
413
except errors.IncompatibleFormat:
409
414
# this is ok too, not all formats have to support references.
415
raise TestNotApplicable("control directory does not "
416
"support branch references")
411
417
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
412
418
dir.get_branch_reference())
421
427
dir = self.make_bzrdir('source')
422
428
if dir.has_branch():
423
429
# this format does not support branchless bzrdirs.
430
raise TestNotApplicable("format does not support "
431
"branchless control directories")
425
432
self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
427
434
def test_sprout_bzrdir_empty(self):
478
487
shared_repo = self.make_repository('target', shared=True)
479
488
except errors.IncompatibleFormat:
489
raise TestNotApplicable("format does not support "
490
"shared repositories")
481
491
target = dir.sprout(self.get_url('target/child'))
482
492
self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
483
493
self.assertTrue(shared_repo.has_revision('1'))
557
569
shared_repo = self.make_repository('target', shared=True)
558
570
except errors.IncompatibleFormat:
571
raise TestNotApplicable("format does not support shared "
560
573
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
561
574
self.assertNotEqual(
562
575
dir.control_transport.base,
615
629
shared_repo = self.make_repository('target', shared=True)
616
630
except errors.IncompatibleFormat:
631
raise TestNotApplicable("format does not support shared "
618
633
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
619
634
self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
620
635
self.assertFalse(shared_repo.has_revision('1'))
627
642
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
628
643
target_branch=referenced_branch)
629
644
except errors.IncompatibleFormat:
630
# this is ok too, not all formats have to support references.
645
raise TestNotApplicable("format does not support branch "
632
647
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
633
648
target = dir.sprout(self.get_url('target'))
634
649
self.assertNotEqual(dir.transport.base, target.transport.base)
647
662
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
648
663
target_branch=referenced_tree.branch)
649
664
except errors.IncompatibleFormat:
650
# this is ok too, not all formats have to support references.
665
raise TestNotApplicable("format does not support branch "
652
667
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
654
669
shared_repo = self.make_repository('target', shared=True)
655
670
except errors.IncompatibleFormat:
671
raise TestNotApplicable("format does not support "
672
"shared repositories")
657
673
target = dir.sprout(self.get_url('target/child'))
658
674
self.assertNotEqual(dir.transport.base, target.transport.base)
659
675
# we want target to have a branch that is in-place.
674
690
target_branch=referenced_tree.branch)
675
691
except errors.IncompatibleFormat:
676
692
# this is ok too, not all formats have to support references.
693
raise TestNotApplicable("format does not support "
678
695
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
680
697
shared_repo = self.make_repository('target', shared=True)
681
698
except errors.IncompatibleFormat:
699
raise TestNotApplicable("format does not support shared "
683
701
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
684
702
self.assertNotEqual(dir.transport.base, target.transport.base)
685
703
# we want target to have a branch that is in-place.
824
842
target_branch=referenced_branch)
825
843
except errors.IncompatibleFormat:
826
844
# this is ok too, not all formats have to support references.
845
raise TestNotApplicable("format does not support "
828
847
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
829
848
tree = self.createWorkingTreeOrSkip(dir)
830
849
self.build_tree(['source/subdir/'])
850
869
target_branch=referenced_branch)
851
870
except errors.IncompatibleFormat:
852
871
# this is ok too, not all formats have to support references.
872
raise TestNotApplicable("format does not support "
854
874
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
855
875
tree = self.createWorkingTreeOrSkip(dir)
856
876
self.build_tree(['source/foo'])
937
957
def test_format_initialize_find_open(self):
938
958
# loopback test to check the current format initializes to itself.
939
if not self.bzrdir_format.is_supported():
959
if not self.bzrdir_format.is_initializable():
940
960
# unsupported formats are not loopback testable
941
961
# because the default open will not open them and
942
962
# they may not be initializable.
963
raise TestNotApplicable("format is not initializable")
944
964
# for remote formats, there must be no prior assumption about the
945
965
# network name to use - it's possible that this may somehow have got
946
966
# in through an unisolated test though - see
951
971
# supported formats must be able to init and open
952
972
t = self.get_transport()
953
973
readonly_t = self.get_readonly_transport()
955
made_control = self.bzrdir_format.initialize(t.base)
956
except errors.UninitializableFormat:
974
made_control = self.bzrdir_format.initialize(t.base)
958
975
self.assertIsInstance(made_control, controldir.ControlDir)
959
976
if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
978
995
self.assertInitializeEx(t, use_existing_dir=True)
980
997
def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
981
if not self.bzrdir_format.is_supported():
982
# Not initializable - not a failure either.
998
if not self.bzrdir_format.is_initializable():
999
raise TestNotApplicable("format is not initializable")
984
1000
t = self.get_transport('dir')
987
self.assertRaises(errors.FileExists,
988
self.bzrdir_format.initialize_on_transport_ex, t,
989
use_existing_dir=False)
990
except errors.UninitializableFormat:
1002
self.assertRaises(errors.FileExists,
1003
self.bzrdir_format.initialize_on_transport_ex, t,
1004
use_existing_dir=False)
993
1006
def test_format_initialize_on_transport_ex_create_prefix_True(self):
994
1007
t = self.get_transport('missing/dir')
995
1008
self.assertInitializeEx(t, create_prefix=True)
997
1010
def test_format_initialize_on_transport_ex_create_prefix_False(self):
998
if not self.bzrdir_format.is_supported():
999
# Not initializable - not a failure either.
1011
if not self.bzrdir_format.is_initializable():
1012
raise TestNotApplicable("format is not initializable")
1001
1013
t = self.get_transport('missing/dir')
1002
1014
self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1003
1015
create_prefix=False)
1026
1038
made_repo.bzrdir.root_transport.base)
1028
1040
def test_format_initialize_on_transport_ex_stacked_on(self):
1029
if not self.bzrdir_format.is_supported():
1030
# Not initializable - not a failure either.
1041
if not self.bzrdir_format.is_initializable():
1042
raise TestNotApplicable("format is not initializable")
1032
1043
# trunk is a stackable format. Note that its in the same server area
1033
1044
# which is what launchpad does, but not sufficient to exercise the
1034
1045
# general case.
1100
1111
initialize_on_transport_ex.
1101
1112
:return: the resulting repo, control dir tuple.
1103
if not self.bzrdir_format.is_supported():
1104
# Not initializable - not a failure either.
1105
raise TestNotApplicable("control dir format is not "
1108
repo, control, require_stacking, repo_policy = \
1109
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1110
except errors.UninitializableFormat:
1111
# Not initializable - not a failure either.
1112
raise TestNotApplicable("control dir format is not "
1114
if not self.bzrdir_format.is_initializable():
1115
raise TestNotApplicable("control dir format is not "
1117
repo, control, require_stacking, repo_policy = \
1118
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1114
1119
if repo is not None:
1115
1120
# Repositories are open write-locked
1116
1121
self.assertTrue(repo.is_write_locked())
1162
1167
def test_create_branch(self):
1163
1168
# a bzrdir can construct a branch and repository for itself.
1164
if not self.bzrdir_format.is_supported():
1169
if not self.bzrdir_format.is_initializable():
1165
1170
# unsupported formats are not loopback testable
1166
1171
# because the default open will not open them and
1167
1172
# they may not be initializable.
1173
raise TestNotApplicable("format is not initializable")
1169
1174
t = self.get_transport()
1171
made_control = self.bzrdir_format.initialize(t.base)
1172
except errors.UninitializableFormat:
1175
made_control = self.bzrdir_format.initialize(t.base)
1174
1176
made_repo = made_control.create_repository()
1175
1177
made_branch = made_control.create_branch()
1176
1178
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1179
1181
def test_create_branch_append_revisions_only(self):
1180
1182
# a bzrdir can construct a branch and repository for itself.
1181
if not self.bzrdir_format.is_supported():
1183
if not self.bzrdir_format.is_initializable():
1182
1184
# unsupported formats are not loopback testable
1183
1185
# because the default open will not open them and
1184
1186
# they may not be initializable.
1187
raise TestNotApplicable("format is not initializable")
1186
1188
t = self.get_transport()
1188
made_control = self.bzrdir_format.initialize(t.base)
1189
except errors.UninitializableFormat:
1190
# format can not be initialized
1189
made_control = self.bzrdir_format.initialize(t.base)
1192
1190
made_repo = made_control.create_repository()
1194
1192
made_branch = made_control.create_branch(
1195
1193
append_revisions_only=True)
1196
1194
except errors.UpgradeRequired:
1195
raise TestNotApplicable("format does not support "
1196
"append_revisions_only setting")
1198
1197
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1199
1198
self.assertEquals(True, made_branch.get_append_revisions_only())
1200
1199
self.assertEqual(made_control, made_branch.bzrdir)
1202
1201
def test_open_branch(self):
1203
if not self.bzrdir_format.is_supported():
1202
if not self.bzrdir_format.is_initializable():
1204
1203
# unsupported formats are not loopback testable
1205
1204
# because the default open will not open them and
1206
1205
# they may not be initializable.
1206
raise TestNotApplicable("format is not initializable")
1208
1207
t = self.get_transport()
1210
made_control = self.bzrdir_format.initialize(t.base)
1211
except errors.UninitializableFormat:
1208
made_control = self.bzrdir_format.initialize(t.base)
1213
1209
made_repo = made_control.create_repository()
1214
1210
made_branch = made_control.create_branch()
1215
1211
opened_branch = made_control.open_branch()
1218
1214
self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1220
1216
def test_list_branches(self):
1221
if not self.bzrdir_format.is_supported():
1222
# unsupported formats are not loopback testable
1223
# because the default open will not open them and
1224
# they may not be initializable.
1217
if not self.bzrdir_format.is_initializable():
1218
raise TestNotApplicable("format is not initializable")
1226
1219
t = self.get_transport()
1228
made_control = self.bzrdir_format.initialize(t.base)
1229
except errors.UninitializableFormat:
1220
made_control = self.bzrdir_format.initialize(t.base)
1231
1221
made_repo = made_control.create_repository()
1232
1222
made_branch = made_control.create_branch()
1233
1223
branches = made_control.list_branches()
1243
1233
def test_create_repository(self):
1244
1234
# a bzrdir can construct a repository for itself.
1245
if not self.bzrdir_format.is_supported():
1235
if not self.bzrdir_format.is_initializable():
1246
1236
# unsupported formats are not loopback testable
1247
1237
# because the default open will not open them and
1248
1238
# they may not be initializable.
1239
raise TestNotApplicable("format is not initializable")
1250
1240
t = self.get_transport()
1252
made_control = self.bzrdir_format.initialize(t.base)
1253
except errors.UninitializableFormat:
1241
made_control = self.bzrdir_format.initialize(t.base)
1255
1242
made_repo = made_control.create_repository()
1256
1243
# Check that we have a repository object.
1257
1244
made_repo.has_revision('foo')
1260
1247
def test_create_repository_shared(self):
1261
1248
# a bzrdir can create a shared repository or
1262
1249
# fail appropriately
1263
if not self.bzrdir_format.is_supported():
1250
if not self.bzrdir_format.is_initializable():
1264
1251
# unsupported formats are not loopback testable
1265
1252
# because the default open will not open them and
1266
1253
# they may not be initializable.
1254
raise TestNotApplicable("format is not initializable")
1268
1255
t = self.get_transport()
1270
made_control = self.bzrdir_format.initialize(t.base)
1271
except errors.UninitializableFormat:
1256
made_control = self.bzrdir_format.initialize(t.base)
1274
1258
made_repo = made_control.create_repository(shared=True)
1275
1259
except errors.IncompatibleFormat:
1276
1260
# Old bzrdir formats don't support shared repositories
1277
1261
# and should raise IncompatibleFormat
1262
raise TestNotApplicable("format does not support shared "
1279
1264
self.assertTrue(made_repo.is_shared())
1281
1266
def test_create_repository_nonshared(self):
1282
1267
# a bzrdir can create a non-shared repository
1283
if not self.bzrdir_format.is_supported():
1268
if not self.bzrdir_format.is_initializable():
1284
1269
# unsupported formats are not loopback testable
1285
1270
# because the default open will not open them and
1286
1271
# they may not be initializable.
1272
raise TestNotApplicable("format is not initializable")
1288
1273
t = self.get_transport()
1290
made_control = self.bzrdir_format.initialize(t.base)
1291
except errors.UninitializableFormat:
1274
made_control = self.bzrdir_format.initialize(t.base)
1294
1276
made_repo = made_control.create_repository(shared=False)
1295
1277
except errors.IncompatibleFormat:
1296
1278
# Some control dir formats don't support non-shared repositories
1297
1279
# and should raise IncompatibleFormat
1280
raise TestNotApplicable("format does not support shared "
1299
1282
self.assertFalse(made_repo.is_shared())
1301
1284
def test_open_repository(self):
1302
if not self.bzrdir_format.is_supported():
1285
if not self.bzrdir_format.is_initializable():
1303
1286
# unsupported formats are not loopback testable
1304
1287
# because the default open will not open them and
1305
1288
# they may not be initializable.
1289
raise TestNotApplicable("format is not initializable")
1307
1290
t = self.get_transport()
1309
made_control = self.bzrdir_format.initialize(t.base)
1310
except errors.UninitializableFormat:
1291
made_control = self.bzrdir_format.initialize(t.base)
1312
1292
made_repo = made_control.create_repository()
1313
1293
opened_repo = made_control.open_repository()
1314
1294
self.assertEqual(made_control, opened_repo.bzrdir)
1318
1298
def test_create_workingtree(self):
1319
1299
# a bzrdir can construct a working tree for itself.
1320
if not self.bzrdir_format.is_supported():
1300
if not self.bzrdir_format.is_initializable():
1321
1301
# unsupported formats are not loopback testable
1322
1302
# because the default open will not open them and
1323
1303
# they may not be initializable.
1304
raise TestNotApplicable("format is not initializable")
1325
1305
t = self.get_transport()
1327
made_control = self.bzrdir_format.initialize(t.base)
1328
except errors.UninitializableFormat:
1306
made_control = self.bzrdir_format.initialize(t.base)
1330
1307
made_repo = made_control.create_repository()
1331
1308
made_branch = made_control.create_branch()
1332
1309
made_tree = self.createWorkingTreeOrSkip(made_control)
1336
1313
def test_create_workingtree_revision(self):
1337
1314
# a bzrdir can construct a working tree for itself @ a specific revision.
1315
if not self.bzrdir_format.is_initializable():
1316
raise TestNotApplicable("format is not initializable")
1338
1317
t = self.get_transport()
1339
1318
source = self.make_branch_and_tree('source')
1340
1319
source.commit('a', rev_id='a', allow_pointless=True)
1341
1320
source.commit('b', rev_id='b', allow_pointless=True)
1343
1322
t_new = t.clone('new')
1345
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1346
except errors.UninitializableFormat:
1323
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1348
1324
source.branch.repository.clone(made_control)
1349
1325
source.branch.clone(made_control)
1354
1330
self.assertEqual(['a'], made_tree.get_parent_ids())
1356
1332
def test_open_workingtree(self):
1357
if not self.bzrdir_format.is_supported():
1358
# unsupported formats are not loopback testable
1359
# because the default open will not open them and
1360
# they may not be initializable.
1333
if not self.bzrdir_format.is_initializable():
1334
raise TestNotApplicable("format is not initializable")
1362
1335
# this has to be tested with local access as we still support creating
1363
1336
# format 6 bzrdirs
1364
1337
t = self.get_transport()
1370
1343
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1371
1344
raise TestSkipped("Can't initialize %r on transport %r"
1372
1345
% (self.bzrdir_format, t))
1373
except errors.UninitializableFormat:
1375
1346
opened_tree = made_control.open_workingtree()
1376
1347
self.assertEqual(made_control, opened_tree.bzrdir)
1377
1348
self.assertIsInstance(opened_tree, made_tree.__class__)
1380
1351
def test_get_selected_branch(self):
1381
1352
# The segment parameters are accessible from the root transport
1382
1353
# if a URL with segment parameters is opened.
1383
if not self.bzrdir_format.is_supported():
1384
# unsupported formats are not loopback testable
1385
# because the default open will not open them and
1386
# they may not be initializable.
1354
if not self.bzrdir_format.is_initializable():
1355
raise TestNotApplicable("format is not initializable")
1388
1356
t = self.get_transport()
1390
1358
made_control = self.bzrdir_format.initialize(t.base)
1391
except (errors.NotLocalUrl, errors.UnsupportedOperation,
1392
errors.UninitializableFormat):
1359
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1393
1360
raise TestSkipped("Can't initialize %r on transport %r"
1394
1361
% (self.bzrdir_format, t))
1395
1362
dir = bzrdir.BzrDir.open(t.base+",branch=foo")
1400
1367
def test_get_selected_branch_none_selected(self):
1401
1368
# _get_selected_branch defaults to None
1402
if not self.bzrdir_format.is_supported():
1403
# unsupported formats are not loopback testable
1404
# because the default open will not open them and
1405
# they may not be initializable.
1369
if not self.bzrdir_format.is_initializable():
1370
raise TestNotApplicable("format is not initializable")
1407
1371
t = self.get_transport()
1409
1373
made_control = self.bzrdir_format.initialize(t.base)
1410
1374
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1411
1375
raise TestSkipped("Can't initialize %r on transport %r"
1412
1376
% (self.bzrdir_format, t))
1413
except errors.UninitializableFormat:
1415
1377
dir = bzrdir.BzrDir.open(t.base)
1416
1378
self.assertIs(None, dir._get_selected_branch())
1427
1389
repo = self.make_repository('.', shared=True)
1428
1390
except errors.IncompatibleFormat:
1429
1391
# need a shared repository to test this.
1392
raise TestNotApplicable("requires shared repository support")
1431
1393
if not repo._format.supports_nesting_repositories:
1432
1394
raise TestNotApplicable("requires nesting repositories")
1433
1395
url = self.get_url('intermediate')
1455
1417
repo = self.make_repository('.', shared=True)
1456
1418
except errors.IncompatibleFormat:
1457
1419
# need a shared repository to test this.
1420
raise TestNotApplicable("requires format with shared repository "
1459
1422
if not repo._format.supports_nesting_repositories:
1423
raise TestNotApplicable("requires support for nesting "
1461
1425
url = self.get_url('childbzrdir')
1462
1426
self.get_transport().mkdir('childbzrdir')
1463
1427
made_control = self.bzrdir_format.initialize(url)
1479
1443
containing_repo = self.make_repository('.', shared=True)
1480
1444
except errors.IncompatibleFormat:
1481
1445
# need a shared repository to test this.
1446
raise TestNotApplicable("requires support for shared "
1483
1448
if not containing_repo._format.supports_nesting_repositories:
1484
1449
raise TestNotApplicable("format does not support "
1485
1450
"nesting repositories")
1495
1460
containing_repo = self.make_repository('.', shared=True)
1496
1461
except errors.IncompatibleFormat:
1497
1462
# need a shared repository to test this.
1463
raise TestNotApplicable("requires support for shared "
1499
1465
if not containing_repo._format.supports_nesting_repositories:
1466
raise TestNotApplicable("requires support for nesting "
1501
1468
url = self.get_url('childrepo')
1502
1469
self.get_transport().mkdir('childrepo')
1503
1470
child_control = self.bzrdir_format.initialize(url)
1516
1483
repo = self.make_repository('.', shared=True)
1517
1484
except errors.IncompatibleFormat:
1518
1485
# need a shared repository to test this.
1486
raise TestNotApplicable("requires support for shared "
1520
1488
if not repo._format.supports_nesting_repositories:
1489
raise TestNotApplicable("requires support for nesting "
1522
1491
url = self.get_url('intermediate')
1523
1492
t = self.get_transport()
1524
1493
t.mkdir('intermediate')
1737
1707
def test_find_repository_no_repository(self):
1738
1708
# loopback test to check the current format fails to find a
1739
1709
# share repository correctly.
1740
if not self.bzrdir_format.is_supported():
1710
if not self.bzrdir_format.is_initializable():
1741
1711
# unsupported formats are not loopback testable
1742
1712
# because the default open will not open them and
1743
1713
# they may not be initializable.
1714
raise TestNotApplicable("format is not initializable")
1745
1715
# supported formats must be able to init and open
1746
1716
# - do the vfs initialisation over the basic vfs transport
1747
1717
# XXX: TODO this should become a 'bzrdirlocation' api call.
1748
1718
url = self.get_vfs_only_url('subdir')
1749
1719
transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
1751
made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1752
except errors.UninitializableFormat:
1720
made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1755
1722
repo = made_control.open_repository()
1756
1723
# if there is a repository, then the format cannot ever hit this