75
73
def test_get_set_default_format(self):
76
74
old_format = bzrdir.BzrDirFormat.get_default_format()
77
75
# default is BzrDirMetaFormat1
78
self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
76
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
79
77
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
80
78
# creating a bzr dir should now create an instrumented dir.
82
80
result = bzrdir.BzrDir.create('memory:///')
83
self.assertIsInstance(result, SampleBzrDir)
81
self.failUnless(isinstance(result, SampleBzrDir))
85
83
controldir.ControlDirFormat._set_default_format(old_format)
86
84
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
286
284
self.build_tree(["foo/", "bar/"], transport=t)
287
285
def check_format(format, url):
288
286
format.initialize(url)
289
t = _mod_transport.get_transport_from_path(url)
287
t = _mod_transport.get_transport(url)
290
288
found_format = bzrdir.BzrDirFormat.find_format(t)
291
self.assertIsInstance(found_format, format.__class__)
289
self.failUnless(isinstance(found_format, format.__class__))
292
290
check_format(BzrDirFormatTest1(), "foo")
293
291
check_format(BzrDirFormatTest2(), "bar")
295
293
def test_find_format_nothing_there(self):
296
294
self.assertRaises(NotBranchError,
297
295
bzrdir.BzrDirFormat.find_format,
298
_mod_transport.get_transport_from_path('.'))
296
_mod_transport.get_transport('.'))
300
298
def test_find_format_unknown_format(self):
301
299
t = self.get_transport()
303
301
t.put_bytes('.bzr/branch-format', '')
304
302
self.assertRaises(UnknownFormatError,
305
303
bzrdir.BzrDirFormat.find_format,
306
_mod_transport.get_transport_from_path('.'))
304
_mod_transport.get_transport('.'))
308
306
def test_register_unregister_format(self):
309
307
format = SampleBzrDirFormat()
317
315
# which bzrdir.open_containing will refuse (not supported)
318
316
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
319
317
# but open_downlevel will work
320
t = _mod_transport.get_transport_from_url(url)
318
t = _mod_transport.get_transport(url)
321
319
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
322
320
# unregister the format
323
321
bzrdir.BzrProber.formats.remove(format.get_format_string())
513
511
# Clone source into directory
514
512
target = source_bzrdir.clone(self.get_url('parent/target'))
516
def test_format_initialize_on_transport_ex_stacked_on(self):
517
# trunk is a stackable format. Note that its in the same server area
518
# which is what launchpad does, but not sufficient to exercise the
520
trunk = self.make_branch('trunk', format='1.9')
521
t = self.get_transport('stacked')
522
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
523
repo_name = old_fmt.repository_format.network_name()
524
# Should end up with a 1.9 format (stackable)
525
repo, control, require_stacking, repo_policy = \
526
old_fmt.initialize_on_transport_ex(t,
527
repo_format_name=repo_name, stacked_on='../trunk',
530
# Repositories are open write-locked
531
self.assertTrue(repo.is_write_locked())
532
self.addCleanup(repo.unlock)
534
repo = control.open_repository()
535
self.assertIsInstance(control, bzrdir.BzrDir)
536
opened = bzrdir.BzrDir.open(t.base)
537
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
538
self.assertEqual(control._format.network_name(),
539
old_fmt.network_name())
540
self.assertEqual(control._format.network_name(),
541
opened._format.network_name())
542
self.assertEqual(control.__class__, opened.__class__)
543
self.assertLength(1, repo._fallback_repositories)
545
514
def test_sprout_obeys_stacking_policy(self):
546
515
child_branch, new_child_transport = self.prepare_default_stacking()
547
516
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
740
709
def test_open_containing_from_transport(self):
741
710
self.assertRaises(NotBranchError,
742
711
bzrdir.BzrDir.open_containing_from_transport,
743
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
712
_mod_transport.get_transport(self.get_readonly_url('')))
744
713
self.assertRaises(NotBranchError,
745
714
bzrdir.BzrDir.open_containing_from_transport,
746
_mod_transport.get_transport_from_url(
747
self.get_readonly_url('g/p/q')))
715
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
748
716
control = bzrdir.BzrDir.create(self.get_url())
749
717
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
750
_mod_transport.get_transport_from_url(
751
self.get_readonly_url('')))
718
_mod_transport.get_transport(self.get_readonly_url('')))
752
719
self.assertEqual('', relpath)
753
720
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
754
_mod_transport.get_transport_from_url(
755
self.get_readonly_url('g/p/q')))
721
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
756
722
self.assertEqual('g/p/q', relpath)
758
724
def test_open_containing_tree_or_branch(self):
831
797
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
832
798
tree2.lock_read()
833
799
self.addCleanup(tree2.unlock)
834
self.assertPathExists('tree2/subtree/file')
800
self.failUnlessExists('tree2/subtree/file')
835
801
self.assertEqual('tree-reference', tree2.kind('subtree-root'))
837
803
def test_cloning_metadir(self):
841
807
branch = self.make_branch('branch', format='knit')
842
808
format = branch.bzrdir.cloning_metadir()
843
809
self.assertIsInstance(format.workingtree_format,
844
workingtree_4.WorkingTreeFormat6)
810
workingtree.WorkingTreeFormat3)
846
812
def test_sprout_recursive_treeless(self):
847
813
tree = self.make_branch_and_tree('tree1',
871
837
# #634470. -- vila 20100909
872
838
self.assertRaises(errors.NotBranchError,
873
839
tree.bzrdir.sprout, 'repo/tree2')
874
# self.assertPathExists('repo/tree2/subtree')
875
# self.assertPathDoesNotExist('repo/tree2/subtree/file')
840
# self.failUnlessExists('repo/tree2/subtree')
841
# self.failIfExists('repo/tree2/subtree/file')
877
843
def make_foo_bar_baz(self):
878
844
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
931
897
def evaluate(bzrdir):
933
899
repo = bzrdir.open_repository()
934
except errors.NoRepositoryPresent:
900
except NoRepositoryPresent:
935
901
return True, bzrdir.root_transport.base
937
903
return False, bzrdir.root_transport.base
997
963
checkout_base = t.clone('checkout').base
998
964
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
999
965
self.assertEqual(checkout_base,
1000
dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
966
dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
1002
968
def test_meta1dir_uses_lockdir(self):
1003
969
"""Meta1 format uses a LockDir to guard the whole directory, not a file."""
1091
1057
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1092
1058
checkout_format = my_bzrdir.checkout_metadir()
1093
1059
self.assertIsInstance(checkout_format.workingtree_format,
1094
workingtree_4.WorkingTreeFormat4)
1060
workingtree.WorkingTreeFormat3)
1097
1063
class TestHTTPRedirections(object):
1242
1208
def __init__(self, *args, **kwargs):
1243
1209
super(_TestBzrDir, self).__init__(*args, **kwargs)
1244
self.test_branch = _TestBranch(self.transport)
1210
self.test_branch = _TestBranch()
1245
1211
self.test_branch.repository = self.create_repository()
1247
1213
def open_branch(self, unsupported=False):
1258
1224
class _TestBranch(bzrlib.branch.Branch):
1259
1225
"""Test Branch implementation for TestBzrDirSprout."""
1261
def __init__(self, transport, *args, **kwargs):
1227
def __init__(self, *args, **kwargs):
1262
1228
self._format = _TestBranchFormat()
1263
self._transport = transport
1264
self.base = transport.base
1265
1229
super(_TestBranch, self).__init__(*args, **kwargs)
1266
1230
self.calls = []
1267
1231
self._parent = None
1269
1233
def sprout(self, *args, **kwargs):
1270
1234
self.calls.append('sprout')
1271
return _TestBranch(self._transport)
1235
return _TestBranch()
1273
1237
def copy_content_into(self, destination, revision_id=None):
1274
1238
self.calls.append('copy_content_into')
1352
1313
self.assertEqual('fail', err._preformatted_string)
1354
1315
def test_post_repo_init(self):
1355
from bzrlib.controldir import RepoInitHookParams
1316
from bzrlib.bzrdir import RepoInitHookParams
1357
1318
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1358
1319
calls.append, None)
1397
1358
self._transport.put_bytes("a.~1~", "some content")
1398
1359
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1401
class TestMeta1DirColoFormat(TestCaseWithTransport):
1402
"""Tests specific to the meta1 dir with colocated branches format."""
1404
def test_supports_colo(self):
1405
format = bzrdir.BzrDirMetaFormat1Colo()
1406
self.assertTrue(format.colocated_branches)
1408
def test_upgrade_from_2a(self):
1409
tree = self.make_branch_and_tree('.', format='2a')
1410
format = bzrdir.BzrDirMetaFormat1Colo()
1411
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1412
converter = tree.bzrdir._format.get_converter(format)
1413
result = converter.convert(tree.bzrdir, None)
1414
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1415
self.assertFalse(result.needs_format_conversion(format))
1417
def test_downgrade_to_2a(self):
1418
tree = self.make_branch_and_tree('.', format='development-colo')
1419
format = bzrdir.BzrDirMetaFormat1()
1420
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1421
converter = tree.bzrdir._format.get_converter(format)
1422
result = converter.convert(tree.bzrdir, None)
1423
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1424
self.assertFalse(result.needs_format_conversion(format))
1426
def test_downgrade_to_2a_too_many_branches(self):
1427
tree = self.make_branch_and_tree('.', format='development-colo')
1428
tree.bzrdir.create_branch(name="another-colocated-branch")
1429
converter = tree.bzrdir._format.get_converter(
1430
bzrdir.BzrDirMetaFormat1())
1431
self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,