1
# Copyright (C) 2007-2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
branch as _mod_branch,
21
bzrbranch as _mod_bzrbranch,
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())
36
'Unshared repository with trees and colocated branches',
37
info.describe_layout(tree.branch.repository, control=tree.bzrdir))
38
tree.branch.repository.set_make_working_trees(False)
39
self.assertEqual('Unshared repository with colocated branches',
40
info.describe_layout(tree.branch.repository, control=tree.bzrdir))
41
self.assertEqual('Standalone branch',
42
info.describe_layout(tree.branch.repository, tree.branch,
44
self.assertEqual('Standalone branchless tree',
45
info.describe_layout(tree.branch.repository, None, tree,
47
self.assertEqual('Standalone tree',
48
info.describe_layout(tree.branch.repository, tree.branch, tree,
50
tree.branch.bind(tree.branch)
51
self.assertEqual('Bound branch',
52
info.describe_layout(tree.branch.repository, tree.branch,
54
self.assertEqual('Checkout',
55
info.describe_layout(tree.branch.repository, tree.branch, tree,
57
checkout = tree.branch.create_checkout('checkout', lightweight=True)
58
self.assertEqual('Lightweight checkout',
59
info.describe_layout(checkout.branch.repository, checkout.branch,
60
checkout, control=tree.bzrdir))
62
def test_describe_repository_layout(self):
63
repository = self.make_repository('.', shared=True)
64
tree = controldir.ControlDir.create_branch_convenience('tree',
65
force_new_tree=True).bzrdir.open_workingtree()
66
self.assertEqual('Shared repository with trees and colocated branches',
67
info.describe_layout(tree.branch.repository, control=tree.bzrdir))
68
repository.set_make_working_trees(False)
69
self.assertEqual('Shared repository with colocated branches',
70
info.describe_layout(tree.branch.repository, control=tree.bzrdir))
71
self.assertEqual('Repository branch',
72
info.describe_layout(tree.branch.repository, tree.branch,
74
self.assertEqual('Repository branchless tree',
75
info.describe_layout(tree.branch.repository, None, tree,
77
self.assertEqual('Repository tree',
78
info.describe_layout(tree.branch.repository, tree.branch, tree,
80
tree.branch.bind(tree.branch)
81
self.assertEqual('Repository checkout',
82
info.describe_layout(tree.branch.repository, tree.branch, tree,
84
checkout = tree.branch.create_checkout('checkout', lightweight=True)
85
self.assertEqual('Lightweight checkout',
86
info.describe_layout(checkout.branch.repository, checkout.branch,
87
checkout, control=tree.bzrdir))
89
def assertTreeDescription(self, format):
90
"""Assert a tree's format description matches expectations"""
91
self.make_branch_and_tree('%s_tree' % format, format=format)
92
tree = workingtree.WorkingTree.open('%s_tree' % format)
93
self.assertEqual(format, info.describe_format(tree.bzrdir,
94
tree.branch.repository, tree.branch, tree))
96
def assertCheckoutDescription(self, format, expected=None):
97
"""Assert a checkout's format description matches expectations"""
100
branch = self.make_branch('%s_cobranch' % format, format=format)
101
# this ought to be easier...
102
branch.create_checkout('%s_co' % format,
103
lightweight=True).bzrdir.destroy_workingtree()
104
control = controldir.ControlDir.open('%s_co' % format)
105
old_format = control._format.workingtree_format
107
control._format.workingtree_format = \
108
controldir.format_registry.make_bzrdir(format).workingtree_format
109
control.create_workingtree()
110
tree = workingtree.WorkingTree.open('%s_co' % format)
111
format_description = info.describe_format(tree.bzrdir,
112
tree.branch.repository, tree.branch, tree)
113
self.assertEqual(expected, format_description,
114
"checkout of format called %r was described as %r" %
115
(expected, format_description))
117
control._format.workingtree_format = old_format
119
def assertBranchDescription(self, format, expected=None):
120
"""Assert branch's format description matches expectations"""
123
self.make_branch('%s_branch' % format, format=format)
124
branch = _mod_branch.Branch.open('%s_branch' % format)
125
self.assertEqual(expected, info.describe_format(branch.bzrdir,
126
branch.repository, branch, None))
128
def assertRepoDescription(self, format, expected=None):
129
"""Assert repository's format description matches expectations"""
132
self.make_repository('%s_repo' % format, format=format)
133
repo = _mod_repository.Repository.open('%s_repo' % format)
134
self.assertEqual(expected, info.describe_format(repo.bzrdir,
137
def test_describe_tree_format(self):
138
for key in controldir.format_registry.keys():
139
if key in controldir.format_registry.aliases():
141
self.assertTreeDescription(key)
143
def test_describe_checkout_format(self):
144
for key in controldir.format_registry.keys():
145
if key in controldir.format_registry.aliases():
146
# Aliases will not describe correctly in the UI because the
147
# real format is found.
149
# legacy: weave does not support checkouts
152
if controldir.format_registry.get_info(key).experimental:
153
# We don't require that experimental formats support checkouts
154
# or describe correctly in the UI.
156
if controldir.format_registry.get_info(key).hidden:
159
if key in ('pack-0.92',):
160
expected = 'pack-0.92'
161
elif key in ('knit', 'metaweave'):
162
if 'metaweave' in controldir.format_registry:
163
expected = 'knit or metaweave'
166
elif key in ('1.14', '1.14-rich-root'):
167
expected = '1.14 or 1.14-rich-root'
168
self.assertCheckoutDescription(key, expected)
170
def test_describe_branch_format(self):
171
for key in controldir.format_registry.keys():
172
if key in controldir.format_registry.aliases():
174
if controldir.format_registry.get_info(key).hidden:
177
if key in ('dirstate', 'knit'):
178
expected = 'dirstate or knit'
179
elif key in ('1.14',):
181
elif key in ('1.14-rich-root',):
182
expected = '1.14-rich-root'
183
self.assertBranchDescription(key, expected)
185
def test_describe_repo_format(self):
186
for key in controldir.format_registry.keys():
187
if key in controldir.format_registry.aliases():
189
if controldir.format_registry.get_info(key).hidden:
192
if key in ('dirstate', 'knit', 'dirstate-tags'):
193
expected = 'dirstate or dirstate-tags or knit'
194
elif key in ('1.14',):
196
elif key in ('1.14-rich-root',):
197
expected = '1.14-rich-root'
198
self.assertRepoDescription(key, expected)
200
format = controldir.format_registry.make_bzrdir('knit')
201
format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
202
tree = self.make_branch_and_tree('unknown', format=format)
203
self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
204
tree.branch.repository, tree.branch, tree))
206
def test_gather_location_controldir_only(self):
207
bzrdir = self.make_bzrdir('.')
208
self.assertEqual([('control directory', bzrdir.user_url)],
209
info.gather_location_info(control=bzrdir))
211
def test_gather_location_standalone(self):
212
tree = self.make_branch_and_tree('tree')
213
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
214
info.gather_location_info(
215
tree.branch.repository, tree.branch, tree, control=tree.bzrdir))
216
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
217
info.gather_location_info(
218
tree.branch.repository, tree.branch, control=tree.bzrdir))
221
def test_gather_location_repo(self):
222
srepo = self.make_repository('shared', shared=True)
224
[('shared repository', srepo.bzrdir.root_transport.base)],
225
info.gather_location_info(srepo, control=srepo.bzrdir))
226
urepo = self.make_repository('unshared')
228
[('repository', urepo.bzrdir.root_transport.base)],
229
info.gather_location_info(urepo, control=urepo.bzrdir))
231
def test_gather_location_repo_branch(self):
232
srepo = self.make_repository('shared', shared=True)
234
[('shared repository', srepo.bzrdir.root_transport.base)],
235
info.gather_location_info(srepo, control=srepo.bzrdir))
236
tree = self.make_branch_and_tree('shared/tree')
238
[('shared repository', srepo.bzrdir.root_transport.base),
239
('repository branch', tree.branch.base)],
240
info.gather_location_info(srepo, tree.branch, tree, srepo.bzrdir))
242
def test_gather_location_light_checkout(self):
243
tree = self.make_branch_and_tree('tree')
244
lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
246
[('light checkout root', lcheckout.bzrdir.root_transport.base),
247
('checkout of branch', tree.bzrdir.root_transport.base)],
248
self.gather_tree_location_info(lcheckout))
250
def test_gather_location_heavy_checkout(self):
251
tree = self.make_branch_and_tree('tree')
252
checkout = tree.branch.create_checkout('checkout')
254
[('checkout root', checkout.bzrdir.root_transport.base),
255
('checkout of branch', tree.bzrdir.root_transport.base)],
256
self.gather_tree_location_info(checkout))
257
light_checkout = checkout.branch.create_checkout('light_checkout',
260
[('light checkout root',
261
light_checkout.bzrdir.root_transport.base),
262
('checkout root', checkout.bzrdir.root_transport.base),
263
('checkout of branch', tree.bzrdir.root_transport.base)],
264
self.gather_tree_location_info(light_checkout)
267
def test_gather_location_shared_repo_checkout(self):
268
tree = self.make_branch_and_tree('tree')
269
srepo = self.make_repository('shared', shared=True)
270
shared_checkout = tree.branch.create_checkout('shared/checkout')
272
[('repository checkout root',
273
shared_checkout.bzrdir.root_transport.base),
274
('checkout of branch', tree.bzrdir.root_transport.base),
275
('shared repository', srepo.bzrdir.root_transport.base)],
276
self.gather_tree_location_info(shared_checkout))
278
def gather_tree_location_info(self, tree):
279
return info.gather_location_info(
280
tree.branch.repository, tree.branch, tree, tree.bzrdir)
282
def test_gather_location_bound(self):
283
branch = self.make_branch('branch')
284
bound_branch = self.make_branch('bound_branch')
285
bound_branch.bind(branch)
287
[('branch root', bound_branch.bzrdir.root_transport.base),
288
('bound to branch', branch.bzrdir.root_transport.base)],
289
info.gather_location_info(
290
bound_branch.repository, bound_branch, control=bound_branch.bzrdir)
293
def test_gather_location_bound_in_repository(self):
294
repo = self.make_repository('repo', shared=True)
295
repo.set_make_working_trees(False)
296
branch = self.make_branch('branch')
297
bound_branch = controldir.ControlDir.create_branch_convenience(
299
bound_branch.bind(branch)
301
[('shared repository', bound_branch.repository.bzrdir.user_url),
302
('repository branch', bound_branch.bzrdir.user_url),
303
('bound to branch', branch.bzrdir.user_url)],
304
info.gather_location_info(bound_branch.repository, bound_branch)
307
def test_location_list(self):
308
if sys.platform == 'win32':
309
raise tests.TestSkipped('Windows-unfriendly test')
310
locs = info.LocationList('/home/foo')
311
locs.add_url('a', 'file:///home/foo/')
312
locs.add_url('b', 'file:///home/foo/bar/')
313
locs.add_url('c', 'file:///home/bar/bar')
314
locs.add_url('d', 'http://example.com/example/')
315
locs.add_url('e', None)
316
self.assertEqual(locs.locs, [('a', '.'),
318
('c', '/home/bar/bar'),
319
('d', 'http://example.com/example/')])
320
self.assertEqualDiff(' a: .\n b: bar\n c: /home/bar/bar\n'
321
' d: http://example.com/example/\n',
322
''.join(locs.get_lines()))
324
def test_gather_related_braches(self):
325
branch = self.make_branch('.')
328
branch.set_public_branch('baz')
329
branch.set_push_location('bar')
330
branch.set_parent('foo')
331
branch.set_submit_branch('qux')
335
[('public branch', 'baz'), ('push branch', 'bar'),
336
('parent branch', 'foo'), ('submit branch', 'qux')],
337
info._gather_related_branches(branch).locs)