~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-08-07 03:07:35 UTC
  • mto: This revision was merged to the branch mainline in revision 425.
  • Revision ID: aaron.bentley@utoronto.ca-20060807030735-0a9f8330ce1a836a
Add --no-color option to shelf

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