69
76
def test_unexpected_prompt_failure(self):
70
77
tree = self.create_shelvable_tree()
78
tree.lock_tree_write()
79
self.addCleanup(tree.unlock)
71
80
shelver = ExpectShelver(tree, tree.basis_tree())
81
self.addCleanup(shelver.finalize)
72
82
e = self.assertRaises(AssertionError, shelver.run)
73
83
self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
75
85
def test_wrong_prompt_failure(self):
76
86
tree = self.create_shelvable_tree()
87
tree.lock_tree_write()
88
self.addCleanup(tree.unlock)
77
89
shelver = ExpectShelver(tree, tree.basis_tree())
90
self.addCleanup(shelver.finalize)
78
91
shelver.expect('foo', 'y')
79
92
e = self.assertRaises(AssertionError, shelver.run)
80
93
self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
82
95
def test_shelve_not_diff(self):
83
96
tree = self.create_shelvable_tree()
97
tree.lock_tree_write()
98
self.addCleanup(tree.unlock)
84
99
shelver = ExpectShelver(tree, tree.basis_tree())
100
self.addCleanup(shelver.finalize)
85
101
shelver.expect('Shelve? [yNfq?]', 'n')
86
102
shelver.expect('Shelve? [yNfq?]', 'n')
87
103
# No final shelving prompt because no changes were selected
190
236
def test_shelve_quit(self):
191
237
tree = self.create_shelvable_tree()
238
tree.lock_tree_write()
239
self.addCleanup(tree.unlock)
192
240
shelver = ExpectShelver(tree, tree.basis_tree())
241
self.addCleanup(shelver.finalize)
193
242
shelver.expect('Shelve? [yNfq?]', 'q')
194
243
self.assertRaises(errors.UserAbort, shelver.run)
195
244
self.assertFileEqual(LINES_ZY, 'tree/foo')
197
246
def test_shelve_all(self):
198
247
tree = self.create_shelvable_tree()
199
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
248
shelver = ExpectShelver.from_args(sys.stdout, all=True,
200
254
self.assertFileEqual(LINES_AJ, 'tree/foo')
202
256
def test_shelve_filename(self):
203
257
tree = self.create_shelvable_tree()
204
258
self.build_tree(['tree/bar'])
260
tree.lock_tree_write()
261
self.addCleanup(tree.unlock)
206
262
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
263
self.addCleanup(shelver.finalize)
207
264
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
208
265
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
211
268
def test_shelve_help(self):
212
269
tree = self.create_shelvable_tree()
270
tree.lock_tree_write()
271
self.addCleanup(tree.unlock)
213
272
shelver = ExpectShelver(tree, tree.basis_tree())
273
self.addCleanup(shelver.finalize)
214
274
shelver.expect('Shelve? [yNfq?]', '?')
215
275
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
216
276
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
219
def test_shelve_distroy(self):
279
def test_shelve_destroy(self):
220
280
tree = self.create_shelvable_tree()
221
281
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
222
282
directory='tree', destroy=True)
283
self.addCleanup(shelver.finalize)
224
285
self.assertIs(None, tree.get_shelf_manager().last_shelf())
225
286
self.assertFileEqual(LINES_AJ, 'tree/foo')
289
def shelve_all(tree, target_revision_id):
292
target = tree.branch.repository.revision_tree(target_revision_id)
293
shelver = shelf_ui.Shelver(tree, target, auto=True,
302
def test_shelve_old_root_deleted(self):
303
tree1 = self.make_branch_and_tree('tree1')
304
tree1.commit('add root')
305
tree2 = self.make_branch_and_tree('tree2')
306
rev2 = tree2.commit('add root')
307
tree1.merge_from_branch(tree2.branch,
308
from_revision=revision.NULL_REVISION)
309
tree1.commit('Replaced root entry')
310
# This is essentially assertNotRaises(InconsistentDelta)
311
self.expectFailure('Cannot shelve replacing a root entry',
312
self.assertRaises, AssertionError,
313
self.assertRaises, errors.InconsistentDelta,
314
self.shelve_all, tree1, rev2)
316
def test_shelve_split(self):
317
outer_tree = self.make_branch_and_tree('outer')
318
outer_tree.commit('Add root')
319
inner_tree = self.make_branch_and_tree('outer/inner')
320
rev2 = inner_tree.commit('Add root')
321
outer_tree.subsume(inner_tree)
322
# This is essentially assertNotRaises(ValueError).
323
# The ValueError is 'None is not a valid file id'.
324
self.expectFailure('Cannot shelve a join back to the inner tree.',
325
self.assertRaises, AssertionError,
326
self.assertRaises, ValueError, self.shelve_all,
228
330
class TestApplyReporter(TestShelver):
230
332
def test_shelve_not_diff(self):
231
333
tree = self.create_shelvable_tree()
334
tree.lock_tree_write()
335
self.addCleanup(tree.unlock)
232
336
shelver = ExpectShelver(tree, tree.basis_tree(),
233
337
reporter=shelf_ui.ApplyReporter())
338
self.addCleanup(shelver.finalize)
234
339
shelver.expect('Apply change? [yNfq?]', 'n')
235
340
shelver.expect('Apply change? [yNfq?]', 'n')
236
341
# No final shelving prompt because no changes were selected
332
461
def create_tree_with_shelf(self):
333
462
tree = self.make_branch_and_tree('tree')
334
self.build_tree_contents([('tree/foo', LINES_AJ)])
335
tree.add('foo', 'foo-id')
336
tree.commit('added foo')
337
self.build_tree_contents([('tree/foo', LINES_ZY)])
338
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
465
self.build_tree_contents([('tree/foo', LINES_AJ)])
466
tree.add('foo', 'foo-id')
467
tree.commit('added foo')
468
self.build_tree_contents([('tree/foo', LINES_ZY)])
469
shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
470
auto_apply=True, auto=True)
342
479
def test_unshelve(self):
350
487
def test_unshelve_args(self):
351
488
tree = self.create_tree_with_shelf()
352
shelf_ui.Unshelver.from_args(directory='tree').run()
489
unshelver = shelf_ui.Unshelver.from_args(directory='tree')
493
unshelver.tree.unlock()
353
494
self.assertFileEqual(LINES_ZY, 'tree/foo')
354
495
self.assertIs(None, tree.get_shelf_manager().last_shelf())
356
497
def test_unshelve_args_dry_run(self):
357
498
tree = self.create_tree_with_shelf()
358
shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
359
self.assertFileEqual(LINES_AJ, 'tree/foo')
360
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
499
unshelver = shelf_ui.Unshelver.from_args(directory='tree',
504
unshelver.tree.unlock()
505
self.assertFileEqual(LINES_AJ, 'tree/foo')
506
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
508
def test_unshelve_args_preview(self):
509
tree = self.create_tree_with_shelf()
510
write_diff_to = StringIO()
511
unshelver = shelf_ui.Unshelver.from_args(
512
directory='tree', action='preview', write_diff_to=write_diff_to)
516
unshelver.tree.unlock()
517
# The changes were not unshelved.
518
self.assertFileEqual(LINES_AJ, 'tree/foo')
519
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
521
# But the diff was written to write_diff_to.
522
diff = write_diff_to.getvalue()
523
expected = dedent("""\
538
self.assertEqualDiff(expected, diff[-len(expected):])
362
540
def test_unshelve_args_delete_only(self):
363
541
tree = self.make_branch_and_tree('tree')
383
564
self.assertRaises(errors.InvalidShelfId,
384
565
shelf_ui.Unshelver.from_args, directory='tree',
385
566
action='delete-only', shelf_id='foo')
569
class TestUnshelveScripts(TestUnshelver,
570
script.TestCaseWithTransportAndScript):
572
def test_unshelve_messages_keep(self):
573
self.create_tree_with_shelf()
576
$ bzr unshelve --keep
577
2>Using changes with id "1".
579
2>All changes applied successfully.
582
def test_unshelve_messages_delete(self):
583
self.create_tree_with_shelf()
586
$ bzr unshelve --delete-only
587
2>Deleted changes with id "1".
590
def test_unshelve_messages_apply(self):
591
self.create_tree_with_shelf()
594
$ bzr unshelve --apply
595
2>Using changes with id "1".
597
2>All changes applied successfully.
598
2>Deleted changes with id "1".
601
def test_unshelve_messages_dry_run(self):
602
self.create_tree_with_shelf()
605
$ bzr unshelve --dry-run
606
2>Using changes with id "1".