198
144
reconfiguration.apply()
200
def test_tree_to_lightweight_checkout(self):
201
# A tree with no related branches and no supplied bind location cannot
203
parent = self.make_branch('parent')
205
tree = self.make_branch_and_tree('tree')
206
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
208
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
209
# setting a parent allows it to become a checkout
210
tree.branch.set_parent(parent.base)
211
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
213
reconfiguration.apply()
214
# supplying a location allows it to become a checkout
215
tree2 = self.make_branch_and_tree('tree2')
216
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
217
tree2.bzrdir, parent.base)
218
reconfiguration.apply()
220
146
def test_checkout_to_checkout(self):
221
147
parent = self.make_branch('parent')
222
148
checkout = parent.create_checkout('checkout')
223
149
self.assertRaises(errors.AlreadyCheckout,
224
150
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
226
def make_unsynced_checkout(self):
227
parent = self.make_branch('parent')
228
checkout = parent.create_checkout('checkout')
229
checkout.commit('test', rev_id='new-commit', local=True)
230
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
232
return checkout, parent, reconfiguration
234
def test_unsynced_checkout_to_lightweight(self):
235
checkout, parent, reconfiguration = self.make_unsynced_checkout()
236
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
238
def test_synced_checkout_to_lightweight(self):
239
checkout, parent, reconfiguration = self.make_unsynced_checkout()
240
parent.pull(checkout.branch)
241
reconfiguration.apply()
242
wt = checkout.bzrdir.open_workingtree()
243
self.assertTrue(parent.repository.has_same_location(
244
wt.branch.repository))
245
parent.repository.get_revision('new-commit')
246
self.assertRaises(errors.NoRepositoryPresent,
247
checkout.bzrdir.open_repository)
249
def prepare_branch_to_lightweight_checkout(self):
250
parent = self.make_branch('parent')
251
child = parent.bzrdir.sprout('child').open_workingtree()
252
child.commit('test', rev_id='new-commit')
253
parent.pull(child.branch)
254
child.bzrdir.destroy_workingtree()
255
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
257
return parent, child, reconfiguration
259
def test_branch_to_lightweight_checkout(self):
260
parent, child, reconfiguration = \
261
self.prepare_branch_to_lightweight_checkout()
262
reconfiguration.apply()
263
self.assertTrue(reconfiguration._destroy_branch)
264
wt = child.bzrdir.open_workingtree()
265
self.assertTrue(parent.repository.has_same_location(
266
wt.branch.repository))
267
parent.repository.get_revision('new-commit')
268
self.assertRaises(errors.NoRepositoryPresent,
269
child.bzrdir.open_repository)
271
def test_branch_to_lightweight_checkout_failure(self):
272
parent, child, reconfiguration = \
273
self.prepare_branch_to_lightweight_checkout()
274
old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
275
vf_repository.VersionedFileRepository.fetch = None
277
self.assertRaises(TypeError, reconfiguration.apply)
279
vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
280
child = _mod_branch.Branch.open('child')
281
self.assertContainsRe(child.base, 'child/$')
283
def test_branch_to_lightweight_checkout_fetch_tags(self):
284
parent, child, reconfiguration = \
285
self.prepare_branch_to_lightweight_checkout()
286
child.branch.tags.set_tag('foo', 'bar')
287
reconfiguration.apply()
288
child = _mod_branch.Branch.open('child')
289
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
291
def test_lightweight_checkout_to_lightweight_checkout(self):
292
parent = self.make_branch('parent')
293
checkout = parent.create_checkout('checkout', lightweight=True)
294
self.assertRaises(errors.AlreadyLightweightCheckout,
295
reconfigure.Reconfigure.to_lightweight_checkout,
298
def test_repo_to_tree(self):
299
repo = self.make_repository('repo')
300
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
301
reconfiguration.apply()
302
workingtree.WorkingTree.open('repo')
304
def test_shared_repo_to_lightweight_checkout(self):
305
repo = self.make_repository('repo', shared=True)
306
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
308
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
309
branch = self.make_branch('branch')
310
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
311
repo.bzrdir, 'branch')
312
reconfiguration.apply()
313
workingtree.WorkingTree.open('repo')
314
repository.Repository.open('repo')
316
def test_unshared_repo_to_lightweight_checkout(self):
317
repo = self.make_repository('repo', shared=False)
318
branch = self.make_branch('branch')
319
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
320
repo.bzrdir, 'branch')
321
reconfiguration.apply()
322
workingtree.WorkingTree.open('repo')
323
self.assertRaises(errors.NoRepositoryPresent,
324
repository.Repository.open, 'repo')
326
def test_standalone_to_use_shared(self):
327
self.build_tree(['root/'])
328
tree = self.make_branch_and_tree('root/tree')
329
tree.commit('Hello', rev_id='hello-id')
330
repo = self.make_repository('root', shared=True)
331
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
332
reconfiguration.apply()
333
tree = workingtree.WorkingTree.open('root/tree')
334
self.assertTrue(repo.has_same_location(tree.branch.repository))
335
self.assertEqual('Hello', repo.get_revision('hello-id').message)
337
def add_dead_head(self, tree):
338
revno, revision_id = tree.branch.last_revision_info()
339
tree.commit('Dead head', rev_id='dead-head-id')
340
tree.branch.set_last_revision_info(revno, revision_id)
341
tree.set_last_revision(revision_id)
343
def test_standalone_to_use_shared_preserves_dead_heads(self):
344
self.build_tree(['root/'])
345
tree = self.make_branch_and_tree('root/tree')
346
self.add_dead_head(tree)
347
tree.commit('Hello', rev_id='hello-id')
348
repo = self.make_repository('root', shared=True)
349
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
350
reconfiguration.apply()
351
tree = workingtree.WorkingTree.open('root/tree')
352
message = repo.get_revision('dead-head-id').message
353
self.assertEqual('Dead head', message)
355
def make_repository_tree(self):
356
self.build_tree(['root/'])
357
repo = self.make_repository('root', shared=True)
358
tree = self.make_branch_and_tree('root/tree')
359
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
360
return workingtree.WorkingTree.open('root/tree')
362
def test_use_shared_to_use_shared(self):
363
tree = self.make_repository_tree()
364
self.assertRaises(errors.AlreadyUsingShared,
365
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
367
def test_use_shared_to_standalone(self):
368
tree = self.make_repository_tree()
369
tree.commit('Hello', rev_id='hello-id')
370
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
371
tree = workingtree.WorkingTree.open('root/tree')
372
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)
377
def test_use_shared_to_standalone_preserves_dead_heads(self):
378
tree = self.make_repository_tree()
379
self.add_dead_head(tree)
380
tree.commit('Hello', rev_id='hello-id')
381
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
382
tree = workingtree.WorkingTree.open('root/tree')
383
repo = tree.branch.repository
384
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
387
def test_standalone_to_standalone(self):
388
tree = self.make_branch_and_tree('tree')
389
self.assertRaises(errors.AlreadyStandalone,
390
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
392
def make_unsynced_branch_reconfiguration(self):
393
parent = self.make_branch_and_tree('parent')
394
parent.commit('commit 1')
395
child = parent.bzrdir.sprout('child').open_workingtree()
396
child.commit('commit 2')
397
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
399
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
400
reconfiguration = self.make_unsynced_branch_reconfiguration()
401
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
403
def test_unsynced_branch_to_lightweight_checkout_forced(self):
404
reconfiguration = self.make_unsynced_branch_reconfiguration()
405
reconfiguration.apply(force=True)
407
def make_repository_with_without_trees(self, with_trees):
408
repo = self.make_repository('repo', shared=True)
409
repo.set_make_working_trees(with_trees)
412
def test_make_with_trees(self):
413
repo = self.make_repository_with_without_trees(False)
414
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
416
reconfiguration.apply()
417
self.assertIs(True, repo.make_working_trees())
419
def test_make_without_trees(self):
420
repo = self.make_repository_with_without_trees(True)
421
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
423
reconfiguration.apply()
424
self.assertIs(False, repo.make_working_trees())
426
def test_make_with_trees_already_with_trees(self):
427
repo = self.make_repository_with_without_trees(True)
428
e = self.assertRaises(errors.AlreadyWithTrees,
429
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
430
self.assertContainsRe(str(e),
431
r"Shared repository '.*' already creates working trees.")
433
def test_make_without_trees_already_no_trees(self):
434
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),
438
r"Shared repository '.*' already doesn't create working trees.")
440
def test_repository_tree_reconfiguration_not_supported(self):
441
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.")
447
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())
450
tree = self.make_branch_and_tree('tree', format=format)
451
tree.branch.set_reference_info('file_id', 'path', '../location')
452
checkout = tree.branch.create_checkout('checkout', lightweight=True)
453
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
454
reconfiguration.apply()
455
checkout_branch = checkout.bzrdir.open_branch()
456
self.assertEqual(('path', '../location'),
457
checkout_branch.get_reference_info('file_id'))