60
60
reconfiguration.apply()
61
61
self.assertIs(None, checkout.branch.get_bound_location())
63
def prepare_lightweight_checkout_to_branch(self):
63
def test_lightweight_checkout_to_branch(self):
64
64
branch = self.make_branch('branch')
65
65
checkout = branch.create_checkout('checkout', lightweight=True)
66
66
checkout.commit('first commit', rev_id='rev1')
67
67
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
68
return reconfiguration, checkout
70
def test_lightweight_checkout_to_branch(self):
71
reconfiguration, checkout = \
72
self.prepare_lightweight_checkout_to_branch()
73
68
reconfiguration.apply()
74
69
checkout_branch = checkout.bzrdir.open_branch()
75
70
self.assertEqual(checkout_branch.bzrdir.root_transport.base,
78
73
repo = checkout.bzrdir.open_repository()
79
74
repo.get_revision('rev1')
81
def test_lightweight_checkout_to_branch_tags(self):
82
reconfiguration, checkout = \
83
self.prepare_lightweight_checkout_to_branch()
84
checkout.branch.tags.set_tag('foo', 'bar')
85
reconfiguration.apply()
86
checkout_branch = checkout.bzrdir.open_branch()
87
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
89
def prepare_lightweight_checkout_to_checkout(self):
76
def test_lightweight_checkout_to_checkout(self):
90
77
branch = self.make_branch('branch')
91
78
checkout = branch.create_checkout('checkout', lightweight=True)
92
79
reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
93
return reconfiguration, checkout
95
def test_lightweight_checkout_to_checkout(self):
96
reconfiguration, checkout = \
97
self.prepare_lightweight_checkout_to_checkout()
98
80
reconfiguration.apply()
99
81
checkout_branch = checkout.bzrdir.open_branch()
100
82
self.assertIsNot(checkout_branch.get_bound_location(), None)
102
def test_lightweight_checkout_to_checkout_tags(self):
103
reconfiguration, checkout = \
104
self.prepare_lightweight_checkout_to_checkout()
105
checkout.branch.tags.set_tag('foo', 'bar')
106
reconfiguration.apply()
107
checkout_branch = checkout.bzrdir.open_branch()
108
self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
110
84
def test_lightweight_conversion_uses_shared_repo(self):
111
85
parent = self.make_branch('parent')
112
86
shared_repo = self.make_repository('repo', shared=True)
197
171
self.assertRaises(errors.AlreadyCheckout,
198
172
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
200
def make_unsynced_checkout(self):
174
def test_checkout_to_lightweight(self):
201
175
parent = self.make_branch('parent')
202
176
checkout = parent.create_checkout('checkout')
203
177
checkout.commit('test', rev_id='new-commit', local=True)
204
178
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
206
return checkout, parent, reconfiguration
208
def test_unsynced_checkout_to_lightweight(self):
209
checkout, parent, reconfiguration = self.make_unsynced_checkout()
210
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
212
def test_synced_checkout_to_lightweight(self):
213
checkout, parent, reconfiguration = self.make_unsynced_checkout()
214
parent.pull(checkout.branch)
215
180
reconfiguration.apply()
216
181
wt = checkout.bzrdir.open_workingtree()
217
182
self.assertTrue(parent.repository.has_same_location(
220
185
self.assertRaises(errors.NoRepositoryPresent,
221
186
checkout.bzrdir.open_repository)
223
def prepare_branch_to_lightweight_checkout(self):
188
def test_branch_to_lightweight_checkout(self):
224
189
parent = self.make_branch('parent')
225
190
child = parent.bzrdir.sprout('child').open_workingtree()
226
191
child.commit('test', rev_id='new-commit')
227
parent.pull(child.branch)
228
192
child.bzrdir.destroy_workingtree()
229
193
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
231
return parent, child, reconfiguration
233
def test_branch_to_lightweight_checkout(self):
234
parent, child, reconfiguration = \
235
self.prepare_branch_to_lightweight_checkout()
236
195
reconfiguration.apply()
237
self.assertTrue(reconfiguration._destroy_branch)
238
196
wt = child.bzrdir.open_workingtree()
239
197
self.assertTrue(parent.repository.has_same_location(
240
198
wt.branch.repository))
242
200
self.assertRaises(errors.NoRepositoryPresent,
243
201
child.bzrdir.open_repository)
245
def test_branch_to_lightweight_checkout_failure(self):
246
parent, child, reconfiguration = \
247
self.prepare_branch_to_lightweight_checkout()
248
old_Repository_fetch = repository.Repository.fetch
249
repository.Repository.fetch = None
251
self.assertRaises(TypeError, reconfiguration.apply)
253
repository.Repository.fetch = old_Repository_fetch
254
child = _mod_branch.Branch.open('child')
255
self.assertContainsRe(child.base, 'child/$')
257
def test_branch_to_lightweight_checkout_fetch_tags(self):
258
parent, child, reconfiguration = \
259
self.prepare_branch_to_lightweight_checkout()
260
child.branch.tags.set_tag('foo', 'bar')
261
reconfiguration.apply()
262
child = _mod_branch.Branch.open('child')
263
self.assertEqual('bar', parent.tags.lookup_tag('foo'))
265
203
def test_lightweight_checkout_to_lightweight_checkout(self):
266
204
parent = self.make_branch('parent')
267
205
checkout = parent.create_checkout('checkout', lightweight=True)
296
234
workingtree.WorkingTree.open('repo')
297
235
self.assertRaises(errors.NoRepositoryPresent,
298
236
repository.Repository.open, 'repo')
300
def test_standalone_to_use_shared(self):
301
self.build_tree(['root/'])
302
tree = self.make_branch_and_tree('root/tree')
303
tree.commit('Hello', rev_id='hello-id')
304
repo = self.make_repository('root', shared=True)
305
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
306
reconfiguration.apply()
307
tree = workingtree.WorkingTree.open('root/tree')
308
self.assertTrue(repo.has_same_location(tree.branch.repository))
309
self.assertEqual('Hello', repo.get_revision('hello-id').message)
311
def add_dead_head(self, tree):
312
revno, revision_id = tree.branch.last_revision_info()
313
tree.commit('Dead head', rev_id='dead-head-id')
314
tree.branch.set_last_revision_info(revno, revision_id)
315
tree.set_last_revision(revision_id)
317
def test_standalone_to_use_shared_preserves_dead_heads(self):
318
self.build_tree(['root/'])
319
tree = self.make_branch_and_tree('root/tree')
320
self.add_dead_head(tree)
321
tree.commit('Hello', rev_id='hello-id')
322
repo = self.make_repository('root', shared=True)
323
reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
324
reconfiguration.apply()
325
tree = workingtree.WorkingTree.open('root/tree')
326
message = repo.get_revision('dead-head-id').message
327
self.assertEqual('Dead head', message)
329
def make_repository_tree(self):
330
self.build_tree(['root/'])
331
repo = self.make_repository('root', shared=True)
332
tree = self.make_branch_and_tree('root/tree')
333
reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
334
return workingtree.WorkingTree.open('root/tree')
336
def test_use_shared_to_use_shared(self):
337
tree = self.make_repository_tree()
338
self.assertRaises(errors.AlreadyUsingShared,
339
reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
341
def test_use_shared_to_standalone(self):
342
tree = self.make_repository_tree()
343
tree.commit('Hello', rev_id='hello-id')
344
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
345
tree = workingtree.WorkingTree.open('root/tree')
346
repo = tree.branch.repository
347
self.assertEqual(repo.bzrdir.root_transport.base,
348
tree.bzrdir.root_transport.base)
349
self.assertEqual('Hello', repo.get_revision('hello-id').message)
351
def test_use_shared_to_standalone_preserves_dead_heads(self):
352
tree = self.make_repository_tree()
353
self.add_dead_head(tree)
354
tree.commit('Hello', rev_id='hello-id')
355
reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
356
tree = workingtree.WorkingTree.open('root/tree')
357
repo = tree.branch.repository
358
self.assertRaises(errors.NoSuchRevision, repo.get_revision,
361
def test_standalone_to_standalone(self):
362
tree = self.make_branch_and_tree('tree')
363
self.assertRaises(errors.AlreadyStandalone,
364
reconfigure.Reconfigure.to_standalone, tree.bzrdir)
366
def make_unsynced_branch_reconfiguration(self):
367
parent = self.make_branch_and_tree('parent')
368
parent.commit('commit 1')
369
child = parent.bzrdir.sprout('child').open_workingtree()
370
child.commit('commit 2')
371
return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
373
def test_unsynced_branch_to_lightweight_checkout_unforced(self):
374
reconfiguration = self.make_unsynced_branch_reconfiguration()
375
self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
377
def test_unsynced_branch_to_lightweight_checkout_forced(self):
378
reconfiguration = self.make_unsynced_branch_reconfiguration()
379
reconfiguration.apply(force=True)