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