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,
26
repository as _mod_repository,
29
branch as _mod_bzrbranch,
33
class TestInfo(tests.TestCaseWithTransport):
35
def test_describe_standalone_layout(self):
36
tree = self.make_branch_and_tree('tree')
37
self.assertEqual('Empty control directory', info.describe_layout())
39
'Unshared repository with trees and colocated branches',
40
info.describe_layout(tree.branch.repository, control=tree.controldir))
41
tree.branch.repository.set_make_working_trees(False)
42
self.assertEqual('Unshared repository with colocated branches',
43
info.describe_layout(tree.branch.repository, control=tree.controldir))
44
self.assertEqual('Standalone branch',
45
info.describe_layout(tree.branch.repository, tree.branch,
46
control=tree.controldir))
47
self.assertEqual('Standalone branchless tree',
48
info.describe_layout(tree.branch.repository, None, tree,
49
control=tree.controldir))
50
self.assertEqual('Standalone tree',
51
info.describe_layout(tree.branch.repository, tree.branch, tree,
52
control=tree.controldir))
53
tree.branch.bind(tree.branch)
54
self.assertEqual('Bound branch',
55
info.describe_layout(tree.branch.repository, tree.branch,
56
control=tree.controldir))
57
self.assertEqual('Checkout',
58
info.describe_layout(tree.branch.repository, tree.branch, tree,
59
control=tree.controldir))
60
checkout = tree.branch.create_checkout('checkout', lightweight=True)
61
self.assertEqual('Lightweight checkout',
62
info.describe_layout(checkout.branch.repository, checkout.branch,
63
checkout, control=tree.controldir))
65
def test_describe_repository_layout(self):
66
repository = self.make_repository('.', shared=True)
67
tree = controldir.ControlDir.create_branch_convenience('tree',
68
force_new_tree=True).controldir.open_workingtree()
69
self.assertEqual('Shared repository with trees and colocated branches',
70
info.describe_layout(tree.branch.repository, control=tree.controldir))
71
repository.set_make_working_trees(False)
72
self.assertEqual('Shared repository with colocated branches',
73
info.describe_layout(tree.branch.repository, control=tree.controldir))
74
self.assertEqual('Repository branch',
75
info.describe_layout(tree.branch.repository, tree.branch,
76
control=tree.controldir))
77
self.assertEqual('Repository branchless tree',
78
info.describe_layout(tree.branch.repository, None, tree,
79
control=tree.controldir))
80
self.assertEqual('Repository tree',
81
info.describe_layout(tree.branch.repository, tree.branch, tree,
82
control=tree.controldir))
83
tree.branch.bind(tree.branch)
84
self.assertEqual('Repository checkout',
85
info.describe_layout(tree.branch.repository, tree.branch, tree,
86
control=tree.controldir))
87
checkout = tree.branch.create_checkout('checkout', lightweight=True)
88
self.assertEqual('Lightweight checkout',
89
info.describe_layout(checkout.branch.repository, checkout.branch,
90
checkout, control=tree.controldir))
92
def assertTreeDescription(self, format):
93
"""Assert a tree's format description matches expectations"""
94
self.make_branch_and_tree('%s_tree' % format, format=format)
95
tree = workingtree.WorkingTree.open('%s_tree' % format)
96
self.assertEqual(format, info.describe_format(tree.controldir,
97
tree.branch.repository, tree.branch, tree))
99
def assertCheckoutDescription(self, format, expected=None):
100
"""Assert a checkout's format description matches expectations"""
103
branch = self.make_branch('%s_cobranch' % format, format=format)
104
# this ought to be easier...
105
branch.create_checkout('%s_co' % format,
106
lightweight=True).controldir.destroy_workingtree()
107
control = controldir.ControlDir.open('%s_co' % format)
108
old_format = control._format.workingtree_format
110
control._format.workingtree_format = \
111
controldir.format_registry.make_controldir(
112
format).workingtree_format
113
control.create_workingtree()
114
tree = workingtree.WorkingTree.open('%s_co' % format)
115
format_description = info.describe_format(tree.controldir,
116
tree.branch.repository, tree.branch, tree)
117
self.assertEqual(expected, format_description,
118
"checkout of format called %r was described as %r" %
119
(expected, format_description))
121
control._format.workingtree_format = old_format
123
def assertBranchDescription(self, format, expected=None):
124
"""Assert branch's format description matches expectations"""
127
self.make_branch('%s_branch' % format, format=format)
128
branch = _mod_branch.Branch.open('%s_branch' % format)
129
self.assertEqual(expected, info.describe_format(branch.controldir,
130
branch.repository, branch, None))
132
def assertRepoDescription(self, format, expected=None):
133
"""Assert repository's format description matches expectations"""
136
self.make_repository('%s_repo' % format, format=format)
137
repo = _mod_repository.Repository.open('%s_repo' % format)
138
self.assertEqual(expected, info.describe_format(repo.controldir,
141
def test_describe_tree_format(self):
142
for key, format in controldir.format_registry.iteritems():
143
if key in controldir.format_registry.aliases():
145
if not format().supports_workingtrees:
147
self.assertTreeDescription(key)
149
def test_describe_checkout_format(self):
150
for key in controldir.format_registry.keys():
151
if key in controldir.format_registry.aliases():
152
# Aliases will not describe correctly in the UI because the
153
# real format is found.
155
# legacy: weave does not support checkouts
158
# foreign: git checkouts can actually be bzr controldirs
159
if key in ('git', 'git-bare'):
161
if controldir.format_registry.get_info(key).experimental:
162
# We don't require that experimental formats support checkouts
163
# or describe correctly in the UI.
165
if controldir.format_registry.get_info(key).hidden:
168
if key in ('pack-0.92',):
169
expected = 'pack-0.92'
170
elif key in ('knit', 'metaweave'):
171
if 'metaweave' in controldir.format_registry:
172
expected = 'knit or metaweave'
175
elif key in ('1.14', '1.14-rich-root'):
176
expected = '1.14 or 1.14-rich-root'
177
self.assertCheckoutDescription(key, expected)
179
def test_describe_branch_format(self):
180
for key in controldir.format_registry.keys():
181
if key in controldir.format_registry.aliases():
183
if controldir.format_registry.get_info(key).hidden:
186
if key in ('dirstate', 'knit'):
187
expected = 'dirstate or knit'
188
elif key in ('1.14',):
190
elif key in ('1.14-rich-root',):
191
expected = '1.14-rich-root'
192
self.assertBranchDescription(key, expected)
194
def test_describe_repo_format(self):
195
for key in controldir.format_registry.keys():
196
if key in controldir.format_registry.aliases():
198
if controldir.format_registry.get_info(key).hidden:
201
if key in ('dirstate', 'knit', 'dirstate-tags'):
202
expected = 'dirstate or dirstate-tags or knit'
203
elif key in ('1.14',):
205
elif key in ('1.14-rich-root',):
206
expected = '1.14-rich-root'
207
self.assertRepoDescription(key, expected)
209
format = controldir.format_registry.make_controldir('knit')
210
format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
211
tree = self.make_branch_and_tree('unknown', format=format)
212
self.assertEqual('unnamed', info.describe_format(tree.controldir,
213
tree.branch.repository, tree.branch, tree))
215
def test_gather_location_controldir_only(self):
216
bzrdir = self.make_controldir('.')
217
self.assertEqual([('control directory', bzrdir.user_url)],
218
info.gather_location_info(control=bzrdir))
220
def test_gather_location_standalone(self):
221
tree = self.make_branch_and_tree('tree')
222
self.assertEqual([('branch root', tree.controldir.root_transport.base)],
223
info.gather_location_info(
224
tree.branch.repository, tree.branch, tree, control=tree.controldir))
225
self.assertEqual([('branch root', tree.controldir.root_transport.base)],
226
info.gather_location_info(
227
tree.branch.repository, tree.branch, control=tree.controldir))
230
def test_gather_location_repo(self):
231
srepo = self.make_repository('shared', shared=True)
233
[('shared repository', srepo.controldir.root_transport.base)],
234
info.gather_location_info(srepo, control=srepo.controldir))
235
urepo = self.make_repository('unshared')
237
[('repository', urepo.controldir.root_transport.base)],
238
info.gather_location_info(urepo, control=urepo.controldir))
240
def test_gather_location_repo_branch(self):
241
srepo = self.make_repository('shared', shared=True)
243
[('shared repository', srepo.controldir.root_transport.base)],
244
info.gather_location_info(srepo, control=srepo.controldir))
245
tree = self.make_branch_and_tree('shared/tree')
247
[('shared repository', srepo.controldir.root_transport.base),
248
('repository branch', tree.branch.base)],
249
info.gather_location_info(srepo, tree.branch, tree, srepo.controldir))
251
def test_gather_location_light_checkout(self):
252
tree = self.make_branch_and_tree('tree')
253
lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
255
[('light checkout root', lcheckout.controldir.root_transport.base),
256
('checkout of branch', tree.controldir.root_transport.base)],
257
self.gather_tree_location_info(lcheckout))
259
def test_gather_location_heavy_checkout(self):
260
tree = self.make_branch_and_tree('tree')
261
checkout = tree.branch.create_checkout('checkout')
263
[('checkout root', checkout.controldir.root_transport.base),
264
('checkout of branch', tree.controldir.root_transport.base)],
265
self.gather_tree_location_info(checkout))
266
light_checkout = checkout.branch.create_checkout('light_checkout',
269
[('light checkout root',
270
light_checkout.controldir.root_transport.base),
271
('checkout root', checkout.controldir.root_transport.base),
272
('checkout of branch', tree.controldir.root_transport.base)],
273
self.gather_tree_location_info(light_checkout)
276
def test_gather_location_shared_repo_checkout(self):
277
tree = self.make_branch_and_tree('tree')
278
srepo = self.make_repository('shared', shared=True)
279
shared_checkout = tree.branch.create_checkout('shared/checkout')
281
[('repository checkout root',
282
shared_checkout.controldir.root_transport.base),
283
('checkout of branch', tree.controldir.root_transport.base),
284
('shared repository', srepo.controldir.root_transport.base)],
285
self.gather_tree_location_info(shared_checkout))
287
def gather_tree_location_info(self, tree):
288
return info.gather_location_info(
289
tree.branch.repository, tree.branch, tree, tree.controldir)
291
def test_gather_location_bound(self):
292
branch = self.make_branch('branch')
293
bound_branch = self.make_branch('bound_branch')
294
bound_branch.bind(branch)
296
[('branch root', bound_branch.controldir.root_transport.base),
297
('bound to branch', branch.controldir.root_transport.base)],
298
info.gather_location_info(
299
bound_branch.repository, bound_branch, control=bound_branch.controldir)
302
def test_gather_location_bound_in_repository(self):
303
repo = self.make_repository('repo', shared=True)
304
repo.set_make_working_trees(False)
305
branch = self.make_branch('branch')
306
bound_branch = controldir.ControlDir.create_branch_convenience(
308
bound_branch.bind(branch)
310
[('shared repository', bound_branch.repository.controldir.user_url),
311
('repository branch', bound_branch.controldir.user_url),
312
('bound to branch', branch.controldir.user_url)],
313
info.gather_location_info(bound_branch.repository, bound_branch)
316
def test_location_list(self):
317
if sys.platform == 'win32':
318
raise tests.TestSkipped('Windows-unfriendly test')
319
locs = info.LocationList('/home/foo')
320
locs.add_url('a', 'file:///home/foo/')
321
locs.add_url('b', 'file:///home/foo/bar/')
322
locs.add_url('c', 'file:///home/bar/bar')
323
locs.add_url('d', 'http://example.com/example/')
324
locs.add_url('e', None)
325
self.assertEqual(locs.locs, [('a', '.'),
327
('c', '/home/bar/bar'),
328
('d', 'http://example.com/example/')])
329
self.assertEqualDiff(' a: .\n b: bar\n c: /home/bar/bar\n'
330
' d: http://example.com/example/\n',
331
''.join(locs.get_lines()))
333
def test_gather_related_braches(self):
334
branch = self.make_branch('.')
337
branch.set_public_branch('baz')
338
branch.set_push_location('bar')
339
branch.set_parent('foo')
340
branch.set_submit_branch('qux')
344
[('public branch', 'baz'), ('push branch', 'bar'),
345
('parent branch', 'foo'), ('submit branch', 'qux')],
346
info._gather_related_branches(branch).locs)