48
keys = { 'filename' : filename , 'old_date': old_date,
48
keys = { 'filename' : filename , 'old_date': old_date,
49
49
'new_date': new_date}
50
50
hdr = self.DIFF_HEADER % keys
52
self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
52
self.assertEqual(self.run_bzr('diff', retcode=1)[0], hdr + diff + '\n')
54
54
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
97
97
# Shelve the changes
98
self.run_bzr('shelve', '--all', retcode=0)
98
self.run_bzr('shelve --all', retcode=0)
100
100
# Make sure there is no diff anymore
101
self.assertEqual(self.capture('diff', retcode=0), '')
101
self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
103
103
# Make sure the file is actually back the way it was
104
104
self.assertEqual(file('test_file').read(), self.ORIGINAL)
106
106
self._check_shelf('00', new_date=new_date)
109
self.run_bzr('unshelve', '--all', retcode=0)
109
self.run_bzr('unshelve --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('shelve --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('shelve --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('unshelve --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
cmd = 'shelve --all -r 1..2'
166
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
165
stdout, stderr = self.run_bzr('shelve --all -r 1..2', retcode=None)
168
167
self.assertEqual(stderr.split('\n')[0],
169
168
'bzr: ERROR: shelve only accepts a single revision parameter.')
178
177
self.build_tree_contents([('test_file', 'patch %s\n' % patch)])
180
179
# Shelve the changes
181
self.run_bzr('shelve', '--all', retcode=0)
180
self.run_bzr('shelve --all', retcode=0)
183
182
# Make sure there is no diff anymore
184
self.assertEqual(self.capture('diff', retcode=0), '')
183
self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
186
185
# Check the shelf is right
187
186
shelf = open(os.path.join(self.tree.basedir,
189
188
self.assertTrue('patch %s' % patch in shelf)
191
190
# Check the shown output is right
192
shown = self.capture('shelf show %s' % patch, retcode=0)
191
shown = self.run_bzr('shelf show %s' % patch, retcode=0)[0]
193
192
self.assertEqual(shown, shelf)
195
194
def test_shelf_show_multi(self):
205
204
self.assertTrue('patch 00' in shelf)
207
206
# Check the shown output is right
208
shown = self.capture('shelf show 00', retcode=0)
207
shown = self.run_bzr('shelf show 00', retcode=0)[0]
209
208
self.assertEqual(shown, shelf)
211
210
def test_shelf_show_unspecified(self):
221
220
self.assertTrue('patch 02' in shelf)
223
222
# Check the shown output is right
224
shown = self.capture('shelf show', retcode=0)
223
shown = self.run_bzr('shelf show', retcode=0)[0]
225
224
self.assertEqual(shown, shelf)
227
226
def test_shelf_show_with_no_patch(self):
228
227
self.tree = self.make_branch_and_tree('.')
229
stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
228
stderr = self.run_bzr('shelf show 00', retcode=None)[1]
230
229
self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
232
231
def test_shelf_unshelve_failure(self):
238
237
file('test_file', 'w').write(self.MODIFIED)
240
239
# Shelve the changes
241
self.run_bzr('shelve', '--all', retcode=0)
240
self.run_bzr('shelve --all', retcode=0)
243
242
# Write an unapplyable patch into the shelf
244
243
shelf = open(os.path.join(self.tree.basedir,
249
248
# Unshelve, should fail
250
self.run_bzr('unshelve', '--all', retcode=3)
249
self.run_bzr('unshelve --all', retcode=3)
252
251
# Make sure the patch is still there, eventhough it's broken
253
252
shelf = open(os.path.join(self.tree.basedir,
255
254
self.assertEqual(shelf, self.DIFF_2)
257
256
# Working tree should be unchanged
258
diff = self.capture('diff', retcode=0)
257
diff = self.run_bzr('diff', retcode=0)[0]
259
258
self.assertEqual(diff, '')
261
260
def test_shelf_unshelve_failure_two_hunks(self):
269
268
file('test_file2', 'w').write(self.MODIFIED)
271
270
# Shelve the changes
272
self.run_bzr('shelve', '--all', retcode=0)
271
self.run_bzr('shelve --all', retcode=0)
274
273
# Put the changes to test_file back, the shelved patch won't apply now
275
274
file('test_file', 'w').write(self.MODIFIED)
276
275
self.tree.commit(message='screw up test_file')
278
277
# Unshelve, should fail
279
self.run_bzr('unshelve', '--all', retcode=3)
278
self.run_bzr('unshelve --all', retcode=3)
281
280
# Working tree should be unchanged
282
diff = self.capture('diff', retcode=0)
281
diff = self.run_bzr('diff', retcode=0)[0]
283
282
self.assertEqual(diff, '')
285
284
# Force should succeed and modify test_file2, but leave shelf
286
self.run_bzr('unshelve', '--force', '--all', retcode=0)
285
self.run_bzr('unshelve --force --all', retcode=0)
287
286
self.assertEqual(open('test_file2').read(), self.MODIFIED)
288
287
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
298
297
file('test_file2', 'w').write(self.MODIFIED)
300
299
# Shelve the changes
301
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
302
self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
300
self.run_bzr('shelve --all test_file', retcode=0)
301
self.run_bzr('shelve --all test_file2', retcode=0)
305
self.run_bzr('unshelve', '--all', retcode=0)
304
self.run_bzr('unshelve --all', retcode=0)
307
306
# We should now have 00 and 01~
308
307
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
309
308
self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
312
lines = self.capture('shelf ls', retcode=0).split('\n')
311
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
313
312
for line in lines:
314
313
self.assertFalse(line.startswith(' 01'))
316
315
# Unshelve, if unshelve is confused by the backup it will fail
317
self.run_bzr('unshelve', '--all', retcode=0)
316
self.run_bzr('unshelve --all', retcode=0)
319
318
def test_shelf_delete(self):
320
319
self.tree = self.make_branch_and_tree('.')
337
336
self.tree.unlock()
339
338
# Shelve the changes
340
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
341
self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
339
self.run_bzr('shelve --all test_file', retcode=0)
340
self.run_bzr('shelve --all test_file2', retcode=0)
343
342
self._check_shelf('00', new_date=new_date)
346
self.run_bzr('shelf', 'delete', '00', retcode=0)
345
self.run_bzr('shelf delete 00', retcode=0)
348
347
# We should now have 01 but not 00, but we should have 00~
349
348
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
354
353
self._check_shelf('00~', new_date=new_date)
357
lines = self.capture('shelf ls', retcode=0).split('\n')
356
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
358
357
for line in lines:
359
358
self.assertFalse(line.startswith(' 00'))
361
360
# Unshelve should unshelve 01
362
self.run_bzr('unshelve', '--all', retcode=0)
361
self.run_bzr('unshelve --all', retcode=0)
363
362
self.assertEqual(file('test_file2').read(), self.MODIFIED)
365
364
def test_shelf_gaps(self):
366
365
self.tree = self.make_branch_and_tree('.')
367
366
self.__create_and_add_test_file()
368
367
file('test_file', 'w').write(self.MODIFIED)
369
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
368
self.run_bzr('shelve --all test_file', retcode=0)
370
369
file('test_file', 'w').write(self.MODIFIED)
371
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
370
self.run_bzr('shelve --all test_file', retcode=0)
373
372
# Now delete 00, leaving 01, next shelve should go into 02
374
self.run_bzr('shelf', 'delete', '0', retcode=0)
373
self.run_bzr('shelf delete 0', retcode=0)
375
374
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
376
375
self.assertFalse(os.path.exists('.shelf/shelves/default/02'))
377
376
file('test_file', 'w').write(self.MODIFIED)
378
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
377
self.run_bzr('shelve --all test_file', retcode=0)
379
378
self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
380
379
self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
387
386
# Modify then shelve, so we're not upgrading to 00, just for kicks
388
387
file('test_file', 'w').write(self.MODIFIED)
389
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
388
self.run_bzr('shelve --all test_file', retcode=0)
391
390
open('.bzr-shelf', 'w').write('First old shelf')
392
391
open('.bzr-shelf-1', 'w').write('Second old shelf')
395
394
# shelve and unshelve should bitch and do nothing
396
395
file('test_file', 'w').write('blah blah blah')
397
self.run_bzr('shelve', '--all', retcode=3)
396
self.run_bzr('shelve --all', retcode=3)
398
397
self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
399
398
self.assertEqual(file('test_file').read(), 'blah blah blah')
400
self.run_bzr('unshelve', '--all', retcode=3)
399
self.run_bzr('unshelve --all', retcode=3)
401
400
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
403
402
# Upgrade, make sure it worked
404
self.run_bzr('shelf', 'upgrade', retcode=0)
403
self.run_bzr('shelf upgrade', retcode=0)
405
404
self.assertEqual(open('.shelf/shelves/default/01').read(),
406
405
'First old shelf')
407
406
self.assertEqual(open('.shelf/shelves/default/02').read(),
418
417
self.assertFalse(os.path.exists('.bzr-shelf-3'))
420
419
# Shelve should work now
421
self.run_bzr('shelve', '--all', retcode=0)
420
self.run_bzr('shelve --all', retcode=0)
423
422
def test_shelf_p1_patch(self):
424
423
self.tree = self.make_branch_and_tree('.')
426
425
self.__create_and_add_test_file()
428
427
# Run a benign shelf command to setup .shelf for us
429
self.run_bzr('shelf', 'ls', retcode=0)
428
self.run_bzr('shelf ls', retcode=0)
431
430
old_tree = self.tree.basis_tree()
432
431
old_tree.lock_read()
448
447
open('.shelf/shelves/default/00', 'w').write(diff)
450
449
# This should work
451
self.run_bzr('unshelve', '--all', retcode=0)
450
self.run_bzr('unshelve --all', retcode=0)
453
452
self._check_diff()
471
470
# Shelve the changes
472
self.run_bzr('shelve', '--all', retcode=0)
471
self.run_bzr('shelve --all', retcode=0)
474
473
# Working tree should be unchanged
475
diff = self.capture('diff', retcode=0)
474
diff = self.run_bzr('diff', retcode=0)[0]
476
475
self.assertEqual(diff, '')
478
477
# Unshelve, should succeed
479
self.run_bzr('unshelve', '--all', retcode=0)
478
self.run_bzr('unshelve --all', retcode=0)
481
480
self._check_diff(filename='subdir/test_file')
483
482
# Make sure relative filenames work ok
484
self.run_bzr('shelve', 'test_file', '--all', retcode=0)
483
self.run_bzr('shelve test_file --all', retcode=0)
486
485
def test_shelf_shelf_bogus_subcommand(self):
487
486
self.tree = self.make_branch_and_tree('.')
488
self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
487
self.run_bzr('shelf foo', retcode=3) # <- retcode == 3
490
489
def test_shelf_OOO_unshelve(self):
491
490
self.tree = self.make_branch_and_tree('.')
500
499
# Shelve the changes
501
500
for i in range(1, 5):
502
self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
501
self.run_bzr(['shelve', '--all', 'test_file%d' % i], retcode=0)
504
503
# Check shelving worked
505
504
for i in range(1, 5):
510
509
self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
513
self.run_bzr('unshelve', '--all', '00', retcode=0)
512
self.run_bzr('unshelve --all 00', retcode=0)
514
513
self.assertEqual(file('test_file1').read(), self.MODIFIED)
517
lines = self.capture('shelf ls', retcode=0).split('\n')
516
lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
518
517
for line in lines:
519
518
self.assertFalse(line.startswith(' 00'))
521
520
# Check we can reshelve once we've unshelved out of order, should be 04
522
521
self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
523
self.run_bzr('shelve', '--all')
522
self.run_bzr('shelve --all')
524
523
self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
527
text = self.capture('shelf ls', retcode=0)
526
text = self.run_bzr('shelf ls', retcode=0)[0]
528
527
for line in text.split('\n'):
529
528
self.assertFalse(line.startswith(' 00'))
531
530
# We now have 01,02,03,04
533
self.run_bzr('unshelve', '--all', '02', retcode=0)
532
self.run_bzr('unshelve --all 02', retcode=0)
534
533
self.assertEqual(file('test_file3').read(), self.MODIFIED)
536
535
# Unshelve the default, this is the reshelved 00, hence modifies file 1
537
self.run_bzr('unshelve', '--all', retcode=0)
536
self.run_bzr('unshelve --all', retcode=0)
538
537
self.assertEqual(file('test_file1').read(), self.MODIFIED)
540
539
def test_shelf_switch_basic(self):
544
543
# This should go to "default"
545
544
file('test_file', 'w').write(self.MODIFIED)
546
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
545
self.run_bzr('shelve --all test_file', retcode=0)
548
547
# Switch to "other"
549
self.run_bzr('shelf', 'switch', 'other', retcode=0)
548
self.run_bzr('shelf switch other', retcode=0)
550
549
file('test_file', 'w').write(self.MODIFIED)
551
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
550
self.run_bzr('shelve --all test_file', retcode=0)
553
552
# Check it worked
554
553
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
556
555
self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
559
self.run_bzr('shelf', 'switch', 'default', retcode=0)
558
self.run_bzr('shelf switch default', retcode=0)
560
559
file('test_file', 'w').write(self.MODIFIED)
561
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
560
self.run_bzr('shelve --all test_file', retcode=0)
563
562
# Check that worked
564
563
self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
565
564
self.assertFalse(os.path.exists('.shelf/shelves/other/01'))
566
def test_shelf_binary(self):
567
self.tree = self.make_branch_and_tree('.')
568
self.build_tree_contents([('file', '\x00')])
569
self.tree.add('file')
570
self.run_bzr_error(['Changes involve binary files.'], 'shelve --all')
567
572
def test_shelf_bad_patch_arg(self):
568
573
self.tree = self.make_branch_and_tree('.')
570
575
# Check the bad arg handling
571
stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
576
stdout, error = self.run_bzr('unshelve 01', retcode=3)
572
577
self.assertTrue("Patch '01' doesn't exist on shelf" in error)
574
stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
579
stdout, error = self.run_bzr('unshelve foo', retcode=3)
575
580
self.assertTrue("Invalid patch name 'foo'" in error)
577
582
# Hex and is cracky, so it shouldn't work
578
stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
583
stdout, error = self.run_bzr(['unshelve', '0x00'], retcode=3)
579
584
self.assertTrue("Invalid patch name '0x00'" in error)
581
586
def test_color_hunk_selector(self):
613
618
f = file('test_file', 'wb')
614
619
f.write(self.MODIFIED)
616
stdout, error = self.run_bzr_captured(['shelve', '--all',
618
stdout, error = self.run_bzr_captured(['unshelve', '--all',
621
stdout, error = self.run_bzr('shelve --all --no-color')
622
stdout, error = self.run_bzr('unshelve --all --no-color')
621
624
def test_shelf_help(self):
622
625
self.assertContainsRe(cmd_shelf().help(),
623
626
'list\n.*List the patches on the current shelf')
628
def test_show_empty_shelf(self):
629
self.tree = self.make_branch_and_tree('.')
630
self.run_bzr_error(('No patches on shelf.',), 'shelf show')