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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
branch as _mod_branch,
28
class TestReconfigure(tests.TestCaseWithTransport):
30
def test_tree_to_branch(self):
31
tree = self.make_branch_and_tree('tree')
32
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
33
reconfiguration.apply()
34
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
37
def test_modified_tree_to_branch(self):
38
tree = self.make_branch_and_tree('tree')
39
self.build_tree(['tree/file'])
41
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
42
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
43
reconfiguration.apply(force=True)
44
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
47
def test_branch_to_branch(self):
48
branch = self.make_branch('branch')
49
self.assertRaises(errors.AlreadyBranch,
50
reconfigure.Reconfigure.to_branch, branch.bzrdir)
52
def test_repo_to_branch(self):
53
repo = self.make_repository('repo')
54
reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
55
reconfiguration.apply()
57
def test_checkout_to_branch(self):
58
branch = self.make_branch('branch')
59
checkout = branch.create_checkout('checkout')
60
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
61
reconfiguration.apply()
62
self.assertIs(None, checkout.branch.get_bound_location())
64
def prepare_lightweight_checkout_to_branch(self):
65
branch = self.make_branch('branch')
66
checkout = branch.create_checkout('checkout', lightweight=True)
67
checkout.commit('first commit', rev_id='rev1')
68
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
69
return reconfiguration, checkout
71
def test_lightweight_checkout_to_branch(self):
72
reconfiguration, checkout = \
73
self.prepare_lightweight_checkout_to_branch()
74
reconfiguration.apply()
75
checkout_branch = checkout.bzrdir.open_branch()
76
self.assertEqual(checkout_branch.bzrdir.root_transport.base,
77
checkout.bzrdir.root_transport.base)
78
self.assertEqual('rev1', checkout_branch.last_revision())
79
repo = checkout.bzrdir.open_repository()
80
repo.get_revision('rev1')
82
def test_lightweight_checkout_to_branch_tags(self):
83
reconfiguration, checkout = \
84
self.prepare_lightweight_checkout_to_branch()
85
checkout.branch.tags.set_tag('foo', 'bar')
86
reconfiguration.apply()
87
checkout_branch = checkout.bzrdir.open_branch()
88
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
90
def prepare_lightweight_checkout_to_checkout(self):
91
branch = self.make_branch('branch')
92
checkout = branch.create_checkout('checkout', lightweight=True)
93
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
94
return reconfiguration, checkout
96
def test_lightweight_checkout_to_checkout(self):
97
reconfiguration, checkout = \
98
self.prepare_lightweight_checkout_to_checkout()
99
reconfiguration.apply()
100
checkout_branch = checkout.bzrdir.open_branch()
101
self.assertIsNot(checkout_branch.get_bound_location(), None)
103
def test_lightweight_checkout_to_checkout_tags(self):
104
reconfiguration, checkout = \
105
self.prepare_lightweight_checkout_to_checkout()
106
checkout.branch.tags.set_tag('foo', 'bar')
107
reconfiguration.apply()
108
checkout_branch = checkout.bzrdir.open_branch()
109
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
111
def test_lightweight_conversion_uses_shared_repo(self):
112
parent = self.make_branch('parent')
113
shared_repo = self.make_repository('repo', shared=True)
114
checkout = parent.create_checkout('repo/checkout', lightweight=True)
115
reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
116
checkout_repo = checkout.bzrdir.open_branch().repository
117
self.assertEqual(shared_repo.bzrdir.root_transport.base,
118
checkout_repo.bzrdir.root_transport.base)
120
def test_branch_to_tree(self):
121
branch = self.make_branch('branch')
122
reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
123
reconfiguration.apply()
124
branch.bzrdir.open_workingtree()
126
def test_tree_to_tree(self):
127
tree = self.make_branch_and_tree('tree')
128
self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
131
def test_select_bind_location(self):
132
branch = self.make_branch('branch')
133
reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
134
self.assertRaises(errors.NoBindLocation,
135
reconfiguration._select_bind_location)
136
branch.set_parent('http://parent')
137
self.assertEqual('http://parent',
138
reconfiguration._select_bind_location())
139
branch.set_push_location('sftp://push')
140
self.assertEqual('sftp://push',
141
reconfiguration._select_bind_location())
142
branch.set_bound_location('bzr://foo/old-bound')
143
branch.set_bound_location(None)
144
self.assertEqual('bzr://foo/old-bound',
145
reconfiguration._select_bind_location())
146
branch.set_bound_location('bzr://foo/cur-bound')
147
self.assertEqual('bzr://foo/cur-bound',
148
reconfiguration._select_bind_location())
149
reconfiguration.new_bound_location = 'ftp://user-specified'
150
self.assertEqual('ftp://user-specified',
151
reconfiguration._select_bind_location())
153
def test_select_reference_bind_location(self):
154
branch = self.make_branch('branch')
155
checkout = branch.create_checkout('checkout', lightweight=True)
156
reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
157
self.assertEqual(branch.base,
158
reconfiguration._select_bind_location())
160
def test_tree_to_checkout(self):
161
# A tree with no related branches and no supplied bind location cannot
163
parent = self.make_branch('parent')
165
tree = self.make_branch_and_tree('tree')
166
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
167
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
168
# setting a parent allows it to become a checkout
169
tree.branch.set_parent(parent.base)
170
reconfiguration.apply()
171
# supplying a location allows it to become a checkout
172
tree2 = self.make_branch_and_tree('tree2')
173
reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
175
reconfiguration.apply()
177
def test_tree_to_lightweight_checkout(self):
178
# A tree with no related branches and no supplied bind location cannot
180
parent = self.make_branch('parent')
182
tree = self.make_branch_and_tree('tree')
183
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
185
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
186
# setting a parent allows it to become a checkout
187
tree.branch.set_parent(parent.base)
188
reconfiguration.apply()
189
# supplying a location allows it to become a checkout
190
tree2 = self.make_branch_and_tree('tree2')
191
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
192
tree2.bzrdir, parent.base)
193
reconfiguration.apply()
195
def test_checkout_to_checkout(self):
196
parent = self.make_branch('parent')
197
checkout = parent.create_checkout('checkout')
198
self.assertRaises(errors.AlreadyCheckout,
199
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
201
def make_unsynced_checkout(self):
202
parent = self.make_branch('parent')
203
checkout = parent.create_checkout('checkout')
204
checkout.commit('test', rev_id='new-commit', local=True)
205
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
207
return checkout, parent, reconfiguration
209
def test_unsynced_checkout_to_lightweight(self):
210
checkout, parent, reconfiguration = self.make_unsynced_checkout()
211
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
213
def test_synced_checkout_to_lightweight(self):
214
checkout, parent, reconfiguration = self.make_unsynced_checkout()
215
parent.pull(checkout.branch)
216
reconfiguration.apply()
217
wt = checkout.bzrdir.open_workingtree()
218
self.assertTrue(parent.repository.has_same_location(
219
wt.branch.repository))
220
parent.repository.get_revision('new-commit')
221
self.assertRaises(errors.NoRepositoryPresent,
222
checkout.bzrdir.open_repository)
224
def prepare_branch_to_lightweight_checkout(self):
225
parent = self.make_branch('parent')
226
child = parent.bzrdir.sprout('child').open_workingtree()
227
child.commit('test', rev_id='new-commit')
228
parent.pull(child.branch)
229
child.bzrdir.destroy_workingtree()
230
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
232
return parent, child, reconfiguration
234
def test_branch_to_lightweight_checkout(self):
235
parent, child, reconfiguration = \
236
self.prepare_branch_to_lightweight_checkout()
237
reconfiguration.apply()
238
self.assertTrue(reconfiguration._destroy_branch)
239
wt = child.bzrdir.open_workingtree()
240
self.assertTrue(parent.repository.has_same_location(
241
wt.branch.repository))
242
parent.repository.get_revision('new-commit')
243
self.assertRaises(errors.NoRepositoryPresent,
244
child.bzrdir.open_repository)
246
def test_branch_to_lightweight_checkout_failure(self):
247
parent, child, reconfiguration = \
248
self.prepare_branch_to_lightweight_checkout()
249
old_Repository_fetch = repository.Repository.fetch
250
repository.Repository.fetch = None
252
self.assertRaises(TypeError, reconfiguration.apply)
254
repository.Repository.fetch = old_Repository_fetch
255
child = _mod_branch.Branch.open('child')
256
self.assertContainsRe(child.base, 'child/$')
258
def test_branch_to_lightweight_checkout_fetch_tags(self):
259
parent, child, reconfiguration = \
260
self.prepare_branch_to_lightweight_checkout()
261
child.branch.tags.set_tag('foo', 'bar')
262
reconfiguration.apply()
263
child = _mod_branch.Branch.open('child')
264
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
266
def test_lightweight_checkout_to_lightweight_checkout(self):
267
parent = self.make_branch('parent')
268
checkout = parent.create_checkout('checkout', lightweight=True)
269
self.assertRaises(errors.AlreadyLightweightCheckout,
270
reconfigure.Reconfigure.to_lightweight_checkout,
273
def test_repo_to_tree(self):
274
repo = self.make_repository('repo')
275
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
276
reconfiguration.apply()
277
workingtree.WorkingTree.open('repo')
279
def test_shared_repo_to_lightweight_checkout(self):
280
repo = self.make_repository('repo', shared=True)
281
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
283
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
284
branch = self.make_branch('branch')
285
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
286
repo.bzrdir, 'branch')
287
reconfiguration.apply()
288
workingtree.WorkingTree.open('repo')
289
repository.Repository.open('repo')
291
def test_unshared_repo_to_lightweight_checkout(self):
292
repo = self.make_repository('repo', shared=False)
293
branch = self.make_branch('branch')
294
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
295
repo.bzrdir, 'branch')
296
reconfiguration.apply()
297
workingtree.WorkingTree.open('repo')
298
self.assertRaises(errors.NoRepositoryPresent,
299
repository.Repository.open, 'repo')
301
def test_standalone_to_use_shared(self):
302
self.build_tree(['root/'])
303
tree = self.make_branch_and_tree('root/tree')
304
tree.commit('Hello', rev_id='hello-id')
305
repo = self.make_repository('root', shared=True)
306
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
307
reconfiguration.apply()
308
tree = workingtree.WorkingTree.open('root/tree')
309
self.assertTrue(repo.has_same_location(tree.branch.repository))
310
self.assertEqual('Hello', repo.get_revision('hello-id').message)
312
def add_dead_head(self, tree):
313
revno, revision_id = tree.branch.last_revision_info()
314
tree.commit('Dead head', rev_id='dead-head-id')
315
tree.branch.set_last_revision_info(revno, revision_id)
316
tree.set_last_revision(revision_id)
318
def test_standalone_to_use_shared_preserves_dead_heads(self):
319
self.build_tree(['root/'])
320
tree = self.make_branch_and_tree('root/tree')
321
self.add_dead_head(tree)
322
tree.commit('Hello', rev_id='hello-id')
323
repo = self.make_repository('root', shared=True)
324
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
325
reconfiguration.apply()
326
tree = workingtree.WorkingTree.open('root/tree')
327
message = repo.get_revision('dead-head-id').message
328
self.assertEqual('Dead head', message)
330
def make_repository_tree(self):
331
self.build_tree(['root/'])
332
repo = self.make_repository('root', shared=True)
333
tree = self.make_branch_and_tree('root/tree')
334
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
335
return workingtree.WorkingTree.open('root/tree')
337
def test_use_shared_to_use_shared(self):
338
tree = self.make_repository_tree()
339
self.assertRaises(errors.AlreadyUsingShared,
340
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
342
def test_use_shared_to_standalone(self):
343
tree = self.make_repository_tree()
344
tree.commit('Hello', rev_id='hello-id')
345
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
346
tree = workingtree.WorkingTree.open('root/tree')
347
repo = tree.branch.repository
348
self.assertEqual(repo.bzrdir.root_transport.base,
349
tree.bzrdir.root_transport.base)
350
self.assertEqual('Hello', repo.get_revision('hello-id').message)
352
def test_use_shared_to_standalone_preserves_dead_heads(self):
353
tree = self.make_repository_tree()
354
self.add_dead_head(tree)
355
tree.commit('Hello', rev_id='hello-id')
356
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
357
tree = workingtree.WorkingTree.open('root/tree')
358
repo = tree.branch.repository
359
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
362
def test_standalone_to_standalone(self):
363
tree = self.make_branch_and_tree('tree')
364
self.assertRaises(errors.AlreadyStandalone,
365
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
367
def make_unsynced_branch_reconfiguration(self):
368
parent = self.make_branch_and_tree('parent')
369
parent.commit('commit 1')
370
child = parent.bzrdir.sprout('child').open_workingtree()
371
child.commit('commit 2')
372
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
374
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
375
reconfiguration = self.make_unsynced_branch_reconfiguration()
376
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
378
def test_unsynced_branch_to_lightweight_checkout_forced(self):
379
reconfiguration = self.make_unsynced_branch_reconfiguration()
380
reconfiguration.apply(force=True)
382
def make_repository_with_without_trees(self, with_trees):
383
repo = self.make_repository('repo', shared=True)
384
repo.set_make_working_trees(with_trees)
387
def test_make_with_trees(self):
388
repo = self.make_repository_with_without_trees(False)
389
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
391
reconfiguration.apply()
392
self.assertIs(True, repo.make_working_trees())
394
def test_make_without_trees(self):
395
repo = self.make_repository_with_without_trees(True)
396
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
398
reconfiguration.apply()
399
self.assertIs(False, repo.make_working_trees())
401
def test_make_with_trees_already_with_trees(self):
402
repo = self.make_repository_with_without_trees(True)
403
e = self.assertRaises(errors.AlreadyWithTrees,
404
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
405
self.assertContainsRe(str(e),
406
r"Shared repository '.*' already creates working trees.")
408
def test_make_without_trees_already_no_trees(self):
409
repo = self.make_repository_with_without_trees(False)
410
e = self.assertRaises(errors.AlreadyWithNoTrees,
411
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
412
self.assertContainsRe(str(e),
413
r"Shared repository '.*' already doesn't create working trees.")
415
def test_repository_tree_reconfiguration_not_supported(self):
416
tree = self.make_branch_and_tree('tree')
417
e = self.assertRaises(errors.ReconfigurationNotSupported,
418
reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
419
self.assertContainsRe(str(e),
420
r"Requested reconfiguration of '.*' is not supported.")
422
def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
423
format = bzrdir.format_registry.make_bzrdir('1.9')
424
format.set_branch_format(_mod_branch.BzrBranchFormat8())
425
tree = self.make_branch_and_tree('tree', format=format)
426
tree.branch.set_reference_info('file_id', 'path', '../location')
427
checkout = tree.branch.create_checkout('checkout', lightweight=True)
428
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
429
reconfiguration.apply()
430
checkout_branch = checkout.bzrdir.open_branch()
431
self.assertEqual(('path', '../location'),
432
checkout_branch.get_reference_info('file_id'))