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