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