1
# Copyright (C) 2006-2013, 2016 Canonical Ltd
1
# Copyright (C) 2006-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
170
170
self.assertNotContainsRe(new, 'hidden')
172
172
def test_set_default_repository(self):
173
default_factory = controldir.format_registry.get('default')
174
old_default = [k for k, v in controldir.format_registry.iteritems()
173
default_factory = bzrdir.format_registry.get('default')
174
old_default = [k for k, v in bzrdir.format_registry.iteritems()
175
175
if v == default_factory and k != 'default'][0]
176
controldir.format_registry.set_default_repository('dirstate-with-subtree')
176
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
178
self.assertIs(controldir.format_registry.get('dirstate-with-subtree'),
179
controldir.format_registry.get('default'))
178
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
179
bzrdir.format_registry.get('default'))
181
181
repository.format_registry.get_default().__class__,
182
182
knitrepo.RepositoryFormatKnit3)
184
controldir.format_registry.set_default_repository(old_default)
184
bzrdir.format_registry.set_default_repository(old_default)
186
186
def test_aliases(self):
187
187
a_registry = controldir.ControlDirFormatRegistry()
212
212
"""A sample BzrDir implementation to allow testing static methods."""
214
214
def create_repository(self, shared=False):
215
"""See ControlDir.create_repository."""
215
"""See BzrDir.create_repository."""
216
216
return "A repository"
218
218
def open_repository(self):
219
"""See ControlDir.open_repository."""
219
"""See BzrDir.open_repository."""
220
220
return SampleRepository(self)
222
222
def create_branch(self, name=None):
223
"""See ControlDir.create_branch."""
223
"""See BzrDir.create_branch."""
224
224
if name is not None:
225
225
raise NoColocatedBranchSupport(self)
226
226
return SampleBranch(self)
228
228
def create_workingtree(self):
229
"""See ControlDir.create_workingtree."""
229
"""See BzrDir.create_workingtree."""
337
337
def test_create_branch_and_repo_under_shared(self):
338
338
# creating a branch and repo in a shared repo uses the
339
339
# shared repository
340
format = controldir.format_registry.make_bzrdir('knit')
340
format = bzrdir.format_registry.make_bzrdir('knit')
341
341
self.make_repository('.', shared=True, format=format)
342
342
branch = bzrdir.BzrDir.create_branch_and_repo(
343
343
self.get_url('child'), format=format)
347
347
def test_create_branch_and_repo_under_shared_force_new(self):
348
348
# creating a branch and repo in a shared repo can be forced to
349
349
# make a new repo
350
format = controldir.format_registry.make_bzrdir('knit')
350
format = bzrdir.format_registry.make_bzrdir('knit')
351
351
self.make_repository('.', shared=True, format=format)
352
352
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
353
353
force_new_repo=True,
368
368
def test_create_standalone_working_tree_under_shared_repo(self):
369
369
# create standalone working tree always makes a repo.
370
format = controldir.format_registry.make_bzrdir('knit')
370
format = bzrdir.format_registry.make_bzrdir('knit')
371
371
self.make_repository('.', shared=True, format=format)
372
372
# note this is deliberately readonly, as this failure should
373
373
# occur before any writes.
381
381
def test_create_branch_convenience(self):
382
382
# outside a repo the default convenience output is a repo+branch_tree
383
format = controldir.format_registry.make_bzrdir('knit')
383
format = bzrdir.format_registry.make_bzrdir('knit')
384
384
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
385
385
branch.bzrdir.open_workingtree()
386
386
branch.bzrdir.open_repository()
388
388
def test_create_branch_convenience_possible_transports(self):
389
389
"""Check that the optional 'possible_transports' is recognized"""
390
format = controldir.format_registry.make_bzrdir('knit')
390
format = bzrdir.format_registry.make_bzrdir('knit')
391
391
t = self.get_transport()
392
392
branch = bzrdir.BzrDir.create_branch_convenience(
393
393
'.', format=format, possible_transports=[t])
398
398
"""Creating a branch at the root of a fs should work."""
399
399
self.vfs_transport_factory = memory.MemoryServer
400
400
# outside a repo the default convenience output is a repo+branch_tree
401
format = controldir.format_registry.make_bzrdir('knit')
401
format = bzrdir.format_registry.make_bzrdir('knit')
402
402
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
404
404
self.assertRaises(errors.NoWorkingTree,
408
408
def test_create_branch_convenience_under_shared_repo(self):
409
409
# inside a repo the default convenience output is a branch+ follow the
410
410
# repo tree policy
411
format = controldir.format_registry.make_bzrdir('knit')
411
format = bzrdir.format_registry.make_bzrdir('knit')
412
412
self.make_repository('.', shared=True, format=format)
413
413
branch = bzrdir.BzrDir.create_branch_convenience('child',
419
419
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
420
420
# inside a repo the default convenience output is a branch+ follow the
421
421
# repo tree policy but we can override that
422
format = controldir.format_registry.make_bzrdir('knit')
422
format = bzrdir.format_registry.make_bzrdir('knit')
423
423
self.make_repository('.', shared=True, format=format)
424
424
branch = bzrdir.BzrDir.create_branch_convenience('child',
425
425
force_new_tree=False, format=format)
431
431
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
432
432
# inside a repo the default convenience output is a branch+ follow the
433
433
# repo tree policy
434
format = controldir.format_registry.make_bzrdir('knit')
434
format = bzrdir.format_registry.make_bzrdir('knit')
435
435
repo = self.make_repository('.', shared=True, format=format)
436
436
repo.set_make_working_trees(False)
437
437
branch = bzrdir.BzrDir.create_branch_convenience('child',
444
444
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
445
445
# inside a repo the default convenience output is a branch+ follow the
446
446
# repo tree policy but we can override that
447
format = controldir.format_registry.make_bzrdir('knit')
447
format = bzrdir.format_registry.make_bzrdir('knit')
448
448
repo = self.make_repository('.', shared=True, format=format)
449
449
repo.set_make_working_trees(False)
450
450
branch = bzrdir.BzrDir.create_branch_convenience('child',
456
456
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
457
457
# inside a repo the default convenience output is overridable to give
458
458
# repo+branch+tree
459
format = controldir.format_registry.make_bzrdir('knit')
459
format = bzrdir.format_registry.make_bzrdir('knit')
460
460
self.make_repository('.', shared=True, format=format)
461
461
branch = bzrdir.BzrDir.create_branch_convenience('child',
462
462
force_new_repo=True, format=format)
524
524
trunk = self.make_branch('trunk', format='1.9')
525
525
t = self.get_transport('stacked')
526
old_fmt = controldir.format_registry.make_bzrdir('pack-0.92')
526
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
527
527
repo_name = old_fmt.repository_format.network_name()
528
528
# Should end up with a 1.9 format (stackable)
529
529
repo, control, require_stacking, repo_policy = \
825
825
def test_sprout_recursive(self):
826
826
tree = self.make_branch_and_tree('tree1',
827
format='development-subtree')
827
format='dirstate-with-subtree')
828
828
sub_tree = self.make_branch_and_tree('tree1/subtree',
829
format='development-subtree')
829
format='dirstate-with-subtree')
830
830
sub_tree.set_root_id('subtree-root')
831
831
tree.add_reference(sub_tree)
832
832
self.build_tree(['tree1/subtree/file'])
850
850
def test_sprout_recursive_treeless(self):
851
851
tree = self.make_branch_and_tree('tree1',
852
format='development-subtree')
852
format='dirstate-with-subtree')
853
853
sub_tree = self.make_branch_and_tree('tree1/subtree',
854
format='development-subtree')
854
format='dirstate-with-subtree')
855
855
tree.add_reference(sub_tree)
856
856
self.build_tree(['tree1/subtree/file'])
857
857
sub_tree.add('file')
858
858
tree.commit('Initial commit')
859
859
# The following line force the orhaning to reveal bug #634470
860
tree.branch.get_config_stack().set(
860
tree.branch.get_config().set_user_option(
861
861
'bzr.transform.orphan_policy', 'move')
862
862
tree.bzrdir.destroy_workingtree()
863
863
# FIXME: subtree/.bzr is left here which allows the test to pass (or
864
864
# fail :-( ) -- vila 20100909
865
865
repo = self.make_repository('repo', shared=True,
866
format='development-subtree')
866
format='dirstate-with-subtree')
867
867
repo.set_make_working_trees(False)
868
868
# FIXME: we just deleted the workingtree and now we want to use it ????
869
869
# At a minimum, we should use tree.branch below (but this fails too
992
992
branch_base = t.clone('branch').base
993
993
self.assertEqual(branch_base, dir.get_branch_transport(None).base)
994
994
self.assertEqual(branch_base,
995
dir.get_branch_transport(BzrBranchFormat5()).base)
995
dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
996
996
repository_base = t.clone('repository').base
997
997
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
998
998
repository_format = repository.format_registry.get_default()
1015
1015
Metadirs should compare equal iff they have the same repo, branch and
1018
mydir = controldir.format_registry.make_bzrdir('knit')
1018
mydir = bzrdir.format_registry.make_bzrdir('knit')
1019
1019
self.assertEqual(mydir, mydir)
1020
1020
self.assertFalse(mydir != mydir)
1021
otherdir = controldir.format_registry.make_bzrdir('knit')
1021
otherdir = bzrdir.format_registry.make_bzrdir('knit')
1022
1022
self.assertEqual(otherdir, mydir)
1023
1023
self.assertFalse(otherdir != mydir)
1024
otherdir2 = controldir.format_registry.make_bzrdir('development-subtree')
1024
otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
1025
1025
self.assertNotEqual(otherdir2, mydir)
1026
1026
self.assertFalse(otherdir2 == mydir)
1032
1032
bzrdir.BzrDirMetaFormat1.register_feature('bar')
1033
1033
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
1034
1034
dir = bzrdir.BzrDir.open('tree')
1035
self.assertEqual("required", dir._format.features.get("bar"))
1035
self.assertEquals("required", dir._format.features.get("bar"))
1036
1036
tree.bzrdir.update_feature_flags({"bar": None, "nonexistant": None})
1037
1037
dir = bzrdir.BzrDir.open('tree')
1038
self.assertEqual({}, dir._format.features)
1038
self.assertEquals({}, dir._format.features)
1040
1040
def test_needs_conversion_different_working_tree(self):
1041
1041
# meta1dirs need an conversion if any element is not the default.
1042
new_format = controldir.format_registry.make_bzrdir('dirstate')
1042
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1043
1043
tree = self.make_branch_and_tree('tree', format='knit')
1044
1044
self.assertTrue(tree.bzrdir.needs_format_conversion(
1047
1047
def test_initialize_on_format_uses_smart_transport(self):
1048
1048
self.setup_smart_server_with_call_log()
1049
new_format = controldir.format_registry.make_bzrdir('dirstate')
1049
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1050
1050
transport = self.get_transport('target')
1051
1051
transport.ensure_base()
1052
1052
self.reset_smart_call_log()
1071
1071
def test_create_branch_convenience(self):
1072
1072
# outside a repo the default convenience output is a repo+branch_tree
1073
format = controldir.format_registry.make_bzrdir('knit')
1073
format = bzrdir.format_registry.make_bzrdir('knit')
1074
1074
branch = bzrdir.BzrDir.create_branch_convenience(
1075
1075
self.get_url('foo'), format=format)
1076
1076
self.assertRaises(errors.NoWorkingTree,
1080
1080
def test_create_branch_convenience_force_tree_not_local_fails(self):
1081
1081
# outside a repo the default convenience output is a repo+branch_tree
1082
format = controldir.format_registry.make_bzrdir('knit')
1082
format = bzrdir.format_registry.make_bzrdir('knit')
1083
1083
self.assertRaises(errors.NotLocalUrl,
1084
1084
bzrdir.BzrDir.create_branch_convenience,
1085
1085
self.get_url('foo'),
1091
1091
def test_clone(self):
1092
1092
# clone into a nonlocal path works
1093
format = controldir.format_registry.make_bzrdir('knit')
1093
format = bzrdir.format_registry.make_bzrdir('knit')
1094
1094
branch = bzrdir.BzrDir.create_branch_convenience('local',
1096
1096
branch.bzrdir.open_workingtree()
1231
1231
raise TestSkipped('unable to make file hidden without pywin32 library')
1232
1232
b = bzrdir.BzrDir.create('.')
1233
1233
self.build_tree(['a'])
1234
self.assertEqual(['a'], self.get_ls())
1234
self.assertEquals(['a'], self.get_ls())
1236
1236
def test_dot_bzr_hidden_with_url(self):
1237
1237
if sys.platform == 'win32' and not win32utils.has_win32file:
1238
1238
raise TestSkipped('unable to make file hidden without pywin32 library')
1239
1239
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1240
1240
self.build_tree(['a'])
1241
self.assertEqual(['a'], self.get_ls())
1241
self.assertEquals(['a'], self.get_ls())
1244
1244
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1404
1404
possible_transports=[self._transport])
1405
1405
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1407
def test_deprecated_generate_backup_name(self):
1408
res = self.applyDeprecated(
1409
symbol_versioning.deprecated_in((2, 3, 0)),
1410
self._bzrdir.generate_backup_name, 'whatever')
1407
1412
def test_new(self):
1408
1413
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1475
1480
def test_as_string(self):
1476
1481
format = SampleBzrFormat()
1477
1482
format.features = {"foo": "required"}
1478
self.assertEqual(format.as_string(),
1483
self.assertEquals(format.as_string(),
1480
1485
"required foo\n")
1481
1486
format.features["another"] = "optional"
1482
self.assertEqual(format.as_string(),
1487
self.assertEquals(format.as_string(),
1484
1489
"required foo\n"
1485
1490
"optional another\n")
1488
1493
# The network string should include the feature info
1489
1494
format = SampleBzrFormat()
1490
1495
format.features = {"foo": "required"}
1492
1497
"First line\nrequired foo\n",
1493
1498
format.network_name())
1497
1502
format = SampleBzrFormat.from_string(
1498
1503
"First line\n")
1499
self.assertEqual({}, format.features)
1504
self.assertEquals({}, format.features)
1501
1506
def test_from_string_with_feature(self):
1502
1507
# Proper feature
1503
1508
format = SampleBzrFormat.from_string(
1504
1509
"First line\nrequired foo\n")
1505
self.assertEqual("required", format.features.get("foo"))
1510
self.assertEquals("required", format.features.get("foo"))
1507
1512
def test_from_string_format_string_mismatch(self):
1508
1513
# The first line has to match the format string
1518
1523
# Feature with spaces (in case we add stuff like this in the future)
1519
1524
format = SampleBzrFormat.from_string(
1520
1525
"First line\nrequired foo with spaces\n")
1521
self.assertEqual("required", format.features.get("foo with spaces"))
1526
self.assertEquals("required", format.features.get("foo with spaces"))
1523
1528
def test_eq(self):
1524
1529
format1 = SampleBzrFormat()
1525
1530
format1.features = {"nested-trees": "optional"}
1526
1531
format2 = SampleBzrFormat()
1527
1532
format2.features = {"nested-trees": "optional"}
1528
self.assertEqual(format1, format1)
1529
self.assertEqual(format1, format2)
1533
self.assertEquals(format1, format1)
1534
self.assertEquals(format1, format2)
1530
1535
format3 = SampleBzrFormat()
1531
self.assertNotEqual(format1, format3)
1536
self.assertNotEquals(format1, format3)
1533
1538
def test_check_support_status_optional(self):
1534
1539
# Optional, so silently ignore