239
189
def test_shelve_quit(self):
240
190
tree = self.create_shelvable_tree()
241
tree.lock_tree_write()
242
self.addCleanup(tree.unlock)
243
191
shelver = ExpectShelver(tree, tree.basis_tree())
244
self.addCleanup(shelver.finalize)
245
192
shelver.expect('Shelve? [yNfq?]', 'q')
246
193
self.assertRaises(errors.UserAbort, shelver.run)
247
194
self.assertFileEqual(LINES_ZY, 'tree/foo')
249
196
def test_shelve_all(self):
250
197
tree = self.create_shelvable_tree()
251
shelver = ExpectShelver.from_args(sys.stdout, all=True,
198
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
257
199
self.assertFileEqual(LINES_AJ, 'tree/foo')
259
201
def test_shelve_filename(self):
260
202
tree = self.create_shelvable_tree()
261
203
self.build_tree(['tree/bar'])
263
tree.lock_tree_write()
264
self.addCleanup(tree.unlock)
265
205
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
266
self.addCleanup(shelver.finalize)
267
206
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
268
207
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
271
210
def test_shelve_help(self):
272
211
tree = self.create_shelvable_tree()
273
tree.lock_tree_write()
274
self.addCleanup(tree.unlock)
275
212
shelver = ExpectShelver(tree, tree.basis_tree())
276
self.addCleanup(shelver.finalize)
277
213
shelver.expect('Shelve? [yNfq?]', '?')
278
214
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
279
215
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
282
def test_shelve_destroy(self):
218
def test_shelve_distroy(self):
283
219
tree = self.create_shelvable_tree()
284
220
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
285
221
directory='tree', destroy=True)
286
self.addCleanup(shelver.finalize)
288
223
self.assertIs(None, tree.get_shelf_manager().last_shelf())
289
224
self.assertFileEqual(LINES_AJ, 'tree/foo')
292
def shelve_all(tree, target_revision_id):
295
target = tree.branch.repository.revision_tree(target_revision_id)
296
shelver = shelf_ui.Shelver(tree, target, auto=True,
305
def test_shelve_old_root_deleted(self):
306
tree1 = self.make_branch_and_tree('tree1')
307
tree1.commit('add root')
308
tree2 = self.make_branch_and_tree('tree2')
309
rev2 = tree2.commit('add root')
310
tree1.merge_from_branch(tree2.branch,
311
from_revision=revision.NULL_REVISION)
312
tree1.commit('Replaced root entry')
313
# This is essentially assertNotRaises(InconsistentDelta)
314
# With testtools 0.99, it can be rewritten as:
315
# with ExpectedException(AssertionError,
316
# 'InconsistentDelta not raised'):
317
# with ExpectedException(errors.InconsistentDelta, ''):
318
# self.shelve_all(tree1, rev2)
319
e = self.assertRaises(AssertionError, self.assertRaises,
320
errors.InconsistentDelta, self.shelve_all, tree1,
322
self.assertContainsRe('InconsistentDelta not raised', str(e))
324
def test_shelve_split(self):
325
outer_tree = self.make_branch_and_tree('outer')
326
outer_tree.commit('Add root')
327
inner_tree = self.make_branch_and_tree('outer/inner')
328
rev2 = inner_tree.commit('Add root')
329
outer_tree.subsume(inner_tree)
330
# This is essentially assertNotRaises(ValueError).
331
# The ValueError is 'None is not a valid file id'.
332
self.expectFailure('Cannot shelve a join back to the inner tree.',
333
self.assertRaises, AssertionError,
334
self.assertRaises, ValueError, self.shelve_all,
338
class TestApplyReporter(ShelfTestCase):
340
def test_shelve_not_diff(self):
341
tree = self.create_shelvable_tree()
342
tree.lock_tree_write()
343
self.addCleanup(tree.unlock)
344
shelver = ExpectShelver(tree, tree.basis_tree(),
345
reporter=shelf_ui.ApplyReporter())
346
self.addCleanup(shelver.finalize)
347
shelver.expect('Apply change? [yNfq?]', 'n')
348
shelver.expect('Apply change? [yNfq?]', 'n')
349
# No final shelving prompt because no changes were selected
351
self.assertFileEqual(LINES_ZY, 'tree/foo')
353
def test_shelve_diff_no(self):
354
tree = self.create_shelvable_tree()
355
tree.lock_tree_write()
356
self.addCleanup(tree.unlock)
357
shelver = ExpectShelver(tree, tree.basis_tree(),
358
reporter=shelf_ui.ApplyReporter())
359
self.addCleanup(shelver.finalize)
360
shelver.expect('Apply change? [yNfq?]', 'y')
361
shelver.expect('Apply change? [yNfq?]', 'y')
362
shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
364
self.assertFileEqual(LINES_ZY, 'tree/foo')
366
def test_shelve_diff(self):
367
tree = self.create_shelvable_tree()
368
tree.lock_tree_write()
369
self.addCleanup(tree.unlock)
370
shelver = ExpectShelver(tree, tree.basis_tree(),
371
reporter=shelf_ui.ApplyReporter())
372
self.addCleanup(shelver.finalize)
373
shelver.expect('Apply change? [yNfq?]', 'y')
374
shelver.expect('Apply change? [yNfq?]', 'y')
375
shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
377
self.assertFileEqual(LINES_AJ, 'tree/foo')
379
def test_shelve_binary_change(self):
380
tree = self.create_shelvable_tree()
381
self.build_tree_contents([('tree/foo', '\x00')])
382
tree.lock_tree_write()
383
self.addCleanup(tree.unlock)
384
shelver = ExpectShelver(tree, tree.basis_tree(),
385
reporter=shelf_ui.ApplyReporter())
386
self.addCleanup(shelver.finalize)
387
shelver.expect('Apply binary changes? [yNfq?]', 'y')
388
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
390
self.assertFileEqual(LINES_AJ, 'tree/foo')
392
def test_shelve_rename(self):
393
tree = self.create_shelvable_tree()
394
tree.rename_one('foo', 'bar')
395
tree.lock_tree_write()
396
self.addCleanup(tree.unlock)
397
shelver = ExpectShelver(tree, tree.basis_tree(),
398
reporter=shelf_ui.ApplyReporter())
399
self.addCleanup(shelver.finalize)
400
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
401
shelver.expect('Apply change? [yNfq?]', 'y')
402
shelver.expect('Apply change? [yNfq?]', 'y')
403
shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
405
self.assertFileEqual(LINES_AJ, 'tree/foo')
407
def test_shelve_deletion(self):
408
tree = self.create_shelvable_tree()
409
os.unlink('tree/foo')
410
tree.lock_tree_write()
411
self.addCleanup(tree.unlock)
412
shelver = ExpectShelver(tree, tree.basis_tree(),
413
reporter=shelf_ui.ApplyReporter())
414
self.addCleanup(shelver.finalize)
415
shelver.expect('Add file "foo"? [yNfq?]', 'y')
416
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
418
self.assertFileEqual(LINES_AJ, 'tree/foo')
420
def test_shelve_creation(self):
421
tree = self.make_branch_and_tree('tree')
422
tree.commit('add tree root')
423
self.build_tree(['tree/foo'])
425
tree.lock_tree_write()
426
self.addCleanup(tree.unlock)
427
shelver = ExpectShelver(tree, tree.basis_tree(),
428
reporter=shelf_ui.ApplyReporter())
429
self.addCleanup(shelver.finalize)
430
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
431
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
433
self.assertPathDoesNotExist('tree/foo')
435
def test_shelve_kind_change(self):
436
tree = self.create_shelvable_tree()
437
os.unlink('tree/foo')
439
tree.lock_tree_write()
440
self.addCleanup(tree.unlock)
441
shelver = ExpectShelver(tree, tree.basis_tree(),
442
reporter=shelf_ui.ApplyReporter())
443
self.addCleanup(shelver.finalize)
444
shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
445
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
447
def test_shelve_modify_target(self):
448
self.requireFeature(tests.SymlinkFeature)
449
tree = self.create_shelvable_tree()
450
os.symlink('bar', 'tree/baz')
451
tree.add('baz', 'baz-id')
452
tree.commit("Add symlink")
453
os.unlink('tree/baz')
454
os.symlink('vax', 'tree/baz')
455
tree.lock_tree_write()
456
self.addCleanup(tree.unlock)
457
shelver = ExpectShelver(tree, tree.basis_tree(),
458
reporter=shelf_ui.ApplyReporter())
459
self.addCleanup(shelver.finalize)
460
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
462
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
464
self.assertEqual('bar', os.readlink('tree/baz'))
467
227
class TestUnshelver(tests.TestCaseWithTransport):
469
229
def create_tree_with_shelf(self):
470
230
tree = self.make_branch_and_tree('tree')
473
self.build_tree_contents([('tree/foo', LINES_AJ)])
474
tree.add('foo', 'foo-id')
475
tree.commit('added foo')
476
self.build_tree_contents([('tree/foo', LINES_ZY)])
477
shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
478
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,
487
239
def test_unshelve(self):