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