242
189
def test_shelve_quit(self):
243
190
tree = self.create_shelvable_tree()
244
tree.lock_tree_write()
245
self.addCleanup(tree.unlock)
246
191
shelver = ExpectShelver(tree, tree.basis_tree())
247
self.addCleanup(shelver.finalize)
248
192
shelver.expect('Shelve? [yNfq?]', 'q')
249
193
self.assertRaises(errors.UserAbort, shelver.run)
250
194
self.assertFileEqual(LINES_ZY, 'tree/foo')
252
196
def test_shelve_all(self):
253
197
tree = self.create_shelvable_tree()
254
shelver = ExpectShelver.from_args(sys.stdout, all=True,
198
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
260
199
self.assertFileEqual(LINES_AJ, 'tree/foo')
262
201
def test_shelve_filename(self):
263
202
tree = self.create_shelvable_tree()
264
203
self.build_tree(['tree/bar'])
266
tree.lock_tree_write()
267
self.addCleanup(tree.unlock)
268
205
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
269
self.addCleanup(shelver.finalize)
270
206
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
271
207
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
274
210
def test_shelve_help(self):
275
211
tree = self.create_shelvable_tree()
276
tree.lock_tree_write()
277
self.addCleanup(tree.unlock)
278
212
shelver = ExpectShelver(tree, tree.basis_tree())
279
self.addCleanup(shelver.finalize)
280
213
shelver.expect('Shelve? [yNfq?]', '?')
281
214
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
282
215
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
285
def test_shelve_destroy(self):
218
def test_shelve_distroy(self):
286
219
tree = self.create_shelvable_tree()
287
220
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
288
221
directory='tree', destroy=True)
289
self.addCleanup(shelver.finalize)
291
223
self.assertIs(None, tree.get_shelf_manager().last_shelf())
292
224
self.assertFileEqual(LINES_AJ, 'tree/foo')
295
def shelve_all(tree, target_revision_id):
298
target = tree.branch.repository.revision_tree(target_revision_id)
299
shelver = shelf_ui.Shelver(tree, target, auto=True,
308
def test_shelve_old_root_preserved(self):
309
tree1 = self.make_branch_and_tree('tree1')
310
tree1.commit('add root')
311
tree1_root_id = tree1.get_root_id()
312
tree2 = self.make_branch_and_tree('tree2')
313
rev2 = tree2.commit('add root')
314
self.assertNotEquals(tree1_root_id, tree2.get_root_id())
315
tree1.merge_from_branch(tree2.branch,
316
from_revision=revision.NULL_REVISION)
317
tree1.commit('merging in tree2')
318
self.assertEquals(tree1_root_id, tree1.get_root_id())
319
# This is essentially assertNotRaises(InconsistentDelta)
320
# With testtools 0.9.9, it can be rewritten as:
321
# with ExpectedException(AssertionError,
322
# 'InconsistentDelta not raised'):
323
# with ExpectedException(errors.InconsistentDelta, ''):
324
# self.shelve_all(tree1, rev2)
325
e = self.assertRaises(AssertionError, self.assertRaises,
326
errors.InconsistentDelta, self.shelve_all, tree1,
328
self.assertContainsRe('InconsistentDelta not raised', str(e))
330
def test_shelve_split(self):
331
outer_tree = self.make_branch_and_tree('outer')
332
outer_tree.commit('Add root')
333
inner_tree = self.make_branch_and_tree('outer/inner')
334
rev2 = inner_tree.commit('Add root')
335
outer_tree.subsume(inner_tree)
336
# This is essentially assertNotRaises(ValueError).
337
# The ValueError is 'None is not a valid file id'.
338
self.expectFailure('Cannot shelve a join back to the inner tree.',
339
self.assertRaises, AssertionError,
340
self.assertRaises, ValueError, self.shelve_all,
344
class TestApplyReporter(ShelfTestCase):
346
def test_shelve_not_diff(self):
347
tree = self.create_shelvable_tree()
348
tree.lock_tree_write()
349
self.addCleanup(tree.unlock)
350
shelver = ExpectShelver(tree, tree.basis_tree(),
351
reporter=shelf_ui.ApplyReporter())
352
self.addCleanup(shelver.finalize)
353
shelver.expect('Apply change? [yNfq?]', 'n')
354
shelver.expect('Apply change? [yNfq?]', 'n')
355
# No final shelving prompt because no changes were selected
357
self.assertFileEqual(LINES_ZY, 'tree/foo')
359
def test_shelve_diff_no(self):
360
tree = self.create_shelvable_tree()
361
tree.lock_tree_write()
362
self.addCleanup(tree.unlock)
363
shelver = ExpectShelver(tree, tree.basis_tree(),
364
reporter=shelf_ui.ApplyReporter())
365
self.addCleanup(shelver.finalize)
366
shelver.expect('Apply change? [yNfq?]', 'y')
367
shelver.expect('Apply change? [yNfq?]', 'y')
368
shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
370
self.assertFileEqual(LINES_ZY, 'tree/foo')
372
def test_shelve_diff(self):
373
tree = self.create_shelvable_tree()
374
tree.lock_tree_write()
375
self.addCleanup(tree.unlock)
376
shelver = ExpectShelver(tree, tree.basis_tree(),
377
reporter=shelf_ui.ApplyReporter())
378
self.addCleanup(shelver.finalize)
379
shelver.expect('Apply change? [yNfq?]', 'y')
380
shelver.expect('Apply change? [yNfq?]', 'y')
381
shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
383
self.assertFileEqual(LINES_AJ, 'tree/foo')
385
def test_shelve_binary_change(self):
386
tree = self.create_shelvable_tree()
387
self.build_tree_contents([('tree/foo', '\x00')])
388
tree.lock_tree_write()
389
self.addCleanup(tree.unlock)
390
shelver = ExpectShelver(tree, tree.basis_tree(),
391
reporter=shelf_ui.ApplyReporter())
392
self.addCleanup(shelver.finalize)
393
shelver.expect('Apply binary changes? [yNfq?]', 'y')
394
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
396
self.assertFileEqual(LINES_AJ, 'tree/foo')
398
def test_shelve_rename(self):
399
tree = self.create_shelvable_tree()
400
tree.rename_one('foo', 'bar')
401
tree.lock_tree_write()
402
self.addCleanup(tree.unlock)
403
shelver = ExpectShelver(tree, tree.basis_tree(),
404
reporter=shelf_ui.ApplyReporter())
405
self.addCleanup(shelver.finalize)
406
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
407
shelver.expect('Apply change? [yNfq?]', 'y')
408
shelver.expect('Apply change? [yNfq?]', 'y')
409
shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
411
self.assertFileEqual(LINES_AJ, 'tree/foo')
413
def test_shelve_deletion(self):
414
tree = self.create_shelvable_tree()
415
os.unlink('tree/foo')
416
tree.lock_tree_write()
417
self.addCleanup(tree.unlock)
418
shelver = ExpectShelver(tree, tree.basis_tree(),
419
reporter=shelf_ui.ApplyReporter())
420
self.addCleanup(shelver.finalize)
421
shelver.expect('Add file "foo"? [yNfq?]', 'y')
422
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
424
self.assertFileEqual(LINES_AJ, 'tree/foo')
426
def test_shelve_creation(self):
427
tree = self.make_branch_and_tree('tree')
428
tree.commit('add tree root')
429
self.build_tree(['tree/foo'])
431
tree.lock_tree_write()
432
self.addCleanup(tree.unlock)
433
shelver = ExpectShelver(tree, tree.basis_tree(),
434
reporter=shelf_ui.ApplyReporter())
435
self.addCleanup(shelver.finalize)
436
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
437
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
439
self.assertPathDoesNotExist('tree/foo')
441
def test_shelve_kind_change(self):
442
tree = self.create_shelvable_tree()
443
os.unlink('tree/foo')
445
tree.lock_tree_write()
446
self.addCleanup(tree.unlock)
447
shelver = ExpectShelver(tree, tree.basis_tree(),
448
reporter=shelf_ui.ApplyReporter())
449
self.addCleanup(shelver.finalize)
450
shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
451
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
453
def test_shelve_modify_target(self):
454
self.requireFeature(features.SymlinkFeature)
455
tree = self.create_shelvable_tree()
456
os.symlink('bar', 'tree/baz')
457
tree.add('baz', 'baz-id')
458
tree.commit("Add symlink")
459
os.unlink('tree/baz')
460
os.symlink('vax', 'tree/baz')
461
tree.lock_tree_write()
462
self.addCleanup(tree.unlock)
463
shelver = ExpectShelver(tree, tree.basis_tree(),
464
reporter=shelf_ui.ApplyReporter())
465
self.addCleanup(shelver.finalize)
466
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
468
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
470
self.assertEqual('bar', os.readlink('tree/baz'))
473
227
class TestUnshelver(tests.TestCaseWithTransport):
475
229
def create_tree_with_shelf(self):
476
230
tree = self.make_branch_and_tree('tree')
479
self.build_tree_contents([('tree/foo', LINES_AJ)])
480
tree.add('foo', 'foo-id')
481
tree.commit('added foo')
482
self.build_tree_contents([('tree/foo', LINES_ZY)])
483
shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
484
auto_apply=True, auto=True)
231
self.build_tree_contents([('tree/foo', LINES_AJ)])
232
tree.add('foo', 'foo-id')
233
tree.commit('added foo')
234
self.build_tree_contents([('tree/foo', LINES_ZY)])
235
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
493
239
def test_unshelve(self):