512
517
# Clone source into directory
513
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)
515
549
def test_sprout_obeys_stacking_policy(self):
516
550
child_branch, new_child_transport = self.prepare_default_stacking()
517
551
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
710
744
def test_open_containing_from_transport(self):
711
745
self.assertRaises(NotBranchError,
712
746
bzrdir.BzrDir.open_containing_from_transport,
713
_mod_transport.get_transport(self.get_readonly_url('')))
747
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
714
748
self.assertRaises(NotBranchError,
715
749
bzrdir.BzrDir.open_containing_from_transport,
716
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
750
_mod_transport.get_transport_from_url(
751
self.get_readonly_url('g/p/q')))
717
752
control = bzrdir.BzrDir.create(self.get_url())
718
753
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
719
_mod_transport.get_transport(self.get_readonly_url('')))
754
_mod_transport.get_transport_from_url(
755
self.get_readonly_url('')))
720
756
self.assertEqual('', relpath)
721
757
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
722
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
758
_mod_transport.get_transport_from_url(
759
self.get_readonly_url('g/p/q')))
723
760
self.assertEqual('g/p/q', relpath)
725
762
def test_open_containing_tree_or_branch(self):
813
850
def test_sprout_recursive_treeless(self):
814
851
tree = self.make_branch_and_tree('tree1',
815
format='dirstate-with-subtree')
852
format='development-subtree')
816
853
sub_tree = self.make_branch_and_tree('tree1/subtree',
817
format='dirstate-with-subtree')
854
format='development-subtree')
818
855
tree.add_reference(sub_tree)
819
856
self.build_tree(['tree1/subtree/file'])
820
857
sub_tree.add('file')
821
858
tree.commit('Initial commit')
822
859
# The following line force the orhaning to reveal bug #634470
823
tree.branch.get_config().set_user_option(
860
tree.branch.get_config_stack().set(
824
861
'bzr.transform.orphan_policy', 'move')
825
862
tree.bzrdir.destroy_workingtree()
826
863
# FIXME: subtree/.bzr is left here which allows the test to pass (or
827
864
# fail :-( ) -- vila 20100909
828
865
repo = self.make_repository('repo', shared=True,
829
format='dirstate-with-subtree')
866
format='development-subtree')
830
867
repo.set_make_working_trees(False)
831
868
# FIXME: we just deleted the workingtree and now we want to use it ????
832
869
# At a minimum, we should use tree.branch below (but this fails too
978
1015
Metadirs should compare equal iff they have the same repo, branch and
981
mydir = bzrdir.format_registry.make_bzrdir('knit')
1018
mydir = controldir.format_registry.make_bzrdir('knit')
982
1019
self.assertEqual(mydir, mydir)
983
1020
self.assertFalse(mydir != mydir)
984
otherdir = bzrdir.format_registry.make_bzrdir('knit')
1021
otherdir = controldir.format_registry.make_bzrdir('knit')
985
1022
self.assertEqual(otherdir, mydir)
986
1023
self.assertFalse(otherdir != mydir)
987
otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
1024
otherdir2 = controldir.format_registry.make_bzrdir('development-subtree')
988
1025
self.assertNotEqual(otherdir2, mydir)
989
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.assertEquals("required", dir._format.features.get("bar"))
1036
tree.bzrdir.update_feature_flags({"bar": None, "nonexistant": None})
1037
dir = bzrdir.BzrDir.open('tree')
1038
self.assertEquals({}, dir._format.features)
991
1040
def test_needs_conversion_different_working_tree(self):
992
1041
# meta1dirs need an conversion if any element is not the default.
993
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1042
new_format = controldir.format_registry.make_bzrdir('dirstate')
994
1043
tree = self.make_branch_and_tree('tree', format='knit')
995
1044
self.assertTrue(tree.bzrdir.needs_format_conversion(
998
1047
def test_initialize_on_format_uses_smart_transport(self):
999
1048
self.setup_smart_server_with_call_log()
1000
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1049
new_format = controldir.format_registry.make_bzrdir('dirstate')
1001
1050
transport = self.get_transport('target')
1002
1051
transport.ensure_base()
1003
1052
self.reset_smart_call_log()
1359
1416
self._transport.put_bytes("a.~1~", "some content")
1360
1417
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1420
class TestMeta1DirColoFormat(TestCaseWithTransport):
1421
"""Tests specific to the meta1 dir with colocated branches format."""
1423
def test_supports_colo(self):
1424
format = bzrdir.BzrDirMetaFormat1Colo()
1425
self.assertTrue(format.colocated_branches)
1427
def test_upgrade_from_2a(self):
1428
tree = self.make_branch_and_tree('.', format='2a')
1429
format = bzrdir.BzrDirMetaFormat1Colo()
1430
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1431
converter = tree.bzrdir._format.get_converter(format)
1432
result = converter.convert(tree.bzrdir, None)
1433
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1434
self.assertFalse(result.needs_format_conversion(format))
1436
def test_downgrade_to_2a(self):
1437
tree = self.make_branch_and_tree('.', format='development-colo')
1438
format = bzrdir.BzrDirMetaFormat1()
1439
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1440
converter = tree.bzrdir._format.get_converter(format)
1441
result = converter.convert(tree.bzrdir, None)
1442
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1443
self.assertFalse(result.needs_format_conversion(format))
1445
def test_downgrade_to_2a_too_many_branches(self):
1446
tree = self.make_branch_and_tree('.', format='development-colo')
1447
tree.bzrdir.create_branch(name="another-colocated-branch")
1448
converter = tree.bzrdir._format.get_converter(
1449
bzrdir.BzrDirMetaFormat1())
1450
result = converter.convert(tree.bzrdir, bzrdir.BzrDirMetaFormat1())
1451
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1453
def test_nested(self):
1454
tree = self.make_branch_and_tree('.', format='development-colo')
1455
tree.bzrdir.create_branch(name='foo')
1456
tree.bzrdir.create_branch(name='fool/bla')
1458
errors.ParentBranchExists, tree.bzrdir.create_branch,
1461
def test_parent(self):
1462
tree = self.make_branch_and_tree('.', format='development-colo')
1463
tree.bzrdir.create_branch(name='fool/bla')
1464
tree.bzrdir.create_branch(name='foo/bar')
1466
errors.AlreadyBranchError, tree.bzrdir.create_branch,
1470
class SampleBzrFormat(bzrdir.BzrFormat):
1473
def get_format_string(cls):
1474
return "First line\n"
1477
class TestBzrFormat(TestCase):
1478
"""Tests for BzrFormat."""
1480
def test_as_string(self):
1481
format = SampleBzrFormat()
1482
format.features = {"foo": "required"}
1483
self.assertEquals(format.as_string(),
1486
format.features["another"] = "optional"
1487
self.assertEquals(format.as_string(),
1490
"optional another\n")
1492
def test_network_name(self):
1493
# The network string should include the feature info
1494
format = SampleBzrFormat()
1495
format.features = {"foo": "required"}
1497
"First line\nrequired foo\n",
1498
format.network_name())
1500
def test_from_string_no_features(self):
1502
format = SampleBzrFormat.from_string(
1504
self.assertEquals({}, format.features)
1506
def test_from_string_with_feature(self):
1508
format = SampleBzrFormat.from_string(
1509
"First line\nrequired foo\n")
1510
self.assertEquals("required", format.features.get("foo"))
1512
def test_from_string_format_string_mismatch(self):
1513
# The first line has to match the format string
1514
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1515
"Second line\nrequired foo\n")
1517
def test_from_string_missing_space(self):
1518
# At least one space is required in the feature lines
1519
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1520
"First line\nfoo\n")
1522
def test_from_string_with_spaces(self):
1523
# Feature with spaces (in case we add stuff like this in the future)
1524
format = SampleBzrFormat.from_string(
1525
"First line\nrequired foo with spaces\n")
1526
self.assertEquals("required", format.features.get("foo with spaces"))
1529
format1 = SampleBzrFormat()
1530
format1.features = {"nested-trees": "optional"}
1531
format2 = SampleBzrFormat()
1532
format2.features = {"nested-trees": "optional"}
1533
self.assertEquals(format1, format1)
1534
self.assertEquals(format1, format2)
1535
format3 = SampleBzrFormat()
1536
self.assertNotEquals(format1, format3)
1538
def test_check_support_status_optional(self):
1539
# Optional, so silently ignore
1540
format = SampleBzrFormat()
1541
format.features = {"nested-trees": "optional"}
1542
format.check_support_status(True)
1543
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1544
SampleBzrFormat.register_feature("nested-trees")
1545
format.check_support_status(True)
1547
def test_check_support_status_required(self):
1548
# Optional, so trigger an exception
1549
format = SampleBzrFormat()
1550
format.features = {"nested-trees": "required"}
1551
self.assertRaises(errors.MissingFeature, format.check_support_status,
1553
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1554
SampleBzrFormat.register_feature("nested-trees")
1555
format.check_support_status(True)
1557
def test_check_support_status_unknown(self):
1558
# treat unknown necessity as required
1559
format = SampleBzrFormat()
1560
format.features = {"nested-trees": "unknown"}
1561
self.assertRaises(errors.MissingFeature, format.check_support_status,
1563
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1564
SampleBzrFormat.register_feature("nested-trees")
1565
format.check_support_status(True)
1567
def test_feature_already_registered(self):
1568
# a feature can only be registered once
1569
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1570
SampleBzrFormat.register_feature("nested-trees")
1571
self.assertRaises(errors.FeatureAlreadyRegistered,
1572
SampleBzrFormat.register_feature, "nested-trees")
1574
def test_feature_with_space(self):
1575
# spaces are not allowed in feature names
1576
self.assertRaises(ValueError, SampleBzrFormat.register_feature,