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(
73
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
78
74
reconfiguration.apply()
79
reconfigured = controldir.ControlDir.open('checkout').open_branch()
80
self.assertIs(None, reconfigured.get_bound_location())
75
self.assertIs(None, checkout.branch.get_bound_location())
82
77
def prepare_lightweight_checkout_to_branch(self):
83
78
branch = self.make_branch('branch')
84
79
checkout = branch.create_checkout('checkout', lightweight=True)
85
checkout.commit('first commit', rev_id=b'rev1')
86
reconfiguration = reconfigure.Reconfigure.to_branch(
80
checkout.commit('first commit', rev_id='rev1')
81
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
88
82
return reconfiguration, checkout
90
84
def test_lightweight_checkout_to_branch(self):
91
85
reconfiguration, checkout = \
92
86
self.prepare_lightweight_checkout_to_branch()
93
87
reconfiguration.apply()
94
checkout_branch = checkout.controldir.open_branch()
95
self.assertEqual(checkout_branch.controldir.root_transport.base,
96
checkout.controldir.root_transport.base)
97
self.assertEqual(b'rev1', checkout_branch.last_revision())
98
repo = checkout.controldir.open_repository()
99
repo.get_revision(b'rev1')
88
checkout_branch = checkout.bzrdir.open_branch()
89
self.assertEqual(checkout_branch.bzrdir.root_transport.base,
90
checkout.bzrdir.root_transport.base)
91
self.assertEqual('rev1', checkout_branch.last_revision())
92
repo = checkout.bzrdir.open_repository()
93
repo.get_revision('rev1')
101
95
def test_lightweight_checkout_to_branch_tags(self):
102
96
reconfiguration, checkout = \
103
97
self.prepare_lightweight_checkout_to_branch()
104
checkout.branch.tags.set_tag('foo', b'bar')
98
checkout.branch.tags.set_tag('foo', 'bar')
105
99
reconfiguration.apply()
106
checkout_branch = checkout.controldir.open_branch()
107
self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
100
checkout_branch = checkout.bzrdir.open_branch()
101
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
109
103
def prepare_lightweight_checkout_to_checkout(self):
110
104
branch = self.make_branch('branch')
111
105
checkout = branch.create_checkout('checkout', lightweight=True)
112
reconfiguration = reconfigure.Reconfigure.to_checkout(
106
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
114
107
return reconfiguration, checkout
116
109
def test_lightweight_checkout_to_checkout(self):
117
110
reconfiguration, checkout = \
118
111
self.prepare_lightweight_checkout_to_checkout()
119
112
reconfiguration.apply()
120
checkout_branch = checkout.controldir.open_branch()
113
checkout_branch = checkout.bzrdir.open_branch()
121
114
self.assertIsNot(checkout_branch.get_bound_location(), None)
123
116
def test_lightweight_checkout_to_checkout_tags(self):
124
117
reconfiguration, checkout = \
125
118
self.prepare_lightweight_checkout_to_checkout()
126
checkout.branch.tags.set_tag('foo', b'bar')
119
checkout.branch.tags.set_tag('foo', 'bar')
127
120
reconfiguration.apply()
128
checkout_branch = checkout.controldir.open_branch()
129
self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
121
checkout_branch = checkout.bzrdir.open_branch()
122
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
131
124
def test_lightweight_conversion_uses_shared_repo(self):
132
125
parent = self.make_branch('parent')
133
126
shared_repo = self.make_repository('repo', shared=True)
134
127
checkout = parent.create_checkout('repo/checkout', lightweight=True)
135
reconfigure.Reconfigure.to_tree(checkout.controldir).apply()
136
checkout_repo = checkout.controldir.open_branch().repository
137
self.assertEqual(shared_repo.controldir.root_transport.base,
138
checkout_repo.controldir.root_transport.base)
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)
140
133
def test_branch_to_tree(self):
141
134
branch = self.make_branch('branch')
142
reconfiguration = reconfigure.Reconfigure.to_tree(branch.controldir)
135
reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
143
136
reconfiguration.apply()
144
branch.controldir.open_workingtree()
137
branch.bzrdir.open_workingtree()
146
139
def test_tree_to_tree(self):
147
140
tree = self.make_branch_and_tree('tree')
148
self.assertRaises(reconfigure.AlreadyTree,
149
reconfigure.Reconfigure.to_tree, tree.controldir)
141
self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
151
144
def test_select_bind_location(self):
152
145
branch = self.make_branch('branch')
153
reconfiguration = reconfigure.Reconfigure(branch.controldir)
154
self.assertRaises(reconfigure.NoBindLocation,
146
reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
147
self.assertRaises(errors.NoBindLocation,
155
148
reconfiguration._select_bind_location)
156
149
branch.set_parent('http://parent')
157
reconfiguration = reconfigure.Reconfigure(branch.controldir)
158
150
self.assertEqual('http://parent',
159
151
reconfiguration._select_bind_location())
160
152
branch.set_push_location('sftp://push')
161
reconfiguration = reconfigure.Reconfigure(branch.controldir)
162
153
self.assertEqual('sftp://push',
163
154
reconfiguration._select_bind_location())
166
branch.set_bound_location('bzr://foo/old-bound')
167
branch.set_bound_location(None)
170
reconfiguration = reconfigure.Reconfigure(branch.controldir)
155
branch.set_bound_location('bzr://foo/old-bound')
156
branch.set_bound_location(None)
171
157
self.assertEqual('bzr://foo/old-bound',
172
158
reconfiguration._select_bind_location())
173
159
branch.set_bound_location('bzr://foo/cur-bound')
174
reconfiguration = reconfigure.Reconfigure(branch.controldir)
175
160
self.assertEqual('bzr://foo/cur-bound',
176
161
reconfiguration._select_bind_location())
177
162
reconfiguration.new_bound_location = 'ftp://user-specified'
211
195
tree = self.make_branch_and_tree('tree')
212
196
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
214
self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
198
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
215
199
# setting a parent allows it to become a checkout
216
200
tree.branch.set_parent(parent.base)
217
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
219
201
reconfiguration.apply()
220
202
# supplying a location allows it to become a checkout
221
203
tree2 = self.make_branch_and_tree('tree2')
222
204
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
223
tree2.controldir, parent.base)
205
tree2.bzrdir, parent.base)
224
206
reconfiguration.apply()
226
208
def test_checkout_to_checkout(self):
227
209
parent = self.make_branch('parent')
228
210
checkout = parent.create_checkout('checkout')
229
self.assertRaises(reconfigure.AlreadyCheckout,
230
reconfigure.Reconfigure.to_checkout, checkout.controldir)
211
self.assertRaises(errors.AlreadyCheckout,
212
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
232
214
def make_unsynced_checkout(self):
233
215
parent = self.make_branch('parent')
234
216
checkout = parent.create_checkout('checkout')
235
checkout.commit('test', rev_id=b'new-commit', local=True)
217
checkout.commit('test', rev_id='new-commit', local=True)
236
218
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
238
220
return checkout, parent, reconfiguration
240
222
def test_unsynced_checkout_to_lightweight(self):
241
223
checkout, parent, reconfiguration = self.make_unsynced_checkout()
242
self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
224
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
244
226
def test_synced_checkout_to_lightweight(self):
245
227
checkout, parent, reconfiguration = self.make_unsynced_checkout()
246
228
parent.pull(checkout.branch)
247
229
reconfiguration.apply()
248
wt = checkout.controldir.open_workingtree()
230
wt = checkout.bzrdir.open_workingtree()
249
231
self.assertTrue(parent.repository.has_same_location(
250
232
wt.branch.repository))
251
parent.repository.get_revision(b'new-commit')
233
parent.repository.get_revision('new-commit')
252
234
self.assertRaises(errors.NoRepositoryPresent,
253
checkout.controldir.open_repository)
235
checkout.bzrdir.open_repository)
255
237
def prepare_branch_to_lightweight_checkout(self):
256
238
parent = self.make_branch('parent')
257
child = parent.controldir.sprout('child').open_workingtree()
258
child.commit('test', rev_id=b'new-commit')
239
child = parent.bzrdir.sprout('child').open_workingtree()
240
child.commit('test', rev_id='new-commit')
259
241
parent.pull(child.branch)
260
child.controldir.destroy_workingtree()
242
child.bzrdir.destroy_workingtree()
261
243
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
263
245
return parent, child, reconfiguration
265
247
def test_branch_to_lightweight_checkout(self):
267
249
self.prepare_branch_to_lightweight_checkout()
268
250
reconfiguration.apply()
269
251
self.assertTrue(reconfiguration._destroy_branch)
270
wt = child.controldir.open_workingtree()
252
wt = child.bzrdir.open_workingtree()
271
253
self.assertTrue(parent.repository.has_same_location(
272
254
wt.branch.repository))
273
parent.repository.get_revision(b'new-commit')
255
parent.repository.get_revision('new-commit')
274
256
self.assertRaises(errors.NoRepositoryPresent,
275
child.controldir.open_repository)
257
child.bzrdir.open_repository)
277
259
def test_branch_to_lightweight_checkout_failure(self):
278
260
parent, child, reconfiguration = \
279
261
self.prepare_branch_to_lightweight_checkout()
280
old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
281
vf_repository.VersionedFileRepository.fetch = None
262
old_Repository_fetch = repository.Repository.fetch
263
repository.Repository.fetch = None
283
265
self.assertRaises(TypeError, reconfiguration.apply)
285
vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
267
repository.Repository.fetch = old_Repository_fetch
286
268
child = _mod_branch.Branch.open('child')
287
269
self.assertContainsRe(child.base, 'child/$')
289
271
def test_branch_to_lightweight_checkout_fetch_tags(self):
290
272
parent, child, reconfiguration = \
291
273
self.prepare_branch_to_lightweight_checkout()
292
child.branch.tags.set_tag('foo', b'bar')
274
child.branch.tags.set_tag('foo', 'bar')
293
275
reconfiguration.apply()
294
276
child = _mod_branch.Branch.open('child')
295
self.assertEqual(b'bar', parent.tags.lookup_tag('foo'))
277
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
297
279
def test_lightweight_checkout_to_lightweight_checkout(self):
298
280
parent = self.make_branch('parent')
299
281
checkout = parent.create_checkout('checkout', lightweight=True)
300
self.assertRaises(reconfigure.AlreadyLightweightCheckout,
282
self.assertRaises(errors.AlreadyLightweightCheckout,
301
283
reconfigure.Reconfigure.to_lightweight_checkout,
304
286
def test_repo_to_tree(self):
305
287
repo = self.make_repository('repo')
306
reconfiguration = reconfigure.Reconfigure.to_tree(repo.controldir)
288
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
307
289
reconfiguration.apply()
308
290
workingtree.WorkingTree.open('repo')
310
292
def test_shared_repo_to_lightweight_checkout(self):
311
293
repo = self.make_repository('repo', shared=True)
312
294
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
314
self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
315
self.make_branch('branch')
296
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
297
branch = self.make_branch('branch')
316
298
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
317
repo.controldir, 'branch')
299
repo.bzrdir, 'branch')
318
300
reconfiguration.apply()
319
301
workingtree.WorkingTree.open('repo')
320
302
repository.Repository.open('repo')
322
304
def test_unshared_repo_to_lightweight_checkout(self):
323
305
repo = self.make_repository('repo', shared=False)
324
self.make_branch('branch')
306
branch = self.make_branch('branch')
325
307
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
326
repo.controldir, 'branch')
308
repo.bzrdir, 'branch')
327
309
reconfiguration.apply()
328
310
workingtree.WorkingTree.open('repo')
329
311
self.assertRaises(errors.NoRepositoryPresent,
351
332
self.build_tree(['root/'])
352
333
tree = self.make_branch_and_tree('root/tree')
353
334
self.add_dead_head(tree)
354
tree.commit('Hello', rev_id=b'hello-id')
335
tree.commit('Hello', rev_id='hello-id')
355
336
repo = self.make_repository('root', shared=True)
356
reconfiguration = reconfigure.Reconfigure.to_use_shared(
337
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
358
338
reconfiguration.apply()
359
339
tree = workingtree.WorkingTree.open('root/tree')
360
message = repo.get_revision(b'dead-head-id').message
340
message = repo.get_revision('dead-head-id').message
361
341
self.assertEqual('Dead head', message)
363
343
def make_repository_tree(self):
364
344
self.build_tree(['root/'])
365
self.make_repository('root', shared=True)
345
repo = self.make_repository('root', shared=True)
366
346
tree = self.make_branch_and_tree('root/tree')
367
reconfigure.Reconfigure.to_use_shared(tree.controldir).apply()
347
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
368
348
return workingtree.WorkingTree.open('root/tree')
370
350
def test_use_shared_to_use_shared(self):
371
351
tree = self.make_repository_tree()
372
self.assertRaises(reconfigure.AlreadyUsingShared,
373
reconfigure.Reconfigure.to_use_shared, tree.controldir)
352
self.assertRaises(errors.AlreadyUsingShared,
353
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
375
355
def test_use_shared_to_standalone(self):
376
356
tree = self.make_repository_tree()
377
tree.commit('Hello', rev_id=b'hello-id')
378
reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
357
tree.commit('Hello', rev_id='hello-id')
358
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
379
359
tree = workingtree.WorkingTree.open('root/tree')
380
360
repo = tree.branch.repository
381
self.assertEqual(repo.controldir.root_transport.base,
382
tree.controldir.root_transport.base)
383
self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
361
self.assertEqual(repo.bzrdir.root_transport.base,
362
tree.bzrdir.root_transport.base)
363
self.assertEqual('Hello', repo.get_revision('hello-id').message)
385
365
def test_use_shared_to_standalone_preserves_dead_heads(self):
386
366
tree = self.make_repository_tree()
387
367
self.add_dead_head(tree)
388
tree.commit('Hello', rev_id=b'hello-id')
389
reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
368
tree.commit('Hello', rev_id='hello-id')
369
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
390
370
tree = workingtree.WorkingTree.open('root/tree')
391
371
repo = tree.branch.repository
392
372
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
395
375
def test_standalone_to_standalone(self):
396
376
tree = self.make_branch_and_tree('tree')
397
self.assertRaises(reconfigure.AlreadyStandalone,
398
reconfigure.Reconfigure.to_standalone, tree.controldir)
377
self.assertRaises(errors.AlreadyStandalone,
378
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
400
380
def make_unsynced_branch_reconfiguration(self):
401
381
parent = self.make_branch_and_tree('parent')
402
382
parent.commit('commit 1')
403
child = parent.controldir.sprout('child').open_workingtree()
383
child = parent.bzrdir.sprout('child').open_workingtree()
404
384
child.commit('commit 2')
405
return reconfigure.Reconfigure.to_lightweight_checkout(child.controldir)
385
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
407
387
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
408
388
reconfiguration = self.make_unsynced_branch_reconfiguration()
409
self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
389
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
411
391
def test_unsynced_branch_to_lightweight_checkout_forced(self):
412
392
reconfiguration = self.make_unsynced_branch_reconfiguration()
420
400
def test_make_with_trees(self):
421
401
repo = self.make_repository_with_without_trees(False)
422
402
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
423
repo.controldir, True)
424
404
reconfiguration.apply()
425
405
self.assertIs(True, repo.make_working_trees())
427
407
def test_make_without_trees(self):
428
408
repo = self.make_repository_with_without_trees(True)
429
409
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
430
repo.controldir, False)
431
411
reconfiguration.apply()
432
412
self.assertIs(False, repo.make_working_trees())
434
414
def test_make_with_trees_already_with_trees(self):
435
415
repo = self.make_repository_with_without_trees(True)
436
e = self.assertRaises(reconfigure.AlreadyWithTrees,
437
reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
416
e = self.assertRaises(errors.AlreadyWithTrees,
417
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
438
418
self.assertContainsRe(str(e),
439
r"Shared repository '.*' already creates working trees.")
419
r"Shared repository '.*' already creates working trees.")
441
421
def test_make_without_trees_already_no_trees(self):
442
422
repo = self.make_repository_with_without_trees(False)
443
e = self.assertRaises(
444
reconfigure.AlreadyWithNoTrees,
445
reconfigure.Reconfigure.set_repository_trees, repo.controldir,
447
self.assertContainsRe(
423
e = self.assertRaises(errors.AlreadyWithNoTrees,
424
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
425
self.assertContainsRe(str(e),
449
426
r"Shared repository '.*' already doesn't create working trees.")
451
428
def test_repository_tree_reconfiguration_not_supported(self):
452
429
tree = self.make_branch_and_tree('tree')
453
e = self.assertRaises(
454
reconfigure.ReconfigurationNotSupported,
455
reconfigure.Reconfigure.set_repository_trees, tree.controldir,
457
self.assertContainsRe(
458
str(e), r"Requested reconfiguration of '.*' is not supported.")
430
e = self.assertRaises(errors.ReconfigurationNotSupported,
431
reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
432
self.assertContainsRe(str(e),
433
r"Requested reconfiguration of '.*' is not supported.")
460
435
def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
461
format = controldir.format_registry.make_controldir('1.9')
462
format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
436
format = bzrdir.format_registry.make_bzrdir('1.9')
437
format.set_branch_format(_mod_branch.BzrBranchFormat8())
463
438
tree = self.make_branch_and_tree('tree', format=format)
464
tree.branch.set_reference_info(b'file_id', '../location', 'path')
439
tree.branch.set_reference_info('file_id', 'path', '../location')
465
440
checkout = tree.branch.create_checkout('checkout', lightweight=True)
466
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
441
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
467
442
reconfiguration.apply()
468
checkout_branch = checkout.controldir.open_branch()
469
self.assertEqual(('../location', 'path'),
470
checkout_branch.get_reference_info(b'file_id'))
443
checkout_branch = checkout.bzrdir.open_branch()
444
self.assertEqual(('path', '../location'),
445
checkout_branch.get_reference_info('file_id'))