513
517
# Clone source into directory
514
518
target = source_bzrdir.clone(self.get_url('parent/target'))
520
def test_format_initialize_on_transport_ex_stacked_on(self):
521
# trunk is a stackable format. Note that its in the same server area
522
# which is what launchpad does, but not sufficient to exercise the
524
trunk = self.make_branch('trunk', format='1.9')
525
t = self.get_transport('stacked')
526
old_fmt = controldir.format_registry.make_bzrdir('pack-0.92')
527
repo_name = old_fmt.repository_format.network_name()
528
# Should end up with a 1.9 format (stackable)
529
repo, control, require_stacking, repo_policy = \
530
old_fmt.initialize_on_transport_ex(t,
531
repo_format_name=repo_name, stacked_on='../trunk',
534
# Repositories are open write-locked
535
self.assertTrue(repo.is_write_locked())
536
self.addCleanup(repo.unlock)
538
repo = control.open_repository()
539
self.assertIsInstance(control, bzrdir.BzrDir)
540
opened = bzrdir.BzrDir.open(t.base)
541
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
542
self.assertEqual(control._format.network_name(),
543
old_fmt.network_name())
544
self.assertEqual(control._format.network_name(),
545
opened._format.network_name())
546
self.assertEqual(control.__class__, opened.__class__)
547
self.assertLength(1, repo._fallback_repositories)
516
549
def test_sprout_obeys_stacking_policy(self):
517
550
child_branch, new_child_transport = self.prepare_default_stacking()
518
551
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
979
1015
Metadirs should compare equal iff they have the same repo, branch and
982
mydir = bzrdir.format_registry.make_bzrdir('knit')
1018
mydir = controldir.format_registry.make_bzrdir('knit')
983
1019
self.assertEqual(mydir, mydir)
984
1020
self.assertFalse(mydir != mydir)
985
otherdir = bzrdir.format_registry.make_bzrdir('knit')
1021
otherdir = controldir.format_registry.make_bzrdir('knit')
986
1022
self.assertEqual(otherdir, mydir)
987
1023
self.assertFalse(otherdir != mydir)
988
otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
1024
otherdir2 = controldir.format_registry.make_bzrdir('development-subtree')
989
1025
self.assertNotEqual(otherdir2, mydir)
990
1026
self.assertFalse(otherdir2 == mydir)
1028
def test_with_features(self):
1029
tree = self.make_branch_and_tree('tree', format='2a')
1030
tree.bzrdir.update_feature_flags({"bar": "required"})
1031
self.assertRaises(errors.MissingFeature, bzrdir.BzrDir.open, 'tree')
1032
bzrdir.BzrDirMetaFormat1.register_feature('bar')
1033
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
1034
dir = bzrdir.BzrDir.open('tree')
1035
self.assertEqual("required", dir._format.features.get("bar"))
1036
tree.bzrdir.update_feature_flags({"bar": None, "nonexistant": None})
1037
dir = bzrdir.BzrDir.open('tree')
1038
self.assertEqual({}, dir._format.features)
992
1040
def test_needs_conversion_different_working_tree(self):
993
1041
# meta1dirs need an conversion if any element is not the default.
994
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1042
new_format = controldir.format_registry.make_bzrdir('dirstate')
995
1043
tree = self.make_branch_and_tree('tree', format='knit')
996
1044
self.assertTrue(tree.bzrdir.needs_format_conversion(
999
1047
def test_initialize_on_format_uses_smart_transport(self):
1000
1048
self.setup_smart_server_with_call_log()
1001
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1049
new_format = controldir.format_registry.make_bzrdir('dirstate')
1002
1050
transport = self.get_transport('target')
1003
1051
transport.ensure_base()
1004
1052
self.reset_smart_call_log()
1366
1412
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1369
class ExtractFormatStringTests(TestCase):
1371
def test_normal(self):
1372
self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1373
bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
1375
def test_with_optional_feature(self):
1376
self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1377
bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
1378
"optional feature foo\n"))
1380
def test_with_required_feature(self):
1381
self.assertRaises(errors.MissingFeature,
1382
bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1383
"required feature foo\n")
1385
def test_with_invalid_line(self):
1386
self.assertRaises(errors.ParseFormatError,
1387
bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1415
class TestMeta1DirColoFormat(TestCaseWithTransport):
1416
"""Tests specific to the meta1 dir with colocated branches format."""
1418
def test_supports_colo(self):
1419
format = bzrdir.BzrDirMetaFormat1Colo()
1420
self.assertTrue(format.colocated_branches)
1422
def test_upgrade_from_2a(self):
1423
tree = self.make_branch_and_tree('.', format='2a')
1424
format = bzrdir.BzrDirMetaFormat1Colo()
1425
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1426
converter = tree.bzrdir._format.get_converter(format)
1427
result = converter.convert(tree.bzrdir, None)
1428
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1429
self.assertFalse(result.needs_format_conversion(format))
1431
def test_downgrade_to_2a(self):
1432
tree = self.make_branch_and_tree('.', format='development-colo')
1433
format = bzrdir.BzrDirMetaFormat1()
1434
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1435
converter = tree.bzrdir._format.get_converter(format)
1436
result = converter.convert(tree.bzrdir, None)
1437
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1438
self.assertFalse(result.needs_format_conversion(format))
1440
def test_downgrade_to_2a_too_many_branches(self):
1441
tree = self.make_branch_and_tree('.', format='development-colo')
1442
tree.bzrdir.create_branch(name="another-colocated-branch")
1443
converter = tree.bzrdir._format.get_converter(
1444
bzrdir.BzrDirMetaFormat1())
1445
result = converter.convert(tree.bzrdir, bzrdir.BzrDirMetaFormat1())
1446
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1448
def test_nested(self):
1449
tree = self.make_branch_and_tree('.', format='development-colo')
1450
tree.bzrdir.create_branch(name='foo')
1451
tree.bzrdir.create_branch(name='fool/bla')
1453
errors.ParentBranchExists, tree.bzrdir.create_branch,
1456
def test_parent(self):
1457
tree = self.make_branch_and_tree('.', format='development-colo')
1458
tree.bzrdir.create_branch(name='fool/bla')
1459
tree.bzrdir.create_branch(name='foo/bar')
1461
errors.AlreadyBranchError, tree.bzrdir.create_branch,
1465
class SampleBzrFormat(bzrdir.BzrFormat):
1468
def get_format_string(cls):
1469
return "First line\n"
1472
class TestBzrFormat(TestCase):
1473
"""Tests for BzrFormat."""
1475
def test_as_string(self):
1476
format = SampleBzrFormat()
1477
format.features = {"foo": "required"}
1478
self.assertEqual(format.as_string(),
1481
format.features["another"] = "optional"
1482
self.assertEqual(format.as_string(),
1485
"optional another\n")
1487
def test_network_name(self):
1488
# The network string should include the feature info
1489
format = SampleBzrFormat()
1490
format.features = {"foo": "required"}
1492
"First line\nrequired foo\n",
1493
format.network_name())
1495
def test_from_string_no_features(self):
1497
format = SampleBzrFormat.from_string(
1499
self.assertEqual({}, format.features)
1501
def test_from_string_with_feature(self):
1503
format = SampleBzrFormat.from_string(
1504
"First line\nrequired foo\n")
1505
self.assertEqual("required", format.features.get("foo"))
1507
def test_from_string_format_string_mismatch(self):
1508
# The first line has to match the format string
1509
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1510
"Second line\nrequired foo\n")
1512
def test_from_string_missing_space(self):
1513
# At least one space is required in the feature lines
1514
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1515
"First line\nfoo\n")
1517
def test_from_string_with_spaces(self):
1518
# Feature with spaces (in case we add stuff like this in the future)
1519
format = SampleBzrFormat.from_string(
1520
"First line\nrequired foo with spaces\n")
1521
self.assertEqual("required", format.features.get("foo with spaces"))
1524
format1 = SampleBzrFormat()
1525
format1.features = {"nested-trees": "optional"}
1526
format2 = SampleBzrFormat()
1527
format2.features = {"nested-trees": "optional"}
1528
self.assertEqual(format1, format1)
1529
self.assertEqual(format1, format2)
1530
format3 = SampleBzrFormat()
1531
self.assertNotEqual(format1, format3)
1533
def test_check_support_status_optional(self):
1534
# Optional, so silently ignore
1535
format = SampleBzrFormat()
1536
format.features = {"nested-trees": "optional"}
1537
format.check_support_status(True)
1538
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1539
SampleBzrFormat.register_feature("nested-trees")
1540
format.check_support_status(True)
1542
def test_check_support_status_required(self):
1543
# Optional, so trigger an exception
1544
format = SampleBzrFormat()
1545
format.features = {"nested-trees": "required"}
1546
self.assertRaises(errors.MissingFeature, format.check_support_status,
1548
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1549
SampleBzrFormat.register_feature("nested-trees")
1550
format.check_support_status(True)
1552
def test_check_support_status_unknown(self):
1553
# treat unknown necessity as required
1554
format = SampleBzrFormat()
1555
format.features = {"nested-trees": "unknown"}
1556
self.assertRaises(errors.MissingFeature, format.check_support_status,
1558
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1559
SampleBzrFormat.register_feature("nested-trees")
1560
format.check_support_status(True)
1562
def test_feature_already_registered(self):
1563
# a feature can only be registered once
1564
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1565
SampleBzrFormat.register_feature("nested-trees")
1566
self.assertRaises(errors.FeatureAlreadyRegistered,
1567
SampleBzrFormat.register_feature, "nested-trees")
1569
def test_feature_with_space(self):
1570
# spaces are not allowed in feature names
1571
self.assertRaises(ValueError, SampleBzrFormat.register_feature,