~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-12-12 16:50:31 UTC
  • Revision ID: abentley@panoramicfeedback.com-20061212165031-51w8gjy1eps1vnw0
update NEWS

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