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,
25
repository as _mod_repository,
28
branch as _mod_bzrbranch,
32
class TestInfo(tests.TestCaseWithTransport):
34
def test_describe_standalone_layout(self):
35
tree = self.make_branch_and_tree('tree')
36
self.assertEqual('Empty control directory', info.describe_layout())
38
'Unshared repository with trees and colocated branches',
39
info.describe_layout(tree.branch.repository, control=tree.controldir))
40
tree.branch.repository.set_make_working_trees(False)
41
self.assertEqual('Unshared repository with colocated branches',
42
info.describe_layout(tree.branch.repository, control=tree.controldir))
43
self.assertEqual('Standalone branch',
44
info.describe_layout(tree.branch.repository, tree.branch,
45
control=tree.controldir))
46
self.assertEqual('Standalone branchless tree',
47
info.describe_layout(tree.branch.repository, None, tree,
48
control=tree.controldir))
49
self.assertEqual('Standalone tree',
50
info.describe_layout(tree.branch.repository, tree.branch, tree,
51
control=tree.controldir))
52
tree.branch.bind(tree.branch)
53
self.assertEqual('Bound branch',
54
info.describe_layout(tree.branch.repository, tree.branch,
55
control=tree.controldir))
56
self.assertEqual('Checkout',
57
info.describe_layout(tree.branch.repository, tree.branch, tree,
58
control=tree.controldir))
59
checkout = tree.branch.create_checkout('checkout', lightweight=True)
60
self.assertEqual('Lightweight checkout',
61
info.describe_layout(checkout.branch.repository, checkout.branch,
62
checkout, control=tree.controldir))
64
def test_describe_repository_layout(self):
65
repository = self.make_repository('.', shared=True)
66
tree = controldir.ControlDir.create_branch_convenience('tree',
67
force_new_tree=True).controldir.open_workingtree()
68
self.assertEqual('Shared repository with trees and colocated branches',
69
info.describe_layout(tree.branch.repository, control=tree.controldir))
70
repository.set_make_working_trees(False)
71
self.assertEqual('Shared repository with colocated branches',
72
info.describe_layout(tree.branch.repository, control=tree.controldir))
73
self.assertEqual('Repository branch',
74
info.describe_layout(tree.branch.repository, tree.branch,
75
control=tree.controldir))
76
self.assertEqual('Repository branchless tree',
77
info.describe_layout(tree.branch.repository, None, tree,
78
control=tree.controldir))
79
self.assertEqual('Repository tree',
80
info.describe_layout(tree.branch.repository, tree.branch, tree,
81
control=tree.controldir))
82
tree.branch.bind(tree.branch)
83
self.assertEqual('Repository checkout',
84
info.describe_layout(tree.branch.repository, tree.branch, tree,
85
control=tree.controldir))
86
checkout = tree.branch.create_checkout('checkout', lightweight=True)
87
self.assertEqual('Lightweight checkout',
88
info.describe_layout(checkout.branch.repository, checkout.branch,
89
checkout, control=tree.controldir))
91
def assertTreeDescription(self, format):
92
"""Assert a tree's format description matches expectations"""
93
self.make_branch_and_tree('%s_tree' % format, format=format)
94
tree = workingtree.WorkingTree.open('%s_tree' % format)
95
self.assertEqual(format, info.describe_format(tree.controldir,
96
tree.branch.repository, tree.branch, tree))
98
def assertCheckoutDescription(self, format, expected=None):
99
"""Assert a checkout's format description matches expectations"""
102
branch = self.make_branch('%s_cobranch' % format, format=format)
103
# this ought to be easier...
104
branch.create_checkout('%s_co' % format,
105
lightweight=True).controldir.destroy_workingtree()
106
control = controldir.ControlDir.open('%s_co' % format)
107
old_format = control._format.workingtree_format
109
control._format.workingtree_format = \
110
controldir.format_registry.make_controldir(format).workingtree_format
111
control.create_workingtree()
112
tree = workingtree.WorkingTree.open('%s_co' % format)
113
format_description = info.describe_format(tree.controldir,
114
tree.branch.repository, tree.branch, tree)
115
self.assertEqual(expected, format_description,
116
"checkout of format called %r was described as %r" %
117
(expected, format_description))
119
control._format.workingtree_format = old_format
121
def assertBranchDescription(self, format, expected=None):
122
"""Assert branch's format description matches expectations"""
125
self.make_branch('%s_branch' % format, format=format)
126
branch = _mod_branch.Branch.open('%s_branch' % format)
127
self.assertEqual(expected, info.describe_format(branch.controldir,
128
branch.repository, branch, None))
130
def assertRepoDescription(self, format, expected=None):
131
"""Assert repository's format description matches expectations"""
134
self.make_repository('%s_repo' % format, format=format)
135
repo = _mod_repository.Repository.open('%s_repo' % format)
136
self.assertEqual(expected, info.describe_format(repo.controldir,
139
def test_describe_tree_format(self):
140
for key in controldir.format_registry.keys():
141
if key in controldir.format_registry.aliases():
143
self.assertTreeDescription(key)
145
def test_describe_checkout_format(self):
146
for key in controldir.format_registry.keys():
147
if key in controldir.format_registry.aliases():
148
# Aliases will not describe correctly in the UI because the
149
# real format is found.
151
# legacy: weave does not support checkouts
154
if controldir.format_registry.get_info(key).experimental:
155
# We don't require that experimental formats support checkouts
156
# or describe correctly in the UI.
158
if controldir.format_registry.get_info(key).hidden:
161
if key in ('pack-0.92',):
162
expected = 'pack-0.92'
163
elif key in ('knit', 'metaweave'):
164
if 'metaweave' in controldir.format_registry:
165
expected = 'knit or metaweave'
168
elif key in ('1.14', '1.14-rich-root'):
169
expected = '1.14 or 1.14-rich-root'
170
self.assertCheckoutDescription(key, expected)
172
def test_describe_branch_format(self):
173
for key in controldir.format_registry.keys():
174
if key in controldir.format_registry.aliases():
176
if controldir.format_registry.get_info(key).hidden:
179
if key in ('dirstate', 'knit'):
180
expected = 'dirstate or knit'
181
elif key in ('1.14',):
183
elif key in ('1.14-rich-root',):
184
expected = '1.14-rich-root'
185
self.assertBranchDescription(key, expected)
187
def test_describe_repo_format(self):
188
for key in controldir.format_registry.keys():
189
if key in controldir.format_registry.aliases():
191
if controldir.format_registry.get_info(key).hidden:
194
if key in ('dirstate', 'knit', 'dirstate-tags'):
195
expected = 'dirstate or dirstate-tags or knit'
196
elif key in ('1.14',):
198
elif key in ('1.14-rich-root',):
199
expected = '1.14-rich-root'
200
self.assertRepoDescription(key, expected)
202
format = controldir.format_registry.make_controldir('knit')
203
format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
204
tree = self.make_branch_and_tree('unknown', format=format)
205
self.assertEqual('unnamed', info.describe_format(tree.controldir,
206
tree.branch.repository, tree.branch, tree))
208
def test_gather_location_controldir_only(self):
209
bzrdir = self.make_controldir('.')
210
self.assertEqual([('control directory', bzrdir.user_url)],
211
info.gather_location_info(control=bzrdir))
213
def test_gather_location_standalone(self):
214
tree = self.make_branch_and_tree('tree')
215
self.assertEqual([('branch root', tree.controldir.root_transport.base)],
216
info.gather_location_info(
217
tree.branch.repository, tree.branch, tree, control=tree.controldir))
218
self.assertEqual([('branch root', tree.controldir.root_transport.base)],
219
info.gather_location_info(
220
tree.branch.repository, tree.branch, control=tree.controldir))
223
def test_gather_location_repo(self):
224
srepo = self.make_repository('shared', shared=True)
226
[('shared repository', srepo.controldir.root_transport.base)],
227
info.gather_location_info(srepo, control=srepo.controldir))
228
urepo = self.make_repository('unshared')
230
[('repository', urepo.controldir.root_transport.base)],
231
info.gather_location_info(urepo, control=urepo.controldir))
233
def test_gather_location_repo_branch(self):
234
srepo = self.make_repository('shared', shared=True)
236
[('shared repository', srepo.controldir.root_transport.base)],
237
info.gather_location_info(srepo, control=srepo.controldir))
238
tree = self.make_branch_and_tree('shared/tree')
240
[('shared repository', srepo.controldir.root_transport.base),
241
('repository branch', tree.branch.base)],
242
info.gather_location_info(srepo, tree.branch, tree, srepo.controldir))
244
def test_gather_location_light_checkout(self):
245
tree = self.make_branch_and_tree('tree')
246
lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
248
[('light checkout root', lcheckout.controldir.root_transport.base),
249
('checkout of branch', tree.controldir.root_transport.base)],
250
self.gather_tree_location_info(lcheckout))
252
def test_gather_location_heavy_checkout(self):
253
tree = self.make_branch_and_tree('tree')
254
checkout = tree.branch.create_checkout('checkout')
256
[('checkout root', checkout.controldir.root_transport.base),
257
('checkout of branch', tree.controldir.root_transport.base)],
258
self.gather_tree_location_info(checkout))
259
light_checkout = checkout.branch.create_checkout('light_checkout',
262
[('light checkout root',
263
light_checkout.controldir.root_transport.base),
264
('checkout root', checkout.controldir.root_transport.base),
265
('checkout of branch', tree.controldir.root_transport.base)],
266
self.gather_tree_location_info(light_checkout)
269
def test_gather_location_shared_repo_checkout(self):
270
tree = self.make_branch_and_tree('tree')
271
srepo = self.make_repository('shared', shared=True)
272
shared_checkout = tree.branch.create_checkout('shared/checkout')
274
[('repository checkout root',
275
shared_checkout.controldir.root_transport.base),
276
('checkout of branch', tree.controldir.root_transport.base),
277
('shared repository', srepo.controldir.root_transport.base)],
278
self.gather_tree_location_info(shared_checkout))
280
def gather_tree_location_info(self, tree):
281
return info.gather_location_info(
282
tree.branch.repository, tree.branch, tree, tree.controldir)
284
def test_gather_location_bound(self):
285
branch = self.make_branch('branch')
286
bound_branch = self.make_branch('bound_branch')
287
bound_branch.bind(branch)
289
[('branch root', bound_branch.controldir.root_transport.base),
290
('bound to branch', branch.controldir.root_transport.base)],
291
info.gather_location_info(
292
bound_branch.repository, bound_branch, control=bound_branch.controldir)
295
def test_gather_location_bound_in_repository(self):
296
repo = self.make_repository('repo', shared=True)
297
repo.set_make_working_trees(False)
298
branch = self.make_branch('branch')
299
bound_branch = controldir.ControlDir.create_branch_convenience(
301
bound_branch.bind(branch)
303
[('shared repository', bound_branch.repository.controldir.user_url),
304
('repository branch', bound_branch.controldir.user_url),
305
('bound to branch', branch.controldir.user_url)],
306
info.gather_location_info(bound_branch.repository, bound_branch)
309
def test_location_list(self):
310
if sys.platform == 'win32':
311
raise tests.TestSkipped('Windows-unfriendly test')
312
locs = info.LocationList('/home/foo')
313
locs.add_url('a', 'file:///home/foo/')
314
locs.add_url('b', 'file:///home/foo/bar/')
315
locs.add_url('c', 'file:///home/bar/bar')
316
locs.add_url('d', 'http://example.com/example/')
317
locs.add_url('e', None)
318
self.assertEqual(locs.locs, [('a', '.'),
320
('c', '/home/bar/bar'),
321
('d', 'http://example.com/example/')])
322
self.assertEqualDiff(' a: .\n b: bar\n c: /home/bar/bar\n'
323
' d: http://example.com/example/\n',
324
''.join(locs.get_lines()))
326
def test_gather_related_braches(self):
327
branch = self.make_branch('.')
330
branch.set_public_branch('baz')
331
branch.set_push_location('bar')
332
branch.set_parent('foo')
333
branch.set_submit_branch('qux')
337
[('public branch', 'baz'), ('push branch', 'bar'),
338
('parent branch', 'foo'), ('submit branch', 'qux')],
339
info._gather_related_branches(branch).locs)