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
18
from urllib import quote
21
branch as _mod_branch,
26
repository as _mod_repository,
30
class TestInfo(tests.TestCaseWithTransport):
32
def test_describe_standalone_layout(self):
33
tree = self.make_branch_and_tree('tree')
34
self.assertEqual('Empty control directory', info.describe_layout())
35
self.assertEqual('Unshared repository with trees',
36
info.describe_layout(tree.branch.repository))
37
tree.branch.repository.set_make_working_trees(False)
38
self.assertEqual('Unshared repository',
39
info.describe_layout(tree.branch.repository))
40
self.assertEqual('Standalone branch',
41
info.describe_layout(tree.branch.repository, tree.branch))
42
self.assertEqual('Standalone branchless tree',
43
info.describe_layout(tree.branch.repository, None, tree))
44
self.assertEqual('Standalone tree',
45
info.describe_layout(tree.branch.repository, tree.branch, tree))
46
tree.branch.bind(tree.branch)
47
self.assertEqual('Bound branch',
48
info.describe_layout(tree.branch.repository, tree.branch))
49
self.assertEqual('Checkout',
50
info.describe_layout(tree.branch.repository, tree.branch, tree))
51
checkout = tree.branch.create_checkout('checkout', lightweight=True)
52
self.assertEqual('Lightweight checkout',
53
info.describe_layout(checkout.branch.repository, checkout.branch,
56
def test_describe_repository_layout(self):
57
repository = self.make_repository('.', shared=True)
58
tree = bzrdir.BzrDir.create_branch_convenience('tree',
59
force_new_tree=True).bzrdir.open_workingtree()
60
self.assertEqual('Shared repository with trees',
61
info.describe_layout(tree.branch.repository))
62
repository.set_make_working_trees(False)
63
self.assertEqual('Shared repository',
64
info.describe_layout(tree.branch.repository))
65
self.assertEqual('Repository branch',
66
info.describe_layout(tree.branch.repository, tree.branch))
67
self.assertEqual('Repository branchless tree',
68
info.describe_layout(tree.branch.repository, None, tree))
69
self.assertEqual('Repository tree',
70
info.describe_layout(tree.branch.repository, tree.branch, tree))
71
tree.branch.bind(tree.branch)
72
self.assertEqual('Repository checkout',
73
info.describe_layout(tree.branch.repository, tree.branch, tree))
74
checkout = tree.branch.create_checkout('checkout', lightweight=True)
75
self.assertEqual('Lightweight checkout',
76
info.describe_layout(checkout.branch.repository, checkout.branch,
79
def assertTreeDescription(self, format):
80
"""Assert a tree's format description matches expectations"""
81
self.make_branch_and_tree('%s_tree' % format, format=format)
82
tree = workingtree.WorkingTree.open('%s_tree' % format)
83
self.assertEqual(format, info.describe_format(tree.bzrdir,
84
tree.branch.repository, tree.branch, tree))
86
def assertCheckoutDescription(self, format, expected=None):
87
"""Assert a checkout's format description matches expectations"""
90
branch = self.make_branch('%s_cobranch' % format, format=format)
91
# this ought to be easier...
92
branch.create_checkout('%s_co' % format,
93
lightweight=True).bzrdir.destroy_workingtree()
94
control = bzrdir.BzrDir.open('%s_co' % format)
95
old_format = control._format.workingtree_format
97
control._format.workingtree_format = \
98
bzrdir.format_registry.make_bzrdir(format).workingtree_format
99
control.create_workingtree()
100
tree = workingtree.WorkingTree.open('%s_co' % format)
101
format_description = info.describe_format(tree.bzrdir,
102
tree.branch.repository, tree.branch, tree)
103
self.assertEqual(expected, format_description,
104
"checkout of format called %r was described as %r" %
105
(expected, format_description))
107
control._format.workingtree_format = old_format
109
def assertBranchDescription(self, format, expected=None):
110
"""Assert branch's format description matches expectations"""
113
self.make_branch('%s_branch' % format, format=format)
114
branch = _mod_branch.Branch.open('%s_branch' % format)
115
self.assertEqual(expected, info.describe_format(branch.bzrdir,
116
branch.repository, branch, None))
118
def assertRepoDescription(self, format, expected=None):
119
"""Assert repository's format description matches expectations"""
122
self.make_repository('%s_repo' % format, format=format)
123
repo = _mod_repository.Repository.open('%s_repo' % format)
124
self.assertEqual(expected, info.describe_format(repo.bzrdir,
127
def test_describe_tree_format(self):
128
for key in bzrdir.format_registry.keys():
131
self.assertTreeDescription(key)
133
def test_describe_checkout_format(self):
134
for key in bzrdir.format_registry.keys():
135
if key in ('default', 'weave', 'experimental'):
137
if key.startswith('experimental-'):
138
# these are typically hidden or aliases for other formats
141
if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
142
'pack-0.92', 'pack-0.92-subtree', 'rich-root',
144
expected = 'dirstate or dirstate-tags or pack-0.92 or'\
145
' rich-root or rich-root-pack'
146
if key in ('knit', 'metaweave'):
147
expected = 'knit or metaweave'
148
self.assertCheckoutDescription(key, expected)
150
def test_describe_branch_format(self):
151
for key in bzrdir.format_registry.keys():
155
if key in ('dirstate', 'knit'):
156
expected = 'dirstate or knit'
157
self.assertBranchDescription(key, expected)
159
def test_describe_repo_format(self):
160
for key in bzrdir.format_registry.keys():
164
if key in ('dirstate', 'knit', 'dirstate-tags'):
165
expected = 'dirstate or dirstate-tags or knit'
166
self.assertRepoDescription(key, expected)
168
format = bzrdir.format_registry.make_bzrdir('metaweave')
169
format.set_branch_format(_mod_branch.BzrBranchFormat6())
170
tree = self.make_branch_and_tree('unknown', format=format)
171
self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
172
tree.branch.repository, tree.branch, tree))
174
def test_gather_location_standalone(self):
175
tree = self.make_branch_and_tree('tree')
176
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
177
info.gather_location_info(tree.branch.repository, tree.branch,
179
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
180
info.gather_location_info(tree.branch.repository, tree.branch))
183
def test_gather_location_repo(self):
184
srepo = self.make_repository('shared', shared=True)
185
self.assertEqual([('shared repository',
186
srepo.bzrdir.root_transport.base)],
187
info.gather_location_info(srepo))
188
urepo = self.make_repository('unshared')
189
self.assertEqual([('repository',
190
urepo.bzrdir.root_transport.base)],
191
info.gather_location_info(urepo))
193
def test_gather_location_repo_branch(self):
194
srepo = self.make_repository('shared', shared=True)
195
self.assertEqual([('shared repository',
196
srepo.bzrdir.root_transport.base)],
197
info.gather_location_info(srepo))
198
tree = self.make_branch_and_tree('shared/tree')
199
self.assertEqual([('shared repository',
200
srepo.bzrdir.root_transport.base),
201
('repository branch', tree.branch.base)],
202
info.gather_location_info(srepo, tree.branch, tree))
204
def test_gather_location_light_checkout(self):
205
tree = self.make_branch_and_tree('tree')
206
lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
208
[('light checkout root', lcheckout.bzrdir.root_transport.base),
209
('checkout of branch', tree.bzrdir.root_transport.base)],
210
self.gather_tree_location_info(lcheckout))
212
def test_gather_location_heavy_checkout(self):
213
tree = self.make_branch_and_tree('tree')
214
checkout = tree.branch.create_checkout('checkout')
216
[('checkout root', checkout.bzrdir.root_transport.base),
217
('checkout of branch', tree.bzrdir.root_transport.base)],
218
self.gather_tree_location_info(checkout))
219
light_checkout = checkout.branch.create_checkout('light_checkout',
222
[('light checkout root',
223
light_checkout.bzrdir.root_transport.base),
224
('checkout root', checkout.bzrdir.root_transport.base),
225
('checkout of branch', tree.bzrdir.root_transport.base)],
226
self.gather_tree_location_info(light_checkout)
229
def test_gather_location_shared_repo_checkout(self):
230
tree = self.make_branch_and_tree('tree')
231
srepo = self.make_repository('shared', shared=True)
232
shared_checkout = tree.branch.create_checkout('shared/checkout')
234
[('repository checkout root',
235
shared_checkout.bzrdir.root_transport.base),
236
('checkout of branch', tree.bzrdir.root_transport.base),
237
('shared repository', srepo.bzrdir.root_transport.base)],
238
self.gather_tree_location_info(shared_checkout))
240
def gather_tree_location_info(self, tree):
241
return info.gather_location_info(tree.branch.repository, tree.branch,
244
def test_gather_location_bound(self):
245
branch = self.make_branch('branch')
246
bound_branch = self.make_branch('bound_branch')
247
bound_branch.bind(branch)
249
[('branch root', bound_branch.bzrdir.root_transport.base),
250
('bound to branch', branch.bzrdir.root_transport.base)],
251
info.gather_location_info(bound_branch.repository, bound_branch)
254
def test_location_list(self):
255
if sys.platform == 'win32':
256
raise tests.TestSkipped('Windows-unfriendly test')
257
locs = info.LocationList('/home/foo')
258
locs.add_url('a', 'file:///home/foo/')
259
locs.add_url('b', 'file:///home/foo/bar/')
260
locs.add_url('c', 'file:///home/bar/bar')
261
locs.add_url('d', 'http://example.com/example/')
262
locs.add_url('e', None)
263
self.assertEqual(locs.locs, [('a', '.'),
265
('c', '/home/bar/bar'),
266
('d', 'http://example.com/example/')])
267
self.assertEqualDiff(' a: .\n b: bar\n c: /home/bar/bar\n'
268
' d: http://example.com/example/\n',
269
''.join(locs.get_lines()))
271
def test_gather_related_braches(self):
272
branch = self.make_branch('.')
273
branch.set_public_branch('baz')
274
branch.set_push_location('bar')
275
branch.set_parent('foo')
276
branch.set_submit_branch('qux')
278
[('public branch', 'baz'), ('push branch', 'bar'),
279
('parent branch', 'foo'), ('submit branch', 'qux')],
280
info._gather_related_branches(branch).locs)