7
7
UnshelveHunkSelector,
9
9
from bzrlib.plugins.bzrtools.errors import NoColor
10
from bzrlib.plugins.bzrtools.command_classes import cmd_shelf
10
from bzrlib.plugins.bzrtools.command_classes import cmd_shelf1
13
13
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
97
97
# Shelve the changes
98
self.run_bzr('shelve --all', retcode=0)
98
self.run_bzr('shelve1 --all', retcode=0)
100
100
# Make sure there is no diff anymore
101
101
self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
106
106
self._check_shelf('00', new_date=new_date)
109
self.run_bzr('unshelve --all', retcode=0)
109
self.run_bzr('unshelve1 --all', retcode=0)
111
111
self._check_diff()
122
122
self.__create_and_add_test_file()
124
124
# Shelve the changes
125
self.run_bzr('shelve --all', retcode=3)
125
self.run_bzr('shelve1 --all', retcode=3)
127
127
if os.path.exists(os.path.join(self.tree.branch.base,
128
128
'.shelf/shelves/default/00')):
146
146
self.tree.commit(message='update test_file')
148
148
# Shelve the changes
149
self.run_bzr('shelve --all -r 1', retcode=0)
149
self.run_bzr('shelve1 --all -r 1', retcode=0)
151
151
self._check_diff(self.DIFF_2)
154
154
self.assertEqual(file('test_file').read(), self.ORIGINAL)
157
self.run_bzr('unshelve --all', retcode=0)
157
self.run_bzr('unshelve1 --all', retcode=0)
159
159
# Make sure the file is back the way it should be
160
160
self.assertEqual(file('test_file').read(), self.MODIFIED)
162
162
def test_shelf_with_two_revisions(self):
163
163
self.tree = self.make_branch_and_tree('.')
165
stdout, stderr = self.run_bzr('shelve --all -r 1..2', retcode=None)
165
stdout, stderr = self.run_bzr('shelve1 --all -r 1..2', retcode=None)
167
167
self.assertEqual(stderr.split('\n')[0],
168
168
'bzr: ERROR: shelve only accepts a single revision parameter.')
177
177
self.build_tree_contents([('test_file', 'patch %s\n' % patch)])
179
179
# Shelve the changes
180
self.run_bzr('shelve --all', retcode=0)
180
self.run_bzr('shelve1 --all', retcode=0)
182
182
# Make sure there is no diff anymore
183
183
self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
188
188
self.assertTrue('patch %s' % patch in shelf)
190
190
# Check the shown output is right
191
shown = self.run_bzr('shelf show %s' % patch, retcode=0)[0]
191
shown = self.run_bzr('shelf1 show %s' % patch, retcode=0)[0]
192
192
self.assertEqual(shown, shelf)
194
194
def test_shelf_show_multi(self):
204
204
self.assertTrue('patch 00' in shelf)
206
206
# Check the shown output is right
207
shown = self.run_bzr('shelf show 00', retcode=0)[0]
207
shown = self.run_bzr('shelf1 show 00', retcode=0)[0]
208
208
self.assertEqual(shown, shelf)
210
210
def test_shelf_show_unspecified(self):
220
220
self.assertTrue('patch 02' in shelf)
222
222
# Check the shown output is right
223
shown = self.run_bzr('shelf show', retcode=0)[0]
223
shown = self.run_bzr('shelf1 show', retcode=0)[0]
224
224
self.assertEqual(shown, shelf)
226
226
def test_shelf_show_with_no_patch(self):
227
227
self.tree = self.make_branch_and_tree('.')
228
stderr = self.run_bzr('shelf show 00', retcode=None)[1]
228
stderr = self.run_bzr('shelf1 show 00', retcode=None)[1]
229
229
self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
231
231
def test_shelf_unshelve_failure(self):
237
237
file('test_file', 'w').write(self.MODIFIED)
239
239
# Shelve the changes
240
self.run_bzr('shelve --all', retcode=0)
240
self.run_bzr('shelve1 --all', retcode=0)
242
242
# Write an unapplyable patch into the shelf
243
243
shelf = open(os.path.join(self.tree.basedir,
248
248
# Unshelve, should fail
249
self.run_bzr('unshelve --all', retcode=3)
249
self.run_bzr('unshelve1 --all', retcode=3)
251
251
# Make sure the patch is still there, eventhough it's broken
252
252
shelf = open(os.path.join(self.tree.basedir,
268
268
file('test_file2', 'w').write(self.MODIFIED)
270
270
# Shelve the changes
271
self.run_bzr('shelve --all', retcode=0)
271
self.run_bzr('shelve1 --all', retcode=0)
273
273
# Put the changes to test_file back, the shelved patch won't apply now
274
274
file('test_file', 'w').write(self.MODIFIED)
275
275
self.tree.commit(message='screw up test_file')
277
277
# Unshelve, should fail
278
self.run_bzr('unshelve --all', retcode=3)
278
self.run_bzr('unshelve1 --all', retcode=3)
280
280
# Working tree should be unchanged
281
281
diff = self.run_bzr('diff', retcode=0)[0]
282
282
self.assertEqual(diff, '')
284
284
# Force should succeed and modify test_file2, but leave shelf
285
self.run_bzr('unshelve --force --all', retcode=0)
285
self.run_bzr('unshelve1 --force --all', retcode=0)
286
286
self.assertEqual(open('test_file2').read(), self.MODIFIED)
287
287
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
297
297
file('test_file2', 'w').write(self.MODIFIED)
299
299
# Shelve the changes
300
self.run_bzr('shelve --all test_file', retcode=0)
301
self.run_bzr('shelve --all test_file2', retcode=0)
300
self.run_bzr('shelve1 --all test_file', retcode=0)
301
self.run_bzr('shelve1 --all test_file2', retcode=0)
304
self.run_bzr('unshelve --all', retcode=0)
304
self.run_bzr('unshelve1 --all', retcode=0)
306
306
# We should now have 00 and 01~
307
307
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
308
308
self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
311
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
311
lines = self.run_bzr('shelf1 ls', retcode=0)[0].split('\n')
312
312
for line in lines:
313
313
self.assertFalse(line.startswith(' 01'))
315
315
# Unshelve, if unshelve is confused by the backup it will fail
316
self.run_bzr('unshelve --all', retcode=0)
316
self.run_bzr('unshelve1 --all', retcode=0)
318
318
def test_shelf_delete(self):
319
319
self.tree = self.make_branch_and_tree('.')
336
336
self.tree.unlock()
338
338
# Shelve the changes
339
self.run_bzr('shelve --all test_file', retcode=0)
340
self.run_bzr('shelve --all test_file2', retcode=0)
339
self.run_bzr('shelve1 --all test_file', retcode=0)
340
self.run_bzr('shelve1 --all test_file2', retcode=0)
342
342
self._check_shelf('00', new_date=new_date)
345
self.run_bzr('shelf delete 00', retcode=0)
345
self.run_bzr('shelf1 delete 00', retcode=0)
347
347
# We should now have 01 but not 00, but we should have 00~
348
348
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
353
353
self._check_shelf('00~', new_date=new_date)
356
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
356
lines = self.run_bzr('shelf1 ls', retcode=0)[0].split('\n')
357
357
for line in lines:
358
358
self.assertFalse(line.startswith(' 00'))
360
360
# Unshelve should unshelve 01
361
self.run_bzr('unshelve --all', retcode=0)
361
self.run_bzr('unshelve1 --all', retcode=0)
362
362
self.assertEqual(file('test_file2').read(), self.MODIFIED)
364
364
def test_shelf_gaps(self):
365
365
self.tree = self.make_branch_and_tree('.')
366
366
self.__create_and_add_test_file()
367
367
file('test_file', 'w').write(self.MODIFIED)
368
self.run_bzr('shelve --all test_file', retcode=0)
368
self.run_bzr('shelve1 --all test_file', retcode=0)
369
369
file('test_file', 'w').write(self.MODIFIED)
370
self.run_bzr('shelve --all test_file', retcode=0)
370
self.run_bzr('shelve1 --all test_file', retcode=0)
372
372
# Now delete 00, leaving 01, next shelve should go into 02
373
self.run_bzr('shelf delete 0', retcode=0)
373
self.run_bzr('shelf1 delete 0', retcode=0)
374
374
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
375
375
self.assertFalse(os.path.exists('.shelf/shelves/default/02'))
376
376
file('test_file', 'w').write(self.MODIFIED)
377
self.run_bzr('shelve --all test_file', retcode=0)
377
self.run_bzr('shelve1 --all test_file', retcode=0)
378
378
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
379
379
self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
386
386
# Modify then shelve, so we're not upgrading to 00, just for kicks
387
387
file('test_file', 'w').write(self.MODIFIED)
388
self.run_bzr('shelve --all test_file', retcode=0)
388
self.run_bzr('shelve1 --all test_file', retcode=0)
390
390
open('.bzr-shelf', 'w').write('First old shelf')
391
391
open('.bzr-shelf-1', 'w').write('Second old shelf')
394
394
# shelve and unshelve should bitch and do nothing
395
395
file('test_file', 'w').write('blah blah blah')
396
self.run_bzr('shelve --all', retcode=3)
396
self.run_bzr('shelve1 --all', retcode=3)
397
397
self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
398
398
self.assertEqual(file('test_file').read(), 'blah blah blah')
399
self.run_bzr('unshelve --all', retcode=3)
399
self.run_bzr('unshelve1 --all', retcode=3)
400
400
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
402
402
# Upgrade, make sure it worked
403
self.run_bzr('shelf upgrade', retcode=0)
403
self.run_bzr('shelf1 upgrade', retcode=0)
404
404
self.assertEqual(open('.shelf/shelves/default/01').read(),
405
405
'First old shelf')
406
406
self.assertEqual(open('.shelf/shelves/default/02').read(),
417
417
self.assertFalse(os.path.exists('.bzr-shelf-3'))
419
419
# Shelve should work now
420
self.run_bzr('shelve --all', retcode=0)
420
self.run_bzr('shelve1 --all', retcode=0)
422
422
def test_shelf_p1_patch(self):
423
423
self.tree = self.make_branch_and_tree('.')
425
425
self.__create_and_add_test_file()
427
427
# Run a benign shelf command to setup .shelf for us
428
self.run_bzr('shelf ls', retcode=0)
428
self.run_bzr('shelf1 ls', retcode=0)
430
430
old_tree = self.tree.basis_tree()
431
431
old_tree.lock_read()
447
447
open('.shelf/shelves/default/00', 'w').write(diff)
449
449
# This should work
450
self.run_bzr('unshelve --all', retcode=0)
450
self.run_bzr('unshelve1 --all', retcode=0)
452
452
self._check_diff()
470
470
# Shelve the changes
471
self.run_bzr('shelve --all', retcode=0)
471
self.run_bzr('shelve1 --all', retcode=0)
473
473
# Working tree should be unchanged
474
474
diff = self.run_bzr('diff', retcode=0)[0]
475
475
self.assertEqual(diff, '')
477
477
# Unshelve, should succeed
478
self.run_bzr('unshelve --all', retcode=0)
478
self.run_bzr('unshelve1 --all', retcode=0)
480
480
self._check_diff(filename='subdir/test_file')
482
482
# Make sure relative filenames work ok
483
self.run_bzr('shelve test_file --all', retcode=0)
483
self.run_bzr('shelve1 test_file --all', retcode=0)
485
485
def test_shelf_shelf_bogus_subcommand(self):
486
486
self.tree = self.make_branch_and_tree('.')
487
self.run_bzr('shelf foo', retcode=3) # <- retcode == 3
487
self.run_bzr('shelf1 foo', retcode=3) # <- retcode == 3
489
489
def test_shelf_OOO_unshelve(self):
490
490
self.tree = self.make_branch_and_tree('.')
499
499
# Shelve the changes
500
500
for i in range(1, 5):
501
self.run_bzr(['shelve', '--all', 'test_file%d' % i], retcode=0)
501
self.run_bzr(['shelve1', '--all', 'test_file%d' % i], retcode=0)
503
503
# Check shelving worked
504
504
for i in range(1, 5):
509
509
self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
512
self.run_bzr('unshelve --all 00', retcode=0)
512
self.run_bzr('unshelve1 --all 00', retcode=0)
513
513
self.assertEqual(file('test_file1').read(), self.MODIFIED)
516
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
516
lines = self.run_bzr('shelf1 ls', retcode=0)[0].split('\n')
517
517
for line in lines:
518
518
self.assertFalse(line.startswith(' 00'))
520
520
# Check we can reshelve once we've unshelved out of order, should be 04
521
521
self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
522
self.run_bzr('shelve --all')
522
self.run_bzr('shelve1 --all')
523
523
self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
526
text = self.run_bzr('shelf ls', retcode=0)[0]
526
text = self.run_bzr('shelf1 ls', retcode=0)[0]
527
527
for line in text.split('\n'):
528
528
self.assertFalse(line.startswith(' 00'))
530
530
# We now have 01,02,03,04
532
self.run_bzr('unshelve --all 02', retcode=0)
532
self.run_bzr('unshelve1 --all 02', retcode=0)
533
533
self.assertEqual(file('test_file3').read(), self.MODIFIED)
535
535
# Unshelve the default, this is the reshelved 00, hence modifies file 1
536
self.run_bzr('unshelve --all', retcode=0)
536
self.run_bzr('unshelve1 --all', retcode=0)
537
537
self.assertEqual(file('test_file1').read(), self.MODIFIED)
539
539
def test_shelf_switch_basic(self):
543
543
# This should go to "default"
544
544
file('test_file', 'w').write(self.MODIFIED)
545
self.run_bzr('shelve --all test_file', retcode=0)
545
self.run_bzr('shelve1 --all test_file', retcode=0)
547
547
# Switch to "other"
548
self.run_bzr('shelf switch other', retcode=0)
548
self.run_bzr('shelf1 switch other', retcode=0)
549
549
file('test_file', 'w').write(self.MODIFIED)
550
self.run_bzr('shelve --all test_file', retcode=0)
550
self.run_bzr('shelve1 --all test_file', retcode=0)
552
552
# Check it worked
553
553
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
555
555
self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
558
self.run_bzr('shelf switch default', retcode=0)
558
self.run_bzr('shelf1 switch default', retcode=0)
559
559
file('test_file', 'w').write(self.MODIFIED)
560
self.run_bzr('shelve --all test_file', retcode=0)
560
self.run_bzr('shelve1 --all test_file', retcode=0)
562
562
# Check that worked
563
563
self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
567
567
self.tree = self.make_branch_and_tree('.')
568
568
self.build_tree_contents([('file', '\x00')])
569
569
self.tree.add('file')
570
self.run_bzr_error(['Changes involve binary files.'], 'shelve --all')
570
self.run_bzr_error(['Changes involve binary files.'], 'shelve1 --all')
572
572
def test_shelf_bad_patch_arg(self):
573
573
self.tree = self.make_branch_and_tree('.')
575
575
# Check the bad arg handling
576
stdout, error = self.run_bzr('unshelve 01', retcode=3)
576
stdout, error = self.run_bzr('unshelve1 01', retcode=3)
577
577
self.assertTrue("Patch '01' doesn't exist on shelf" in error)
579
stdout, error = self.run_bzr('unshelve foo', retcode=3)
579
stdout, error = self.run_bzr('unshelve1 foo', retcode=3)
580
580
self.assertTrue("Invalid patch name 'foo'" in error)
582
582
# Hex and is cracky, so it shouldn't work
583
stdout, error = self.run_bzr(['unshelve', '0x00'], retcode=3)
583
stdout, error = self.run_bzr(['unshelve1', '0x00'], retcode=3)
584
584
self.assertTrue("Invalid patch name '0x00'" in error)
586
586
def test_color_hunk_selector(self):
618
618
f = file('test_file', 'wb')
619
619
f.write(self.MODIFIED)
621
stdout, error = self.run_bzr('shelve --all --no-color')
622
stdout, error = self.run_bzr('unshelve --all --no-color')
621
stdout, error = self.run_bzr('shelve1 --all --no-color')
622
stdout, error = self.run_bzr('unshelve1 --all --no-color')
624
624
def test_shelf_help(self):
625
self.assertContainsRe(cmd_shelf().help(),
625
self.assertContainsRe(cmd_shelf1().help(),
626
626
'list\n.*List the patches on the current shelf')
628
628
def test_show_empty_shelf(self):
629
629
self.tree = self.make_branch_and_tree('.')
630
self.run_bzr_error(('No patches on shelf.',), 'shelf show')
630
self.run_bzr_error(('No patches on shelf.',), 'shelf1 show')