23
23
from StringIO import StringIO
25
25
from bzrlib import (
31
34
import bzrlib.branch
32
import bzrlib.bzrdir as bzrdir
33
import bzrlib.errors as errors
34
35
from bzrlib.errors import (NotBranchError,
35
36
UnknownFormatError,
36
37
UnsupportedFormatError,
38
import bzrlib.repository as repository
39
39
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
40
40
from bzrlib.tests.HttpServer import HttpServer
41
41
from bzrlib.transport import get_transport
78
78
my_format_registry.set_default('knit')
79
79
my_format_registry.register_metadir(
81
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
82
'Experimental successor to knit. Use at your own risk.',
84
my_format_registry.register_metadir(
86
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
81
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
87
82
'Experimental successor to knit. Use at your own risk.',
88
branch_format='BzrBranchFormat6')
83
branch_format='bzrlib.branch.BzrBranchFormat6')
89
84
return my_format_registry
91
86
def test_format_registry(self):
132
127
default_factory = bzrdir.format_registry.get('default')
133
128
old_default = [k for k, v in bzrdir.format_registry.iteritems()
134
129
if v == default_factory and k != 'default'][0]
135
bzrdir.format_registry.set_default_repository('experimental-knit2')
130
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
137
self.assertIs(bzrdir.format_registry.get('experimental-knit2'),
132
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
138
133
bzrdir.format_registry.get('default'))
140
135
repository.RepositoryFormat.get_default_format().__class__,
141
knitrepo.RepositoryFormatKnit2)
136
knitrepo.RepositoryFormatKnit3)
143
138
bzrdir.format_registry.set_default_repository(old_default)
477
472
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
475
def test_sprout_recursive(self):
476
tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
477
sub_tree = self.make_branch_and_tree('tree1/subtree',
478
format='dirstate-with-subtree')
479
tree.add_reference(sub_tree)
480
self.build_tree(['tree1/subtree/file'])
482
tree.commit('Initial commit')
483
tree.bzrdir.sprout('tree2')
484
self.failUnlessExists('tree2/subtree/file')
486
def test_cloning_metadir(self):
487
"""Ensure that cloning metadir is suitable"""
488
bzrdir = self.make_bzrdir('bzrdir')
489
bzrdir.cloning_metadir()
490
branch = self.make_branch('branch', format='knit')
491
format = branch.bzrdir.cloning_metadir()
492
self.assertIsInstance(format.workingtree_format,
493
workingtree.WorkingTreeFormat3)
495
def test_sprout_recursive_treeless(self):
496
tree = self.make_branch_and_tree('tree1',
497
format='dirstate-with-subtree')
498
sub_tree = self.make_branch_and_tree('tree1/subtree',
499
format='dirstate-with-subtree')
500
tree.add_reference(sub_tree)
501
self.build_tree(['tree1/subtree/file'])
503
tree.commit('Initial commit')
504
tree.bzrdir.destroy_workingtree()
505
repo = self.make_repository('repo', shared=True,
506
format='dirstate-with-subtree')
507
repo.set_make_working_trees(False)
508
tree.bzrdir.sprout('repo/tree2')
509
self.failUnlessExists('repo/tree2/subtree')
510
self.failIfExists('repo/tree2/subtree/file')
481
513
class TestMeta1DirFormat(TestCaseWithTransport):
482
514
"""Tests specific to the meta1 dir format."""
503
535
t = dir.transport
504
536
self.assertIsDirectory('branch-lock', t)
538
def test_comparison(self):
539
"""Equality and inequality behave properly.
541
Metadirs should compare equal iff they have the same repo, branch and
544
mydir = bzrdir.format_registry.make_bzrdir('knit')
545
self.assertEqual(mydir, mydir)
546
self.assertFalse(mydir != mydir)
547
otherdir = bzrdir.format_registry.make_bzrdir('knit')
548
self.assertEqual(otherdir, mydir)
549
self.assertFalse(otherdir != mydir)
550
otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
551
self.assertNotEqual(otherdir2, mydir)
552
self.assertFalse(otherdir2 == mydir)
554
def test_needs_conversion_different_working_tree(self):
555
# meta1dirs need an conversion if any element is not the default.
556
old_format = bzrdir.BzrDirFormat.get_default_format()
558
new_default = bzrdir.format_registry.make_bzrdir('dirstate')
559
bzrdir.BzrDirFormat._set_default_format(new_default)
561
tree = self.make_branch_and_tree('tree', format='knit')
562
self.assertTrue(tree.bzrdir.needs_format_conversion())
564
bzrdir.BzrDirFormat._set_default_format(old_format)
507
567
class TestFormat5(TestCaseWithTransport):
508
568
"""Tests specific to the version 5 bzrdir format."""
678
738
result.open_branch()
679
739
result.open_repository()
741
def test_checkout_metadir(self):
742
# checkout_metadir has reasonable working tree format even when no
743
# working tree is present
744
self.make_branch('branch-knit2', format='dirstate-with-subtree')
745
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
746
checkout_format = my_bzrdir.checkout_metadir()
747
self.assertIsInstance(checkout_format.workingtree_format,
748
workingtree.WorkingTreeFormat3)
682
751
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):