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
75
75
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
76
76
'Format using knits',
78
my_format_registry.register_metadir('experimental-knit3',
79
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
81
tree='WorkingTreeFormatAB1')
78
82
my_format_registry.set_default('knit')
79
83
my_format_registry.register_metadir(
80
84
'experimental-knit2',
100
104
my_bzrdir = my_format_registry.make_bzrdir('knit')
101
105
self.assertIsInstance(my_bzrdir.repository_format,
102
106
knitrepo.RepositoryFormatKnit1)
107
my_bzrdir = my_format_registry.make_bzrdir('experimental-knit3')
108
self.assertIsInstance(my_bzrdir.repository_format,
109
knitrepo.RepositoryFormatKnit3)
110
self.assertIsInstance(my_bzrdir.workingtree_format,
111
workingtree.WorkingTreeFormatAB1)
103
112
my_bzrdir = my_format_registry.make_bzrdir('branch6')
104
113
self.assertIsInstance(my_bzrdir.get_branch_format(),
105
114
bzrlib.branch.BzrBranchFormat6)
476
485
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
488
def test_sprout_recursive(self):
489
tree = self.make_branch_and_tree('tree1', format='experimental-knit3')
490
sub_tree = self.make_branch_and_tree('tree1/subtree',
491
format='experimental-knit3')
492
tree.add_reference(sub_tree)
493
self.build_tree(['tree1/subtree/file'])
495
tree.commit('Initial commit')
496
tree.bzrdir.sprout('tree2')
497
self.failUnlessExists('tree2/subtree/file')
499
def test_cloning_metadir(self):
500
"""Ensure that cloning metadir is suitable"""
501
bzrdir = self.make_bzrdir('bzrdir')
502
bzrdir.cloning_metadir()
503
branch = self.make_branch('branch', format='knit')
504
format = branch.bzrdir.cloning_metadir()
505
self.assertIsInstance(format.workingtree_format,
506
workingtree.WorkingTreeFormat3)
507
branch2 = self.make_branch('branch2', format='experimental-knit3')
508
format2 = branch2.bzrdir.cloning_metadir()
509
self.assertIsInstance(format2.workingtree_format,
510
workingtree.WorkingTreeFormatAB1)
512
def test_sprout_recursive_treeless(self):
513
tree = self.make_branch_and_tree('tree1', format='experimental-knit3')
514
sub_tree = self.make_branch_and_tree('tree1/subtree',
515
format='experimental-knit3')
516
tree.add_reference(sub_tree)
517
self.build_tree(['tree1/subtree/file'])
519
tree.commit('Initial commit')
520
tree.bzrdir.destroy_workingtree()
521
repo = self.make_repository('repo', shared=True,
522
format='experimental-knit3')
523
repo.set_make_working_trees(False)
524
tree.bzrdir.sprout('repo/tree2')
525
self.failUnlessExists('repo/tree2/subtree')
526
self.failIfExists('repo/tree2/subtree/file')
480
529
class TestMeta1DirFormat(TestCaseWithTransport):
481
530
"""Tests specific to the meta1 dir format."""
502
551
t = dir.transport
503
552
self.assertIsDirectory('branch-lock', t)
554
def test_comparison(self):
555
"""Equality and inequality behave properly.
557
Metadirs should compare equal iff they have the same repo, branch and
560
mydir = bzrdir.format_registry.make_bzrdir('knit')
561
self.assertEqual(mydir, mydir)
562
self.assertFalse(mydir != mydir)
563
otherdir = bzrdir.format_registry.make_bzrdir('knit')
564
self.assertEqual(otherdir, mydir)
565
self.assertFalse(otherdir != mydir)
566
otherdir2 = bzrdir.format_registry.make_bzrdir('experimental-knit2')
567
self.assertNotEqual(otherdir2, mydir)
568
self.assertFalse(otherdir2 == mydir)
506
571
class TestFormat5(TestCaseWithTransport):
507
572
"""Tests specific to the version 5 bzrdir format."""
677
742
result.open_branch()
678
743
result.open_repository()
745
def test_checkout_metadir(self):
746
# checkout_metadir has reasonable working tree format even when no
747
# working tree is present
748
self.make_branch('branch-knit3', format='experimental-knit3')
749
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit3'))
750
checkout_format = my_bzrdir.checkout_metadir()
751
self.assertIsInstance(checkout_format.workingtree_format,
752
workingtree.WorkingTreeFormatAB1)
754
self.make_branch('branch-knit2', format='experimental-knit2')
755
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
756
checkout_format = my_bzrdir.checkout_metadir()
757
self.assertIsInstance(checkout_format.workingtree_format,
758
workingtree.WorkingTreeFormat3)
681
761
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):