~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2007-01-08 17:27:48 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070108172748-1b22qtszaadoby89
Improve bzr import docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os.path
2
1
from bzrlib.diff import _patch_header_date
3
2
import bzrlib.tests
 
3
import os.path
4
4
 
5
 
from bzrlib.plugins.bzrtools.hunk_selector import (
6
 
    ShelveHunkSelector,
7
 
    UnshelveHunkSelector,
8
 
    )
9
 
from bzrlib.plugins.bzrtools.errors import NoColor
10
 
from bzrlib.plugins.bzrtools import cmd_shelf
 
5
try:
 
6
    from bzrlib.plugins.bzrtools.hunk_selector import (
 
7
        ShelveHunkSelector,
 
8
        UnshelveHunkSelector,
 
9
        )
 
10
    from bzrlib.plugins.bzrtools.errors import NoColor
 
11
except ImportError:
 
12
    from bzrtools.hunk_selector import (
 
13
        ShelveHunkSelector,
 
14
        UnshelveHunkSelector,
 
15
        )
 
16
    from bzrtools.errors import NoColor
11
17
 
12
18
 
13
19
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
34
40
"""
35
41
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
36
42
        old_tree = self.tree.basis_tree()
37
 
        old_tree.lock_read()
38
 
        self.tree.lock_read()
39
 
        try:
40
 
            old_date = _patch_header_date(old_tree,
41
 
                                          old_tree.inventory.path2id(filename),
42
 
                                          filename)
43
 
            new_date = _patch_header_date(self.tree,
44
 
                self.tree.inventory.path2id(filename), filename)
45
 
        finally:
46
 
            self.tree.unlock()
47
 
            old_tree.unlock()
48
 
        keys = { 'filename' : filename , 'old_date': old_date,
 
43
        old_date = _patch_header_date(old_tree, 
 
44
                                      old_tree.inventory.path2id(filename),
 
45
                                      filename)
 
46
        new_date = _patch_header_date(self.tree, 
 
47
                                      self.tree.inventory.path2id(filename),
 
48
                                      filename)
 
49
        keys = { 'filename' : filename , 'old_date': old_date, 
49
50
                 'new_date': new_date}
50
51
        hdr  = self.DIFF_HEADER % keys
51
52
        diff = diff % keys
52
 
        self.assertEqual(self.run_bzr('diff', retcode=1)[0], hdr + diff + '\n')
 
53
        self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
53
54
 
54
55
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
55
56
                     new_date=None):
56
57
        old_tree = self.tree.basis_tree()
57
 
        old_tree.lock_read()
58
 
        try:
59
 
            old_date = _patch_header_date(old_tree,
60
 
                                          old_tree.inventory.path2id(filename),
61
 
                                          filename)
62
 
        finally:
63
 
            old_tree.unlock()
 
58
        old_date = _patch_header_date(old_tree, 
 
59
                                      old_tree.inventory.path2id(filename),
 
60
                                      filename)
64
61
        diff = diff % { 'filename' : filename, 'old_date': old_date,
65
62
                        'new_date': new_date}
66
63
        shelf = open(os.path.join(self.tree.basedir,
77
74
    def __test_loop(self, count):
78
75
        self.tree = self.make_branch_and_tree('.')
79
76
        self.__create_and_add_test_file()
80
 
        for counter in range(count):
 
77
 
 
78
        while count > 0:
 
79
            count -= 1
 
80
 
81
81
            # Modify the test file
82
 
            # write in binary mode because on win32 line-endings should be
83
 
            # LF
 
82
            # write in binary mode because on win32 line-endings should be LF
84
83
            f = file('test_file', 'wb')
85
84
            f.write(self.MODIFIED)
86
85
            f.close()
87
86
 
88
87
            self._check_diff()
89
 
 
90
 
            self.tree.lock_write()
91
 
            try:
92
 
                new_date = _patch_header_date(self.tree,
93
 
                    self.tree.inventory.path2id('test_file'), 'test_file')
94
 
            finally:
95
 
                self.tree.unlock()
 
88
            
 
89
            new_date = _patch_header_date(self.tree, 
 
90
                self.tree.inventory.path2id('test_file'), 'test_file')
96
91
 
97
92
            # Shelve the changes
98
 
            self.run_bzr('shelve --all', retcode=0)
 
93
            self.run_bzr('shelve', '--all', retcode=0)
99
94
 
100
95
            # Make sure there is no diff anymore
101
 
            self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
 
96
            self.assertEqual(self.capture('diff', retcode=0), '')
102
97
 
103
98
            # Make sure the file is actually back the way it was
104
99
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
106
101
            self._check_shelf('00', new_date=new_date)
107
102
 
108
103
            # Unshelve
109
 
            self.run_bzr('unshelve --all', retcode=0)
 
104
            self.run_bzr('unshelve', '--all', retcode=0)
110
105
 
111
106
            self._check_diff()
112
107
 
122
117
        self.__create_and_add_test_file()
123
118
 
124
119
        # Shelve the changes
125
 
        self.run_bzr('shelve --all', retcode=3)
 
120
        self.run_bzr('shelve', '--all', retcode=3)
126
121
 
127
122
        if os.path.exists(os.path.join(self.tree.branch.base,
128
123
                '.shelf/shelves/default/00')):
146
141
        self.tree.commit(message='update test_file')
147
142
 
148
143
        # Shelve the changes
149
 
        self.run_bzr('shelve --all -r 1', retcode=0)
 
144
        self.run_bzr('shelve', '--all', '-r', '1', retcode=0)
150
145
 
151
146
        self._check_diff(self.DIFF_2)
152
147
 
154
149
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
155
150
 
156
151
        # Unshelve
157
 
        self.run_bzr('unshelve --all', retcode=0)
 
152
        self.run_bzr('unshelve', '--all', retcode=0)
158
153
 
159
154
        # Make sure the file is back the way it should be
160
155
        self.assertEqual(file('test_file').read(), self.MODIFIED)
162
157
    def test_shelf_with_two_revisions(self):
163
158
        self.tree = self.make_branch_and_tree('.')
164
159
 
165
 
        stdout, stderr = self.run_bzr('shelve --all -r 1..2', retcode=None)
 
160
        cmd = 'shelve --all -r 1..2'
 
161
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
166
162
 
167
163
        self.assertEqual(stderr.split('\n')[0],
168
164
            'bzr: ERROR: shelve only accepts a single revision parameter.')
177
173
        self.build_tree_contents([('test_file', 'patch %s\n' % patch)])
178
174
 
179
175
        # Shelve the changes
180
 
        self.run_bzr('shelve --all', retcode=0)
 
176
        self.run_bzr('shelve', '--all', retcode=0)
181
177
 
182
178
        # Make sure there is no diff anymore
183
 
        self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
 
179
        self.assertEqual(self.capture('diff', retcode=0), '')
184
180
 
185
181
        # Check the shelf is right
186
182
        shelf = open(os.path.join(self.tree.basedir,
188
184
        self.assertTrue('patch %s' % patch in shelf)
189
185
 
190
186
        # Check the shown output is right
191
 
        shown = self.run_bzr('shelf show %s' % patch, retcode=0)[0]
 
187
        shown = self.capture('shelf show %s' % patch, retcode=0)
192
188
        self.assertEqual(shown, shelf)
193
189
 
194
190
    def test_shelf_show_multi(self):
204
200
        self.assertTrue('patch 00' in shelf)
205
201
 
206
202
        # Check the shown output is right
207
 
        shown = self.run_bzr('shelf show 00', retcode=0)[0]
 
203
        shown = self.capture('shelf show 00', retcode=0)
208
204
        self.assertEqual(shown, shelf)
209
205
 
210
206
    def test_shelf_show_unspecified(self):
220
216
        self.assertTrue('patch 02' in shelf)
221
217
 
222
218
        # Check the shown output is right
223
 
        shown = self.run_bzr('shelf show', retcode=0)[0]
 
219
        shown = self.capture('shelf show', retcode=0)
224
220
        self.assertEqual(shown, shelf)
225
221
 
226
222
    def test_shelf_show_with_no_patch(self):
227
223
        self.tree = self.make_branch_and_tree('.')
228
 
        stderr = self.run_bzr('shelf show 00', retcode=None)[1]
 
224
        stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
229
225
        self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
230
226
 
231
227
    def test_shelf_unshelve_failure(self):
237
233
        file('test_file', 'w').write(self.MODIFIED)
238
234
 
239
235
        # Shelve the changes
240
 
        self.run_bzr('shelve --all', retcode=0)
 
236
        self.run_bzr('shelve', '--all', retcode=0)
241
237
 
242
238
        # Write an unapplyable patch into the shelf
243
239
        shelf = open(os.path.join(self.tree.basedir,
246
242
        shelf.close()
247
243
 
248
244
        # Unshelve, should fail
249
 
        self.run_bzr('unshelve --all', retcode=3)
 
245
        self.run_bzr('unshelve', '--all', retcode=3)
250
246
 
251
247
        # Make sure the patch is still there, eventhough it's broken
252
248
        shelf = open(os.path.join(self.tree.basedir,
254
250
        self.assertEqual(shelf, self.DIFF_2)
255
251
 
256
252
        # Working tree should be unchanged
257
 
        diff = self.run_bzr('diff', retcode=0)[0]
 
253
        diff = self.capture('diff', retcode=0)
258
254
        self.assertEqual(diff, '')
259
255
 
260
256
    def test_shelf_unshelve_failure_two_hunks(self):
268
264
        file('test_file2', 'w').write(self.MODIFIED)
269
265
 
270
266
        # Shelve the changes
271
 
        self.run_bzr('shelve --all', retcode=0)
 
267
        self.run_bzr('shelve', '--all', retcode=0)
272
268
 
273
269
        # Put the changes to test_file back, the shelved patch won't apply now
274
270
        file('test_file', 'w').write(self.MODIFIED)
275
271
        self.tree.commit(message='screw up test_file')
276
272
 
277
273
        # Unshelve, should fail
278
 
        self.run_bzr('unshelve --all', retcode=3)
 
274
        self.run_bzr('unshelve', '--all', retcode=3)
279
275
 
280
276
        # Working tree should be unchanged
281
 
        diff = self.run_bzr('diff', retcode=0)[0]
 
277
        diff = self.capture('diff', retcode=0)
282
278
        self.assertEqual(diff, '')
283
279
 
284
280
        # Force should succeed and modify test_file2, but leave shelf
285
 
        self.run_bzr('unshelve --force --all', retcode=0)
 
281
        self.run_bzr('unshelve', '--force', '--all', retcode=0)
286
282
        self.assertEqual(open('test_file2').read(), self.MODIFIED)
287
283
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
288
284
 
297
293
        file('test_file2', 'w').write(self.MODIFIED)
298
294
 
299
295
        # Shelve the changes
300
 
        self.run_bzr('shelve --all test_file', retcode=0)
301
 
        self.run_bzr('shelve --all test_file2', retcode=0)
 
296
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
297
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
302
298
 
303
299
        # Unshelve
304
 
        self.run_bzr('unshelve --all', retcode=0)
 
300
        self.run_bzr('unshelve', '--all', retcode=0)
305
301
 
306
302
        # We should now have 00 and 01~
307
303
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
308
304
        self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
309
305
 
310
306
        # Check ls works
311
 
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
 
307
        lines = self.capture('shelf ls', retcode=0).split('\n')
312
308
        for line in lines:
313
309
            self.assertFalse(line.startswith(' 01'))
314
310
 
315
311
        # Unshelve, if unshelve is confused by the backup it will fail
316
 
        self.run_bzr('unshelve --all', retcode=0)
 
312
        self.run_bzr('unshelve', '--all', retcode=0)
317
313
 
318
314
    def test_shelf_delete(self):
319
315
        self.tree = self.make_branch_and_tree('.')
320
 
        self.tree.lock_write()
321
 
        try:
322
 
            self.__create_and_add_test_file()
323
 
            self.__create_and_add_test_file(filename='test_file2')
324
 
 
325
 
            # Modify the test files
326
 
            # write in binary mode because on win32 line-endings should be LF
327
 
            f = file('test_file', 'wb')
328
 
            f.write(self.MODIFIED)
329
 
            f.close()
330
 
            f = file('test_file2', 'wb')
331
 
            f.write(self.MODIFIED)
332
 
            f.close()
333
 
            new_date = _patch_header_date(self.tree,
334
 
                self.tree.inventory.path2id('test_file'), 'test_file')
335
 
        finally:
336
 
            self.tree.unlock()
 
316
 
 
317
        self.__create_and_add_test_file()
 
318
        self.__create_and_add_test_file(filename='test_file2')
 
319
 
 
320
        # Modify the test files
 
321
        # write in binary mode because on win32 line-endings should be LF
 
322
        f = file('test_file', 'wb')
 
323
        f.write(self.MODIFIED)
 
324
        f.close()
 
325
        f = file('test_file2', 'wb')
 
326
        f.write(self.MODIFIED)
 
327
        f.close()
 
328
        new_date = _patch_header_date(self.tree, 
 
329
            self.tree.inventory.path2id('test_file'), 'test_file')
337
330
 
338
331
        # Shelve the changes
339
 
        self.run_bzr('shelve --all test_file', retcode=0)
340
 
        self.run_bzr('shelve --all test_file2', retcode=0)
 
332
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
333
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
341
334
 
342
335
        self._check_shelf('00', new_date=new_date)
343
336
 
344
337
        # Delete 00
345
 
        self.run_bzr('shelf delete 00', retcode=0)
 
338
        self.run_bzr('shelf', 'delete', '00', retcode=0)
346
339
 
347
340
        # We should now have 01 but not 00, but we should have 00~
348
341
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
353
346
        self._check_shelf('00~', new_date=new_date)
354
347
 
355
348
        # Check ls works
356
 
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
 
349
        lines = self.capture('shelf ls', retcode=0).split('\n')
357
350
        for line in lines:
358
351
            self.assertFalse(line.startswith(' 00'))
359
352
 
360
353
        # Unshelve should unshelve 01
361
 
        self.run_bzr('unshelve --all', retcode=0)
 
354
        self.run_bzr('unshelve', '--all', retcode=0)
362
355
        self.assertEqual(file('test_file2').read(), self.MODIFIED)
363
356
 
364
357
    def test_shelf_gaps(self):
365
358
        self.tree = self.make_branch_and_tree('.')
366
359
        self.__create_and_add_test_file()
367
360
        file('test_file', 'w').write(self.MODIFIED)
368
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
361
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
369
362
        file('test_file', 'w').write(self.MODIFIED)
370
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
363
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
371
364
 
372
365
        # Now delete 00, leaving 01, next shelve should go into 02
373
 
        self.run_bzr('shelf delete 0', retcode=0)
 
366
        self.run_bzr('shelf', 'delete', '0', retcode=0)
374
367
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
375
368
        self.assertFalse(os.path.exists('.shelf/shelves/default/02'))
376
369
        file('test_file', 'w').write(self.MODIFIED)
377
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
370
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
378
371
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
379
372
        self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
380
373
 
385
378
 
386
379
        # Modify then shelve, so we're not upgrading to 00, just for kicks
387
380
        file('test_file', 'w').write(self.MODIFIED)
388
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
381
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
389
382
 
390
383
        open('.bzr-shelf', 'w').write('First old shelf')
391
384
        open('.bzr-shelf-1', 'w').write('Second old shelf')
393
386
 
394
387
        # shelve and unshelve should bitch and do nothing
395
388
        file('test_file', 'w').write('blah blah blah')
396
 
        self.run_bzr('shelve --all', retcode=3)
 
389
        self.run_bzr('shelve', '--all', retcode=3)
397
390
        self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
398
391
        self.assertEqual(file('test_file').read(), 'blah blah blah')
399
 
        self.run_bzr('unshelve --all', retcode=3)
 
392
        self.run_bzr('unshelve', '--all', retcode=3)
400
393
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
401
394
 
402
395
        # Upgrade, make sure it worked
403
 
        self.run_bzr('shelf upgrade', retcode=0)
 
396
        self.run_bzr('shelf', 'upgrade', retcode=0)
404
397
        self.assertEqual(open('.shelf/shelves/default/01').read(),
405
398
                'First old shelf')
406
399
        self.assertEqual(open('.shelf/shelves/default/02').read(),
417
410
        self.assertFalse(os.path.exists('.bzr-shelf-3'))
418
411
 
419
412
        # Shelve should work now
420
 
        self.run_bzr('shelve --all', retcode=0)
 
413
        self.run_bzr('shelve', '--all', retcode=0)
421
414
 
422
415
    def test_shelf_p1_patch(self):
423
416
        self.tree = self.make_branch_and_tree('.')
425
418
        self.__create_and_add_test_file()
426
419
 
427
420
        # Run a benign shelf command to setup .shelf for us
428
 
        self.run_bzr('shelf ls', retcode=0)
 
421
        self.run_bzr('shelf', 'ls', retcode=0)
429
422
 
430
423
        old_tree = self.tree.basis_tree()
431
 
        old_tree.lock_read()
432
 
        self.tree.lock_read()
433
 
        try:
434
 
            old_date = _patch_header_date(old_tree,
435
 
                old_tree.inventory.path2id('test_file'),
436
 
                                          'test_file')
437
 
            new_date = _patch_header_date(self.tree,
438
 
                self.tree.inventory.path2id('test_file'), 'test_file')
439
 
        finally:
440
 
            old_tree.unlock()
441
 
            self.tree.unlock()
 
424
        old_date = _patch_header_date(old_tree, 
 
425
                                      old_tree.inventory.path2id('test_file'),
 
426
                                      'test_file')
 
427
        new_date = _patch_header_date(self.tree, 
 
428
                                      self.tree.inventory.path2id('test_file'),
 
429
                                      'test_file')
442
430
        # Fake a -p0 shelved patch
443
431
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
444
432
                               'new_date' : new_date}
447
435
        open('.shelf/shelves/default/00', 'w').write(diff)
448
436
 
449
437
        # This should work
450
 
        self.run_bzr('unshelve --all', retcode=0)
 
438
        self.run_bzr('unshelve', '--all', retcode=0)
451
439
 
452
440
        self._check_diff()
453
441
 
468
456
        f.close()
469
457
 
470
458
        # Shelve the changes
471
 
        self.run_bzr('shelve --all', retcode=0)
 
459
        self.run_bzr('shelve', '--all', retcode=0)
472
460
 
473
461
        # Working tree should be unchanged
474
 
        diff = self.run_bzr('diff', retcode=0)[0]
 
462
        diff = self.capture('diff', retcode=0)
475
463
        self.assertEqual(diff, '')
476
464
 
477
465
        # Unshelve, should succeed
478
 
        self.run_bzr('unshelve --all', retcode=0)
 
466
        self.run_bzr('unshelve', '--all', retcode=0)
479
467
 
480
468
        self._check_diff(filename='subdir/test_file')
481
469
 
482
470
        # Make sure relative filenames work ok
483
 
        self.run_bzr('shelve test_file --all', retcode=0)
 
471
        self.run_bzr('shelve', 'test_file', '--all', retcode=0)
484
472
 
485
473
    def test_shelf_shelf_bogus_subcommand(self):
486
474
        self.tree = self.make_branch_and_tree('.')
487
 
        self.run_bzr('shelf foo', retcode=3) # <- retcode == 3
 
475
        self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
488
476
 
489
477
    def test_shelf_OOO_unshelve(self):
490
478
        self.tree = self.make_branch_and_tree('.')
498
486
 
499
487
        # Shelve the changes
500
488
        for i in range(1, 5):
501
 
            self.run_bzr(['shelve', '--all', 'test_file%d' % i], retcode=0)
 
489
            self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
502
490
 
503
491
        # Check shelving worked
504
492
        for i in range(1, 5):
509
497
            self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
510
498
 
511
499
        # Unshelve 00
512
 
        self.run_bzr('unshelve --all 00', retcode=0)
 
500
        self.run_bzr('unshelve', '--all', '00', retcode=0)
513
501
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
514
502
 
515
503
        # Check ls works
516
 
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
 
504
        lines = self.capture('shelf ls', retcode=0).split('\n')
517
505
        for line in lines:
518
506
            self.assertFalse(line.startswith(' 00'))
519
507
 
520
508
        # Check we can reshelve once we've unshelved out of order, should be 04
521
509
        self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
522
 
        self.run_bzr('shelve --all')
 
510
        self.run_bzr('shelve', '--all')
523
511
        self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
524
512
 
525
513
        # Check ls works
526
 
        text = self.run_bzr('shelf ls', retcode=0)[0]
 
514
        text = self.capture('shelf ls', retcode=0)
527
515
        for line in text.split('\n'):
528
516
            self.assertFalse(line.startswith(' 00'))
529
517
 
530
518
        # We now have 01,02,03,04
531
519
        # Unshelve 02
532
 
        self.run_bzr('unshelve --all 02', retcode=0)
 
520
        self.run_bzr('unshelve', '--all', '02', retcode=0)
533
521
        self.assertEqual(file('test_file3').read(), self.MODIFIED)
534
522
 
535
523
        # Unshelve the default, this is the reshelved 00, hence modifies file 1
536
 
        self.run_bzr('unshelve --all', retcode=0)
 
524
        self.run_bzr('unshelve', '--all', retcode=0)
537
525
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
538
526
 
539
527
    def test_shelf_switch_basic(self):
542
530
 
543
531
        # This should go to "default"
544
532
        file('test_file', 'w').write(self.MODIFIED)
545
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
533
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
546
534
 
547
535
        # Switch to "other"
548
 
        self.run_bzr('shelf switch other', retcode=0)
 
536
        self.run_bzr('shelf', 'switch', 'other', retcode=0)
549
537
        file('test_file', 'w').write(self.MODIFIED)
550
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
538
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
551
539
 
552
540
        # Check it worked
553
541
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
555
543
        self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
556
544
 
557
545
        # Switch back
558
 
        self.run_bzr('shelf switch default', retcode=0)
 
546
        self.run_bzr('shelf', 'switch', 'default', retcode=0)
559
547
        file('test_file', 'w').write(self.MODIFIED)
560
 
        self.run_bzr('shelve --all test_file', retcode=0)
 
548
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
561
549
 
562
550
        # Check that worked
563
551
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
564
552
        self.assertFalse(os.path.exists('.shelf/shelves/other/01'))
565
553
 
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')
571
 
 
572
554
    def test_shelf_bad_patch_arg(self):
573
555
        self.tree = self.make_branch_and_tree('.')
574
556
 
575
557
        # Check the bad arg handling
576
 
        stdout, error = self.run_bzr('unshelve 01', retcode=3)
 
558
        stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
577
559
        self.assertTrue("Patch '01' doesn't exist on shelf" in error)
578
560
 
579
 
        stdout, error = self.run_bzr('unshelve foo', retcode=3)
 
561
        stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
580
562
        self.assertTrue("Invalid patch name 'foo'" in error)
581
563
 
582
564
        # Hex and is cracky, so it shouldn't work
583
 
        stdout, error = self.run_bzr(['unshelve', '0x00'], retcode=3)
 
565
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
584
566
        self.assertTrue("Invalid patch name '0x00'" in error)
585
567
 
586
568
    def test_color_hunk_selector(self):
618
600
        f = file('test_file', 'wb')
619
601
        f.write(self.MODIFIED)
620
602
        f.close()
621
 
        stdout, error = self.run_bzr('shelve --all --no-color')
622
 
        stdout, error = self.run_bzr('unshelve --all --no-color')
623
 
 
624
 
    def test_shelf_help(self):
625
 
        self.assertContainsRe(cmd_shelf().help(),
626
 
                              'list\n.*List the patches on the current shelf')
627
 
 
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')
 
603
        stdout, error = self.run_bzr_captured(['shelve', '--all', 
 
604
                                               '--no-color'])
 
605
        stdout, error = self.run_bzr_captured(['unshelve', '--all', 
 
606
                                               '--no-color'])