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