92
72
repo = checkout.bzrdir.open_repository()
93
73
repo.get_revision('rev1')
95
def test_lightweight_checkout_to_branch_tags(self):
96
reconfiguration, checkout = \
97
self.prepare_lightweight_checkout_to_branch()
98
checkout.branch.tags.set_tag('foo', 'bar')
99
reconfiguration.apply()
100
checkout_branch = checkout.bzrdir.open_branch()
101
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
103
def prepare_lightweight_checkout_to_checkout(self):
75
def test_lightweight_checkout_to_checkout(self):
104
76
branch = self.make_branch('branch')
105
77
checkout = branch.create_checkout('checkout', lightweight=True)
106
78
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
107
return reconfiguration, checkout
109
def test_lightweight_checkout_to_checkout(self):
110
reconfiguration, checkout = \
111
self.prepare_lightweight_checkout_to_checkout()
112
79
reconfiguration.apply()
113
80
checkout_branch = checkout.bzrdir.open_branch()
114
81
self.assertIsNot(checkout_branch.get_bound_location(), None)
116
def test_lightweight_checkout_to_checkout_tags(self):
117
reconfiguration, checkout = \
118
self.prepare_lightweight_checkout_to_checkout()
119
checkout.branch.tags.set_tag('foo', 'bar')
120
reconfiguration.apply()
121
checkout_branch = checkout.bzrdir.open_branch()
122
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
124
83
def test_lightweight_conversion_uses_shared_repo(self):
125
84
parent = self.make_branch('parent')
126
85
shared_repo = self.make_repository('repo', shared=True)
188
147
reconfiguration.apply()
190
def test_tree_to_lightweight_checkout(self):
191
# A tree with no related branches and no supplied bind location cannot
193
parent = self.make_branch('parent')
195
tree = self.make_branch_and_tree('tree')
196
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
198
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
199
# setting a parent allows it to become a checkout
200
tree.branch.set_parent(parent.base)
201
reconfiguration.apply()
202
# supplying a location allows it to become a checkout
203
tree2 = self.make_branch_and_tree('tree2')
204
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
205
tree2.bzrdir, parent.base)
206
reconfiguration.apply()
208
149
def test_checkout_to_checkout(self):
209
150
parent = self.make_branch('parent')
210
151
checkout = parent.create_checkout('checkout')
211
152
self.assertRaises(errors.AlreadyCheckout,
212
153
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
214
def make_unsynced_checkout(self):
155
def test_checkout_to_lightweight(self):
215
156
parent = self.make_branch('parent')
216
157
checkout = parent.create_checkout('checkout')
217
158
checkout.commit('test', rev_id='new-commit', local=True)
218
159
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
220
return checkout, parent, reconfiguration
222
def test_unsynced_checkout_to_lightweight(self):
223
checkout, parent, reconfiguration = self.make_unsynced_checkout()
224
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
226
def test_synced_checkout_to_lightweight(self):
227
checkout, parent, reconfiguration = self.make_unsynced_checkout()
228
parent.pull(checkout.branch)
229
161
reconfiguration.apply()
230
162
wt = checkout.bzrdir.open_workingtree()
231
163
self.assertTrue(parent.repository.has_same_location(
256
181
self.assertRaises(errors.NoRepositoryPresent,
257
182
child.bzrdir.open_repository)
259
def test_branch_to_lightweight_checkout_failure(self):
260
parent, child, reconfiguration = \
261
self.prepare_branch_to_lightweight_checkout()
262
old_Repository_fetch = repository.Repository.fetch
263
repository.Repository.fetch = None
265
self.assertRaises(TypeError, reconfiguration.apply)
267
repository.Repository.fetch = old_Repository_fetch
268
child = _mod_branch.Branch.open('child')
269
self.assertContainsRe(child.base, 'child/$')
271
def test_branch_to_lightweight_checkout_fetch_tags(self):
272
parent, child, reconfiguration = \
273
self.prepare_branch_to_lightweight_checkout()
274
child.branch.tags.set_tag('foo', 'bar')
275
reconfiguration.apply()
276
child = _mod_branch.Branch.open('child')
277
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
279
184
def test_lightweight_checkout_to_lightweight_checkout(self):
280
185
parent = self.make_branch('parent')
281
186
checkout = parent.create_checkout('checkout', lightweight=True)
282
187
self.assertRaises(errors.AlreadyLightweightCheckout,
283
188
reconfigure.Reconfigure.to_lightweight_checkout,
286
def test_repo_to_tree(self):
287
repo = self.make_repository('repo')
288
reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
289
reconfiguration.apply()
290
workingtree.WorkingTree.open('repo')
292
def test_shared_repo_to_lightweight_checkout(self):
293
repo = self.make_repository('repo', shared=True)
294
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
296
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
297
branch = self.make_branch('branch')
298
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
299
repo.bzrdir, 'branch')
300
reconfiguration.apply()
301
workingtree.WorkingTree.open('repo')
302
repository.Repository.open('repo')
304
def test_unshared_repo_to_lightweight_checkout(self):
305
repo = self.make_repository('repo', shared=False)
306
branch = self.make_branch('branch')
307
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
308
repo.bzrdir, 'branch')
309
reconfiguration.apply()
310
workingtree.WorkingTree.open('repo')
311
self.assertRaises(errors.NoRepositoryPresent,
312
repository.Repository.open, 'repo')
314
def test_standalone_to_use_shared(self):
315
self.build_tree(['root/'])
316
tree = self.make_branch_and_tree('root/tree')
317
tree.commit('Hello', rev_id='hello-id')
318
repo = self.make_repository('root', shared=True)
319
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
320
reconfiguration.apply()
321
tree = workingtree.WorkingTree.open('root/tree')
322
self.assertTrue(repo.has_same_location(tree.branch.repository))
323
self.assertEqual('Hello', repo.get_revision('hello-id').message)
325
def add_dead_head(self, tree):
326
revno, revision_id = tree.branch.last_revision_info()
327
tree.commit('Dead head', rev_id='dead-head-id')
328
tree.branch.set_last_revision_info(revno, revision_id)
329
tree.set_last_revision(revision_id)
331
def test_standalone_to_use_shared_preserves_dead_heads(self):
332
self.build_tree(['root/'])
333
tree = self.make_branch_and_tree('root/tree')
334
self.add_dead_head(tree)
335
tree.commit('Hello', rev_id='hello-id')
336
repo = self.make_repository('root', shared=True)
337
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
338
reconfiguration.apply()
339
tree = workingtree.WorkingTree.open('root/tree')
340
message = repo.get_revision('dead-head-id').message
341
self.assertEqual('Dead head', message)
343
def make_repository_tree(self):
344
self.build_tree(['root/'])
345
repo = self.make_repository('root', shared=True)
346
tree = self.make_branch_and_tree('root/tree')
347
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
348
return workingtree.WorkingTree.open('root/tree')
350
def test_use_shared_to_use_shared(self):
351
tree = self.make_repository_tree()
352
self.assertRaises(errors.AlreadyUsingShared,
353
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
355
def test_use_shared_to_standalone(self):
356
tree = self.make_repository_tree()
357
tree.commit('Hello', rev_id='hello-id')
358
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
359
tree = workingtree.WorkingTree.open('root/tree')
360
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)
365
def test_use_shared_to_standalone_preserves_dead_heads(self):
366
tree = self.make_repository_tree()
367
self.add_dead_head(tree)
368
tree.commit('Hello', rev_id='hello-id')
369
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
370
tree = workingtree.WorkingTree.open('root/tree')
371
repo = tree.branch.repository
372
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
375
def test_standalone_to_standalone(self):
376
tree = self.make_branch_and_tree('tree')
377
self.assertRaises(errors.AlreadyStandalone,
378
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
380
def make_unsynced_branch_reconfiguration(self):
381
parent = self.make_branch_and_tree('parent')
382
parent.commit('commit 1')
383
child = parent.bzrdir.sprout('child').open_workingtree()
384
child.commit('commit 2')
385
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
387
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
388
reconfiguration = self.make_unsynced_branch_reconfiguration()
389
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
391
def test_unsynced_branch_to_lightweight_checkout_forced(self):
392
reconfiguration = self.make_unsynced_branch_reconfiguration()
393
reconfiguration.apply(force=True)
395
def make_repository_with_without_trees(self, with_trees):
396
repo = self.make_repository('repo', shared=True)
397
repo.set_make_working_trees(with_trees)
400
def test_make_with_trees(self):
401
repo = self.make_repository_with_without_trees(False)
402
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
404
reconfiguration.apply()
405
self.assertIs(True, repo.make_working_trees())
407
def test_make_without_trees(self):
408
repo = self.make_repository_with_without_trees(True)
409
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
411
reconfiguration.apply()
412
self.assertIs(False, repo.make_working_trees())
414
def test_make_with_trees_already_with_trees(self):
415
repo = self.make_repository_with_without_trees(True)
416
e = self.assertRaises(errors.AlreadyWithTrees,
417
reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
418
self.assertContainsRe(str(e),
419
r"Shared repository '.*' already creates working trees.")
421
def test_make_without_trees_already_no_trees(self):
422
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),
426
r"Shared repository '.*' already doesn't create working trees.")
428
def test_repository_tree_reconfiguration_not_supported(self):
429
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.")
435
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())
438
tree = self.make_branch_and_tree('tree', format=format)
439
tree.branch.set_reference_info('file_id', 'path', '../location')
440
checkout = tree.branch.create_checkout('checkout', lightweight=True)
441
reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
442
reconfiguration.apply()
443
checkout_branch = checkout.bzrdir.open_branch()
444
self.assertEqual(('path', '../location'),
445
checkout_branch.get_reference_info('file_id'))