14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
branch as _mod_branch,
26
from breezy.bzr import (
27
branch as _mod_bzrbranch,
28
32
class TestReconfigure(tests.TestCaseWithTransport):
30
34
def test_tree_to_branch(self):
31
35
tree = self.make_branch_and_tree('tree')
32
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
36
reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
33
37
reconfiguration.apply()
34
38
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
38
42
tree = self.make_branch_and_tree('tree')
39
43
self.build_tree(['tree/file'])
41
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
45
reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
42
46
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
43
47
reconfiguration.apply(force=True)
44
48
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
47
51
def test_tree_with_pending_merge_to_branch(self):
48
52
tree = self.make_branch_and_tree('tree')
49
other_tree = tree.bzrdir.sprout('other').open_workingtree()
50
self.build_tree(['other/file'])
51
other_tree.add('file')
52
other_tree.commit('file added')
53
tree.commit('unchanged')
54
other_tree = tree.controldir.sprout('other').open_workingtree()
55
other_tree.commit('mergeable commit')
53
56
tree.merge_from_branch(other_tree.branch)
54
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
57
reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
55
58
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
56
59
reconfiguration.apply(force=True)
57
60
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
60
63
def test_branch_to_branch(self):
61
64
branch = self.make_branch('branch')
62
65
self.assertRaises(errors.AlreadyBranch,
63
reconfigure.Reconfigure.to_branch, branch.bzrdir)
66
reconfigure.Reconfigure.to_branch, branch.controldir)
65
68
def test_repo_to_branch(self):
66
69
repo = self.make_repository('repo')
67
reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
70
reconfiguration = reconfigure.Reconfigure.to_branch(repo.controldir)
68
71
reconfiguration.apply()
70
73
def test_checkout_to_branch(self):
71
74
branch = self.make_branch('branch')
72
75
checkout = branch.create_checkout('checkout')
73
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
76
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.controldir)
74
77
reconfiguration.apply()
75
self.assertIs(None, checkout.branch.get_bound_location())
78
reconfigured = controldir.ControlDir.open('checkout').open_branch()
79
self.assertIs(None, reconfigured.get_bound_location())
77
81
def prepare_lightweight_checkout_to_branch(self):
78
82
branch = self.make_branch('branch')
79
83
checkout = branch.create_checkout('checkout', lightweight=True)
80
84
checkout.commit('first commit', rev_id='rev1')
81
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
85
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.controldir)
82
86
return reconfiguration, checkout
84
88
def test_lightweight_checkout_to_branch(self):
85
89
reconfiguration, checkout = \
86
90
self.prepare_lightweight_checkout_to_branch()
87
91
reconfiguration.apply()
88
checkout_branch = checkout.bzrdir.open_branch()
89
self.assertEqual(checkout_branch.bzrdir.root_transport.base,
90
checkout.bzrdir.root_transport.base)
92
checkout_branch = checkout.controldir.open_branch()
93
self.assertEqual(checkout_branch.controldir.root_transport.base,
94
checkout.controldir.root_transport.base)
91
95
self.assertEqual('rev1', checkout_branch.last_revision())
92
repo = checkout.bzrdir.open_repository()
96
repo = checkout.controldir.open_repository()
93
97
repo.get_revision('rev1')
95
99
def test_lightweight_checkout_to_branch_tags(self):
97
101
self.prepare_lightweight_checkout_to_branch()
98
102
checkout.branch.tags.set_tag('foo', 'bar')
99
103
reconfiguration.apply()
100
checkout_branch = checkout.bzrdir.open_branch()
104
checkout_branch = checkout.controldir.open_branch()
101
105
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
103
107
def prepare_lightweight_checkout_to_checkout(self):
104
108
branch = self.make_branch('branch')
105
109
checkout = branch.create_checkout('checkout', lightweight=True)
106
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
110
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.controldir)
107
111
return reconfiguration, checkout
109
113
def test_lightweight_checkout_to_checkout(self):
110
114
reconfiguration, checkout = \
111
115
self.prepare_lightweight_checkout_to_checkout()
112
116
reconfiguration.apply()
113
checkout_branch = checkout.bzrdir.open_branch()
117
checkout_branch = checkout.controldir.open_branch()
114
118
self.assertIsNot(checkout_branch.get_bound_location(), None)
116
120
def test_lightweight_checkout_to_checkout_tags(self):
118
122
self.prepare_lightweight_checkout_to_checkout()
119
123
checkout.branch.tags.set_tag('foo', 'bar')
120
124
reconfiguration.apply()
121
checkout_branch = checkout.bzrdir.open_branch()
125
checkout_branch = checkout.controldir.open_branch()
122
126
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
124
128
def test_lightweight_conversion_uses_shared_repo(self):
125
129
parent = self.make_branch('parent')
126
130
shared_repo = self.make_repository('repo', shared=True)
127
131
checkout = parent.create_checkout('repo/checkout', lightweight=True)
128
reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
129
checkout_repo = checkout.bzrdir.open_branch().repository
130
self.assertEqual(shared_repo.bzrdir.root_transport.base,
131
checkout_repo.bzrdir.root_transport.base)
132
reconfigure.Reconfigure.to_tree(checkout.controldir).apply()
133
checkout_repo = checkout.controldir.open_branch().repository
134
self.assertEqual(shared_repo.controldir.root_transport.base,
135
checkout_repo.controldir.root_transport.base)
133
137
def test_branch_to_tree(self):
134
138
branch = self.make_branch('branch')
135
reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
139
reconfiguration=reconfigure.Reconfigure.to_tree(branch.controldir)
136
140
reconfiguration.apply()
137
branch.bzrdir.open_workingtree()
141
branch.controldir.open_workingtree()
139
143
def test_tree_to_tree(self):
140
144
tree = self.make_branch_and_tree('tree')
141
145
self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
144
148
def test_select_bind_location(self):
145
149
branch = self.make_branch('branch')
146
reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
150
reconfiguration = reconfigure.Reconfigure(branch.controldir)
147
151
self.assertRaises(errors.NoBindLocation,
148
152
reconfiguration._select_bind_location)
149
153
branch.set_parent('http://parent')
154
reconfiguration = reconfigure.Reconfigure(branch.controldir)
150
155
self.assertEqual('http://parent',
151
156
reconfiguration._select_bind_location())
152
157
branch.set_push_location('sftp://push')
158
reconfiguration = reconfigure.Reconfigure(branch.controldir)
153
159
self.assertEqual('sftp://push',
154
160
reconfiguration._select_bind_location())
155
branch.set_bound_location('bzr://foo/old-bound')
156
branch.set_bound_location(None)
163
branch.set_bound_location('bzr://foo/old-bound')
164
branch.set_bound_location(None)
167
reconfiguration = reconfigure.Reconfigure(branch.controldir)
157
168
self.assertEqual('bzr://foo/old-bound',
158
169
reconfiguration._select_bind_location())
159
170
branch.set_bound_location('bzr://foo/cur-bound')
171
reconfiguration = reconfigure.Reconfigure(branch.controldir)
160
172
self.assertEqual('bzr://foo/cur-bound',
161
173
reconfiguration._select_bind_location())
162
174
reconfiguration.new_bound_location = 'ftp://user-specified'
176
188
parent = self.make_branch('parent')
178
190
tree = self.make_branch_and_tree('tree')
179
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
191
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
180
192
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
181
193
# setting a parent allows it to become a checkout
182
194
tree.branch.set_parent(parent.base)
195
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
183
196
reconfiguration.apply()
184
197
# supplying a location allows it to become a checkout
185
198
tree2 = self.make_branch_and_tree('tree2')
186
reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
199
reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.controldir,
188
201
reconfiguration.apply()
195
208
tree = self.make_branch_and_tree('tree')
196
209
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
198
211
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
199
212
# setting a parent allows it to become a checkout
200
213
tree.branch.set_parent(parent.base)
214
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
201
216
reconfiguration.apply()
202
217
# supplying a location allows it to become a checkout
203
218
tree2 = self.make_branch_and_tree('tree2')
204
219
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
205
tree2.bzrdir, parent.base)
220
tree2.controldir, parent.base)
206
221
reconfiguration.apply()
208
223
def test_checkout_to_checkout(self):
209
224
parent = self.make_branch('parent')
210
225
checkout = parent.create_checkout('checkout')
211
226
self.assertRaises(errors.AlreadyCheckout,
212
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
227
reconfigure.Reconfigure.to_checkout, checkout.controldir)
214
229
def make_unsynced_checkout(self):
215
230
parent = self.make_branch('parent')
216
231
checkout = parent.create_checkout('checkout')
217
232
checkout.commit('test', rev_id='new-commit', local=True)
218
233
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
220
235
return checkout, parent, reconfiguration
222
237
def test_unsynced_checkout_to_lightweight(self):
227
242
checkout, parent, reconfiguration = self.make_unsynced_checkout()
228
243
parent.pull(checkout.branch)
229
244
reconfiguration.apply()
230
wt = checkout.bzrdir.open_workingtree()
245
wt = checkout.controldir.open_workingtree()
231
246
self.assertTrue(parent.repository.has_same_location(
232
247
wt.branch.repository))
233
248
parent.repository.get_revision('new-commit')
234
249
self.assertRaises(errors.NoRepositoryPresent,
235
checkout.bzrdir.open_repository)
250
checkout.controldir.open_repository)
237
252
def prepare_branch_to_lightweight_checkout(self):
238
253
parent = self.make_branch('parent')
239
child = parent.bzrdir.sprout('child').open_workingtree()
254
child = parent.controldir.sprout('child').open_workingtree()
240
255
child.commit('test', rev_id='new-commit')
241
256
parent.pull(child.branch)
242
child.bzrdir.destroy_workingtree()
257
child.controldir.destroy_workingtree()
243
258
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
245
260
return parent, child, reconfiguration
247
262
def test_branch_to_lightweight_checkout(self):
249
264
self.prepare_branch_to_lightweight_checkout()
250
265
reconfiguration.apply()
251
266
self.assertTrue(reconfiguration._destroy_branch)
252
wt = child.bzrdir.open_workingtree()
267
wt = child.controldir.open_workingtree()
253
268
self.assertTrue(parent.repository.has_same_location(
254
269
wt.branch.repository))
255
270
parent.repository.get_revision('new-commit')
256
271
self.assertRaises(errors.NoRepositoryPresent,
257
child.bzrdir.open_repository)
272
child.controldir.open_repository)
259
274
def test_branch_to_lightweight_checkout_failure(self):
260
275
parent, child, reconfiguration = \
261
276
self.prepare_branch_to_lightweight_checkout()
262
old_Repository_fetch = repository.Repository.fetch
263
repository.Repository.fetch = None
277
old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
278
vf_repository.VersionedFileRepository.fetch = None
265
280
self.assertRaises(TypeError, reconfiguration.apply)
267
repository.Repository.fetch = old_Repository_fetch
282
vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
268
283
child = _mod_branch.Branch.open('child')
269
284
self.assertContainsRe(child.base, 'child/$')
281
296
checkout = parent.create_checkout('checkout', lightweight=True)
282
297
self.assertRaises(errors.AlreadyLightweightCheckout,
283
298
reconfigure.Reconfigure.to_lightweight_checkout,
286
301
def test_repo_to_tree(self):
287
302
repo = self.make_repository('repo')
288
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
303
reconfiguration = reconfigure.Reconfigure.to_tree(repo.controldir)
289
304
reconfiguration.apply()
290
305
workingtree.WorkingTree.open('repo')
292
307
def test_shared_repo_to_lightweight_checkout(self):
293
308
repo = self.make_repository('repo', shared=True)
294
309
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
296
311
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
297
312
branch = self.make_branch('branch')
298
313
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
299
repo.bzrdir, 'branch')
314
repo.controldir, 'branch')
300
315
reconfiguration.apply()
301
316
workingtree.WorkingTree.open('repo')
302
317
repository.Repository.open('repo')
344
359
self.build_tree(['root/'])
345
360
repo = self.make_repository('root', shared=True)
346
361
tree = self.make_branch_and_tree('root/tree')
347
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
362
reconfigure.Reconfigure.to_use_shared(tree.controldir).apply()
348
363
return workingtree.WorkingTree.open('root/tree')
350
365
def test_use_shared_to_use_shared(self):
351
366
tree = self.make_repository_tree()
352
367
self.assertRaises(errors.AlreadyUsingShared,
353
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
368
reconfigure.Reconfigure.to_use_shared, tree.controldir)
355
370
def test_use_shared_to_standalone(self):
356
371
tree = self.make_repository_tree()
357
372
tree.commit('Hello', rev_id='hello-id')
358
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
373
reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
359
374
tree = workingtree.WorkingTree.open('root/tree')
360
375
repo = tree.branch.repository
361
self.assertEqual(repo.bzrdir.root_transport.base,
362
tree.bzrdir.root_transport.base)
376
self.assertEqual(repo.controldir.root_transport.base,
377
tree.controldir.root_transport.base)
363
378
self.assertEqual('Hello', repo.get_revision('hello-id').message)
365
380
def test_use_shared_to_standalone_preserves_dead_heads(self):
366
381
tree = self.make_repository_tree()
367
382
self.add_dead_head(tree)
368
383
tree.commit('Hello', rev_id='hello-id')
369
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
384
reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
370
385
tree = workingtree.WorkingTree.open('root/tree')
371
386
repo = tree.branch.repository
372
387
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
375
390
def test_standalone_to_standalone(self):
376
391
tree = self.make_branch_and_tree('tree')
377
392
self.assertRaises(errors.AlreadyStandalone,
378
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
393
reconfigure.Reconfigure.to_standalone, tree.controldir)
380
395
def make_unsynced_branch_reconfiguration(self):
381
396
parent = self.make_branch_and_tree('parent')
382
397
parent.commit('commit 1')
383
child = parent.bzrdir.sprout('child').open_workingtree()
398
child = parent.controldir.sprout('child').open_workingtree()
384
399
child.commit('commit 2')
385
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
400
return reconfigure.Reconfigure.to_lightweight_checkout(child.controldir)
387
402
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
388
403
reconfiguration = self.make_unsynced_branch_reconfiguration()
400
415
def test_make_with_trees(self):
401
416
repo = self.make_repository_with_without_trees(False)
402
417
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
418
repo.controldir, True)
404
419
reconfiguration.apply()
405
420
self.assertIs(True, repo.make_working_trees())
407
422
def test_make_without_trees(self):
408
423
repo = self.make_repository_with_without_trees(True)
409
424
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
425
repo.controldir, False)
411
426
reconfiguration.apply()
412
427
self.assertIs(False, repo.make_working_trees())
414
429
def test_make_with_trees_already_with_trees(self):
415
430
repo = self.make_repository_with_without_trees(True)
416
431
e = self.assertRaises(errors.AlreadyWithTrees,
417
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
432
reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
418
433
self.assertContainsRe(str(e),
419
434
r"Shared repository '.*' already creates working trees.")
421
436
def test_make_without_trees_already_no_trees(self):
422
437
repo = self.make_repository_with_without_trees(False)
423
438
e = self.assertRaises(errors.AlreadyWithNoTrees,
424
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
439
reconfigure.Reconfigure.set_repository_trees, repo.controldir, False)
425
440
self.assertContainsRe(str(e),
426
441
r"Shared repository '.*' already doesn't create working trees.")
428
443
def test_repository_tree_reconfiguration_not_supported(self):
429
444
tree = self.make_branch_and_tree('tree')
430
445
e = self.assertRaises(errors.ReconfigurationNotSupported,
431
reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
446
reconfigure.Reconfigure.set_repository_trees, tree.controldir, None)
432
447
self.assertContainsRe(str(e),
433
448
r"Requested reconfiguration of '.*' is not supported.")
435
450
def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
436
format = bzrdir.format_registry.make_bzrdir('1.9')
437
format.set_branch_format(_mod_branch.BzrBranchFormat8())
451
format = controldir.format_registry.make_controldir('1.9')
452
format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
438
453
tree = self.make_branch_and_tree('tree', format=format)
439
454
tree.branch.set_reference_info('file_id', 'path', '../location')
440
455
checkout = tree.branch.create_checkout('checkout', lightweight=True)
441
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
456
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
442
457
reconfiguration.apply()
443
checkout_branch = checkout.bzrdir.open_branch()
458
checkout_branch = checkout.controldir.open_branch()
444
459
self.assertEqual(('path', '../location'),
445
460
checkout_branch.get_reference_info('file_id'))