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,
27
class TestReconfigure(tests.TestCaseWithTransport):
29
def test_tree_to_branch(self):
30
tree = self.make_branch_and_tree('tree')
31
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
32
reconfiguration.apply()
33
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
36
def test_modified_tree_to_branch(self):
37
tree = self.make_branch_and_tree('tree')
38
self.build_tree(['tree/file'])
40
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
41
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
42
reconfiguration.apply(force=True)
43
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
46
def test_branch_to_branch(self):
47
branch = self.make_branch('branch')
48
self.assertRaises(errors.AlreadyBranch,
49
reconfigure.Reconfigure.to_branch, branch.bzrdir)
51
def test_repo_to_branch(self):
52
repo = self.make_repository('repo')
53
reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
54
reconfiguration.apply()
56
def test_checkout_to_branch(self):
57
branch = self.make_branch('branch')
58
checkout = branch.create_checkout('checkout')
59
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
60
reconfiguration.apply()
61
self.assertIs(None, checkout.branch.get_bound_location())
63
def prepare_lightweight_checkout_to_branch(self):
64
branch = self.make_branch('branch')
65
checkout = branch.create_checkout('checkout', lightweight=True)
66
checkout.commit('first commit', rev_id='rev1')
67
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
68
return reconfiguration, checkout
70
def test_lightweight_checkout_to_branch(self):
71
reconfiguration, checkout = \
72
self.prepare_lightweight_checkout_to_branch()
73
reconfiguration.apply()
74
checkout_branch = checkout.bzrdir.open_branch()
75
self.assertEqual(checkout_branch.bzrdir.root_transport.base,
76
checkout.bzrdir.root_transport.base)
77
self.assertEqual('rev1', checkout_branch.last_revision())
78
repo = checkout.bzrdir.open_repository()
79
repo.get_revision('rev1')
81
def test_lightweight_checkout_to_branch_tags(self):
82
reconfiguration, checkout = \
83
self.prepare_lightweight_checkout_to_branch()
84
checkout.branch.tags.set_tag('foo', 'bar')
85
reconfiguration.apply()
86
checkout_branch = checkout.bzrdir.open_branch()
87
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
89
def prepare_lightweight_checkout_to_checkout(self):
90
branch = self.make_branch('branch')
91
checkout = branch.create_checkout('checkout', lightweight=True)
92
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
93
return reconfiguration, checkout
95
def test_lightweight_checkout_to_checkout(self):
96
reconfiguration, checkout = \
97
self.prepare_lightweight_checkout_to_checkout()
98
reconfiguration.apply()
99
checkout_branch = checkout.bzrdir.open_branch()
100
self.assertIsNot(checkout_branch.get_bound_location(), None)
102
def test_lightweight_checkout_to_checkout_tags(self):
103
reconfiguration, checkout = \
104
self.prepare_lightweight_checkout_to_checkout()
105
checkout.branch.tags.set_tag('foo', 'bar')
106
reconfiguration.apply()
107
checkout_branch = checkout.bzrdir.open_branch()
108
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
110
def test_lightweight_conversion_uses_shared_repo(self):
111
parent = self.make_branch('parent')
112
shared_repo = self.make_repository('repo', shared=True)
113
checkout = parent.create_checkout('repo/checkout', lightweight=True)
114
reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
115
checkout_repo = checkout.bzrdir.open_branch().repository
116
self.assertEqual(shared_repo.bzrdir.root_transport.base,
117
checkout_repo.bzrdir.root_transport.base)
119
def test_branch_to_tree(self):
120
branch = self.make_branch('branch')
121
reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
122
reconfiguration.apply()
123
branch.bzrdir.open_workingtree()
125
def test_tree_to_tree(self):
126
tree = self.make_branch_and_tree('tree')
127
self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
130
def test_select_bind_location(self):
131
branch = self.make_branch('branch')
132
reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
133
self.assertRaises(errors.NoBindLocation,
134
reconfiguration._select_bind_location)
135
branch.set_parent('http://parent')
136
self.assertEqual('http://parent',
137
reconfiguration._select_bind_location())
138
branch.set_push_location('sftp://push')
139
self.assertEqual('sftp://push',
140
reconfiguration._select_bind_location())
141
branch.set_bound_location('bzr://foo/old-bound')
142
branch.set_bound_location(None)
143
self.assertEqual('bzr://foo/old-bound',
144
reconfiguration._select_bind_location())
145
branch.set_bound_location('bzr://foo/cur-bound')
146
self.assertEqual('bzr://foo/cur-bound',
147
reconfiguration._select_bind_location())
148
reconfiguration.new_bound_location = 'ftp://user-specified'
149
self.assertEqual('ftp://user-specified',
150
reconfiguration._select_bind_location())
152
def test_select_reference_bind_location(self):
153
branch = self.make_branch('branch')
154
checkout = branch.create_checkout('checkout', lightweight=True)
155
reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
156
self.assertEqual(branch.base,
157
reconfiguration._select_bind_location())
159
def test_tree_to_checkout(self):
160
# A tree with no related branches and no supplied bind location cannot
162
parent = self.make_branch('parent')
164
tree = self.make_branch_and_tree('tree')
165
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
166
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
167
# setting a parent allows it to become a checkout
168
tree.branch.set_parent(parent.base)
169
reconfiguration.apply()
170
# supplying a location allows it to become a checkout
171
tree2 = self.make_branch_and_tree('tree2')
172
reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
174
reconfiguration.apply()
176
def test_tree_to_lightweight_checkout(self):
177
# A tree with no related branches and no supplied bind location cannot
179
parent = self.make_branch('parent')
181
tree = self.make_branch_and_tree('tree')
182
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
184
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
185
# setting a parent allows it to become a checkout
186
tree.branch.set_parent(parent.base)
187
reconfiguration.apply()
188
# supplying a location allows it to become a checkout
189
tree2 = self.make_branch_and_tree('tree2')
190
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
191
tree2.bzrdir, parent.base)
192
reconfiguration.apply()
194
def test_checkout_to_checkout(self):
195
parent = self.make_branch('parent')
196
checkout = parent.create_checkout('checkout')
197
self.assertRaises(errors.AlreadyCheckout,
198
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
200
def make_unsynced_checkout(self):
201
parent = self.make_branch('parent')
202
checkout = parent.create_checkout('checkout')
203
checkout.commit('test', rev_id='new-commit', local=True)
204
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
206
return checkout, parent, reconfiguration
208
def test_unsynced_checkout_to_lightweight(self):
209
checkout, parent, reconfiguration = self.make_unsynced_checkout()
210
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
212
def test_synced_checkout_to_lightweight(self):
213
checkout, parent, reconfiguration = self.make_unsynced_checkout()
214
parent.pull(checkout.branch)
215
reconfiguration.apply()
216
wt = checkout.bzrdir.open_workingtree()
217
self.assertTrue(parent.repository.has_same_location(
218
wt.branch.repository))
219
parent.repository.get_revision('new-commit')
220
self.assertRaises(errors.NoRepositoryPresent,
221
checkout.bzrdir.open_repository)
223
def prepare_branch_to_lightweight_checkout(self):
224
parent = self.make_branch('parent')
225
child = parent.bzrdir.sprout('child').open_workingtree()
226
child.commit('test', rev_id='new-commit')
227
parent.pull(child.branch)
228
child.bzrdir.destroy_workingtree()
229
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
231
return parent, child, reconfiguration
233
def test_branch_to_lightweight_checkout(self):
234
parent, child, reconfiguration = \
235
self.prepare_branch_to_lightweight_checkout()
236
reconfiguration.apply()
237
self.assertTrue(reconfiguration._destroy_branch)
238
wt = child.bzrdir.open_workingtree()
239
self.assertTrue(parent.repository.has_same_location(
240
wt.branch.repository))
241
parent.repository.get_revision('new-commit')
242
self.assertRaises(errors.NoRepositoryPresent,
243
child.bzrdir.open_repository)
245
def test_branch_to_lightweight_checkout_failure(self):
246
parent, child, reconfiguration = \
247
self.prepare_branch_to_lightweight_checkout()
248
old_Repository_fetch = repository.Repository.fetch
249
repository.Repository.fetch = None
251
self.assertRaises(TypeError, reconfiguration.apply)
253
repository.Repository.fetch = old_Repository_fetch
254
child = _mod_branch.Branch.open('child')
255
self.assertContainsRe(child.base, 'child/$')
257
def test_branch_to_lightweight_checkout_fetch_tags(self):
258
parent, child, reconfiguration = \
259
self.prepare_branch_to_lightweight_checkout()
260
child.branch.tags.set_tag('foo', 'bar')
261
reconfiguration.apply()
262
child = _mod_branch.Branch.open('child')
263
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
265
def test_lightweight_checkout_to_lightweight_checkout(self):
266
parent = self.make_branch('parent')
267
checkout = parent.create_checkout('checkout', lightweight=True)
268
self.assertRaises(errors.AlreadyLightweightCheckout,
269
reconfigure.Reconfigure.to_lightweight_checkout,
272
def test_repo_to_tree(self):
273
repo = self.make_repository('repo')
274
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
275
reconfiguration.apply()
276
workingtree.WorkingTree.open('repo')
278
def test_shared_repo_to_lightweight_checkout(self):
279
repo = self.make_repository('repo', shared=True)
280
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
282
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
283
branch = self.make_branch('branch')
284
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
285
repo.bzrdir, 'branch')
286
reconfiguration.apply()
287
workingtree.WorkingTree.open('repo')
288
repository.Repository.open('repo')
290
def test_unshared_repo_to_lightweight_checkout(self):
291
repo = self.make_repository('repo', shared=False)
292
branch = self.make_branch('branch')
293
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
294
repo.bzrdir, 'branch')
295
reconfiguration.apply()
296
workingtree.WorkingTree.open('repo')
297
self.assertRaises(errors.NoRepositoryPresent,
298
repository.Repository.open, 'repo')
300
def test_standalone_to_use_shared(self):
301
self.build_tree(['root/'])
302
tree = self.make_branch_and_tree('root/tree')
303
tree.commit('Hello', rev_id='hello-id')
304
repo = self.make_repository('root', shared=True)
305
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
306
reconfiguration.apply()
307
tree = workingtree.WorkingTree.open('root/tree')
308
self.assertTrue(repo.has_same_location(tree.branch.repository))
309
self.assertEqual('Hello', repo.get_revision('hello-id').message)
311
def add_dead_head(self, tree):
312
revno, revision_id = tree.branch.last_revision_info()
313
tree.commit('Dead head', rev_id='dead-head-id')
314
tree.branch.set_last_revision_info(revno, revision_id)
315
tree.set_last_revision(revision_id)
317
def test_standalone_to_use_shared_preserves_dead_heads(self):
318
self.build_tree(['root/'])
319
tree = self.make_branch_and_tree('root/tree')
320
self.add_dead_head(tree)
321
tree.commit('Hello', rev_id='hello-id')
322
repo = self.make_repository('root', shared=True)
323
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
324
reconfiguration.apply()
325
tree = workingtree.WorkingTree.open('root/tree')
326
message = repo.get_revision('dead-head-id').message
327
self.assertEqual('Dead head', message)
329
def make_repository_tree(self):
330
self.build_tree(['root/'])
331
repo = self.make_repository('root', shared=True)
332
tree = self.make_branch_and_tree('root/tree')
333
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
334
return workingtree.WorkingTree.open('root/tree')
336
def test_use_shared_to_use_shared(self):
337
tree = self.make_repository_tree()
338
self.assertRaises(errors.AlreadyUsingShared,
339
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
341
def test_use_shared_to_standalone(self):
342
tree = self.make_repository_tree()
343
tree.commit('Hello', rev_id='hello-id')
344
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
345
tree = workingtree.WorkingTree.open('root/tree')
346
repo = tree.branch.repository
347
self.assertEqual(repo.bzrdir.root_transport.base,
348
tree.bzrdir.root_transport.base)
349
self.assertEqual('Hello', repo.get_revision('hello-id').message)
351
def test_use_shared_to_standalone_preserves_dead_heads(self):
352
tree = self.make_repository_tree()
353
self.add_dead_head(tree)
354
tree.commit('Hello', rev_id='hello-id')
355
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
356
tree = workingtree.WorkingTree.open('root/tree')
357
repo = tree.branch.repository
358
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
361
def test_standalone_to_standalone(self):
362
tree = self.make_branch_and_tree('tree')
363
self.assertRaises(errors.AlreadyStandalone,
364
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
366
def make_unsynced_branch_reconfiguration(self):
367
parent = self.make_branch_and_tree('parent')
368
parent.commit('commit 1')
369
child = parent.bzrdir.sprout('child').open_workingtree()
370
child.commit('commit 2')
371
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
373
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
374
reconfiguration = self.make_unsynced_branch_reconfiguration()
375
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
377
def test_unsynced_branch_to_lightweight_checkout_forced(self):
378
reconfiguration = self.make_unsynced_branch_reconfiguration()
379
reconfiguration.apply(force=True)
381
def make_repository_with_without_trees(self, with_trees):
382
repo = self.make_repository('repo', shared=True)
383
repo.set_make_working_trees(with_trees)
386
def test_make_with_trees(self):
387
repo = self.make_repository_with_without_trees(False)
388
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
390
reconfiguration.apply()
391
self.assertIs(True, repo.make_working_trees())
393
def test_make_without_trees(self):
394
repo = self.make_repository_with_without_trees(True)
395
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
397
reconfiguration.apply()
398
self.assertIs(False, repo.make_working_trees())
400
def test_make_with_trees_already_with_trees(self):
401
repo = self.make_repository_with_without_trees(True)
402
e = self.assertRaises(errors.AlreadyWithTrees,
403
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
404
self.assertContainsRe(str(e),
405
r"Shared repository '.*' already creates working trees.")
407
def test_make_without_trees_already_no_trees(self):
408
repo = self.make_repository_with_without_trees(False)
409
e = self.assertRaises(errors.AlreadyWithNoTrees,
410
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
411
self.assertContainsRe(str(e),
412
r"Shared repository '.*' already doesn't create working trees.")
414
def test_repository_tree_reconfiguration_not_supported(self):
415
tree = self.make_branch_and_tree('tree')
416
e = self.assertRaises(errors.ReconfigurationNotSupported,
417
reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
418
self.assertContainsRe(str(e),
419
r"Requested reconfiguration of '.*' is not supported.")