1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
branch as _mod_branch,
24
repository as _mod_repository,
28
class TestInfo(tests.TestCaseWithTransport):
30
def test_describe_standalone_layout(self):
31
tree = self.make_branch_and_tree('tree')
32
self.assertEqual('Empty control directory', info.describe_layout())
33
self.assertEqual('Unshared repository with trees',
34
info.describe_layout(tree.branch.repository))
35
tree.branch.repository.set_make_working_trees(False)
36
self.assertEqual('Unshared repository',
37
info.describe_layout(tree.branch.repository))
38
self.assertEqual('Standalone branch',
39
info.describe_layout(tree.branch.repository, tree.branch))
40
self.assertEqual('Standalone branchless tree',
41
info.describe_layout(tree.branch.repository, None, tree))
42
self.assertEqual('Standalone tree',
43
info.describe_layout(tree.branch.repository, tree.branch, tree))
44
tree.branch.bind(tree.branch)
45
self.assertEqual('Bound branch',
46
info.describe_layout(tree.branch.repository, tree.branch))
47
self.assertEqual('Checkout',
48
info.describe_layout(tree.branch.repository, tree.branch, tree))
49
checkout = tree.branch.create_checkout('checkout', lightweight=True)
50
self.assertEqual('Lightweight checkout',
51
info.describe_layout(checkout.branch.repository, checkout.branch,
55
def test_describe_repository_layout(self):
56
repository = self.make_repository('.', shared=True)
57
tree = bzrdir.BzrDir.create_branch_convenience('tree',
58
force_new_tree=True).bzrdir.open_workingtree()
59
self.assertEqual('Shared repository with trees',
60
info.describe_layout(tree.branch.repository))
61
repository.set_make_working_trees(False)
62
self.assertEqual('Shared repository',
63
info.describe_layout(tree.branch.repository))
64
self.assertEqual('Repository branch',
65
info.describe_layout(tree.branch.repository, tree.branch))
66
self.assertEqual('Repository branchless tree',
67
info.describe_layout(tree.branch.repository, None, tree))
68
self.assertEqual('Repository tree',
69
info.describe_layout(tree.branch.repository, tree.branch, tree))
70
tree.branch.bind(tree.branch)
71
self.assertEqual('Repository checkout',
72
info.describe_layout(tree.branch.repository, tree.branch, tree))
73
checkout = tree.branch.create_checkout('checkout', lightweight=True)
74
self.assertEqual('Lightweight checkout',
75
info.describe_layout(checkout.branch.repository, checkout.branch,
78
def assertTreeDescription(self, format):
79
self.make_branch_and_tree('%s_tree' % format, format=format)
80
tree = workingtree.WorkingTree.open('%s_tree' % format)
81
self.assertEqual(format, info.describe_format(tree.bzrdir,
82
tree.branch.repository, tree.branch, tree))
84
def assertCheckoutDescription(self, format, expected=None):
87
branch = self.make_branch('%s_cobranch' % format, format=format)
88
# this ought to be easier...
89
branch.create_checkout('%s_co' % format,
90
lightweight=True).bzrdir.destroy_workingtree()
91
control = bzrdir.BzrDir.open('%s_co' % format)
92
old_format = control._format.workingtree_format
94
control._format.workingtree_format = \
95
bzrdir.format_registry.make_bzrdir(format).workingtree_format
96
control.create_workingtree()
97
tree = workingtree.WorkingTree.open('%s_co' % format)
98
self.assertEqual(expected, info.describe_format(tree.bzrdir,
99
tree.branch.repository, tree.branch, tree))
101
control._format.workingtree_format = old_format
103
def assertBranchDescription(self, format, expected=None):
106
self.make_branch('%s_branch' % format, format=format)
107
branch = _mod_branch.Branch.open('%s_branch' % format)
108
self.assertEqual(expected, info.describe_format(branch.bzrdir,
109
branch.repository, branch, None))
111
def assertRepoDescription(self, format, expected=None):
114
self.make_repository('%s_repo' % format, format=format)
115
repo = _mod_repository.Repository.open('%s_repo' % format)
116
self.assertEqual(expected, info.describe_format(repo.bzrdir,
119
def test_describe_format(self):
120
for key in bzrdir.format_registry.keys():
123
self.assertTreeDescription(key)
125
for key in bzrdir.format_registry.keys():
126
if key in ('default', 'weave'):
129
if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
130
expected = 'dirstate / dirstate-tags'
131
if key in ('knit', 'metaweave'):
132
expected = 'knit / metaweave'
133
self.assertCheckoutDescription(key, expected)
135
for key in bzrdir.format_registry.keys():
139
if key in ('dirstate', 'knit'):
140
expected = 'dirstate / knit'
141
self.assertBranchDescription(key, expected)
143
for key in bzrdir.format_registry.keys():
147
if key in ('dirstate', 'knit', 'dirstate-tags'):
148
expected = 'dirstate / dirstate-tags / knit'
149
self.assertRepoDescription(key, expected)
151
format = bzrdir.format_registry.make_bzrdir('metaweave')
152
format.set_branch_format(_mod_branch.BzrBranchFormat6())
153
tree = self.make_branch_and_tree('unknown', format=format)
154
self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
155
tree.branch.repository, tree.branch, tree))