~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-03-18 17:14:51 UTC
  • mfrom: (0.1.98 shelf)
  • Revision ID: aaron.bentley@utoronto.ca-20060318171451-2b15a9bcf7b77d69
Merge from shelf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
from bzrlib.diff import _patch_header_date
4
3
import bzrlib.tests
5
4
import os.path
6
5
 
7
6
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
8
7
    ORIGINAL = '\n\nhello test world\n\n'
9
8
    MODIFIED = '\n\ngoodbye test world\n\n'
10
 
    DIFF_HEADER = "=== modified file '%(filename)s'\n"
11
 
    DIFF_1 = """--- %(filename)s\t%(old_date)s
12
 
+++ %(filename)s\t%(new_date)s
 
9
    DIFF_HEADER = "=== modified file 'a/test_file'\n"
 
10
    DIFF_1 = """--- a/test_file\t
 
11
+++ b/test_file\t
13
12
@@ -1,4 +1,4 @@
14
13
 
15
14
 
17
16
+goodbye test world
18
17
 
19
18
"""
20
 
    DIFF_2 = """--- test_file\t%(old_date)s
21
 
+++ test_file\t%(new_date)s
 
19
    DIFF_2 = """--- a/test_file\t
 
20
+++ b/test_file\t
22
21
@@ -1,4 +1,4 @@
23
22
 
24
23
 
26
25
+hello test world
27
26
 
28
27
"""
29
 
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
30
 
        old_tree = self.tree.basis_tree()
31
 
        old_date = _patch_header_date(old_tree, 
32
 
                                      old_tree.inventory.path2id(filename),
33
 
                                      filename)
34
 
        new_date = _patch_header_date(self.tree, 
35
 
                                      self.tree.inventory.path2id(filename),
36
 
                                      filename)
37
 
        keys = { 'filename' : filename , 'old_date': old_date, 
38
 
                 'new_date': new_date}
39
 
        hdr  = self.DIFF_HEADER % keys
40
 
        diff = diff % keys
41
 
        self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
42
 
 
43
 
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
44
 
                     new_date=None):
45
 
        old_tree = self.tree.basis_tree()
46
 
        old_date = _patch_header_date(old_tree, 
47
 
                                      old_tree.inventory.path2id(filename),
48
 
                                      filename)
49
 
        diff = diff % { 'filename' : filename, 'old_date': old_date,
50
 
                        'new_date': new_date}
51
 
        shelf = open(os.path.join(self.tree.basedir,
52
 
                '.shelf/shelves/default/' + idx)).read()
53
 
        shelf = shelf[shelf.index('\n') + 1:] # skip the message
54
 
        self.assertEqual(shelf, diff)
55
 
 
56
28
    def test_shelf(self):
57
29
        self.__test_loop(1)
58
30
 
60
32
        self.__test_loop(10)
61
33
 
62
34
    def __test_loop(self, count):
63
 
        self.tree = self.make_branch_and_tree('.')
64
 
        self.__create_and_add_test_file()
 
35
        tree = self.make_branch_and_tree('.')
 
36
        self.__create_and_add_test_file(tree)
65
37
 
66
38
        while count > 0:
67
39
            count -= 1
68
40
 
69
41
            # Modify the test file
70
 
            # write in binary mode because on win32 line-endings should be LF
71
 
            f = file('test_file', 'wb')
72
 
            f.write(self.MODIFIED)
73
 
            f.close()
 
42
            file('test_file', 'w').write(self.MODIFIED)
74
43
 
75
 
            self._check_diff()
76
 
            
77
 
            new_date = _patch_header_date(self.tree, 
78
 
                self.tree.inventory.path2id('test_file'), 'test_file')
 
44
            # Check the diff is right
 
45
            self.assertEqual(self.capture('diff', retcode=1),
 
46
                self.DIFF_HEADER + self.DIFF_1 + '\n')
79
47
 
80
48
            # Shelve the changes
81
49
            self.run_bzr('shelve', '--all', retcode=0)
86
54
            # Make sure the file is actually back the way it was
87
55
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
88
56
 
89
 
            self._check_shelf('00', new_date=new_date)
 
57
            # Check the shelf is right
 
58
            shelf = open(os.path.join(tree.branch.base,
 
59
                        '.shelf/shelves/default/00')).read()
 
60
            shelf = shelf[shelf.index('\n') + 1:] # skip the message
 
61
            self.assertEqual(shelf, self.DIFF_1)
90
62
 
91
63
            # Unshelve
92
64
            self.run_bzr('unshelve', '--all', retcode=0)
93
65
 
94
 
            self._check_diff()
 
66
            # Check the diff is right again
 
67
            self.assertEqual(self.capture('diff', retcode=1),
 
68
                self.DIFF_HEADER + self.DIFF_1 + '\n')
95
69
 
96
70
            # Check the shelved patch was backed up
97
 
            self._check_shelf('00~', new_date=new_date)
 
71
            shelf = open(os.path.join(tree.branch.base,
 
72
                        '.shelf/shelves/default/00~')).read()
 
73
            shelf = shelf[shelf.index('\n') + 1:] # skip the message
 
74
            self.assertEqual(shelf, self.DIFF_1)
98
75
 
99
76
            # Make sure the file is back the way it should be
100
77
            self.assertEqual(file('test_file').read(), self.MODIFIED)
101
78
 
102
79
    def test_shelf_nothing_to_shelve(self):
103
80
        import os.path
104
 
        self.tree = self.make_branch_and_tree('.')
105
 
        self.__create_and_add_test_file()
 
81
        tree = self.make_branch_and_tree('.')
 
82
        self.__create_and_add_test_file(tree)
106
83
 
107
84
        # Shelve the changes
108
85
        self.run_bzr('shelve', '--all', retcode=3)
109
86
 
110
 
        if os.path.exists(os.path.join(self.tree.branch.base,
 
87
        if os.path.exists(os.path.join(tree.branch.base,
111
88
                '.shelf/shelves/default/00')):
112
89
            self.fail("Shelf exists, but it shouldn't")
113
90
 
114
 
    def __create_and_add_test_file(self, filename='test_file'):
115
 
        # write in binary mode because on win32 line-endings should be LF
116
 
        f = open(filename, 'wb')
 
91
    def __create_and_add_test_file(self, tree, filename='test_file'):
 
92
        f = open(filename, 'w')
117
93
        f.write(self.ORIGINAL)
118
94
        f.close()
119
 
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), filename)))
120
 
        self.tree.commit(message='add %s' % filename)
 
95
        tree.add(tree.relpath(os.path.join(os.getcwd(), filename)))
 
96
        tree.commit(message='add %s' % filename)
121
97
 
122
98
    def test_shelf_with_revision(self):
123
 
        self.tree = self.make_branch_and_tree('.')
 
99
        tree = self.make_branch_and_tree('.')
124
100
 
125
 
        self.__create_and_add_test_file()
 
101
        self.__create_and_add_test_file(tree)
126
102
 
127
103
        # Modify the test file and commit it
128
104
        self.build_tree_contents([('test_file', self.MODIFIED)])
129
 
        self.tree.commit(message='update test_file')
 
105
        tree.commit(message='update test_file')
130
106
 
131
107
        # Shelve the changes
132
108
        self.run_bzr('shelve', '--all', '-r', '1', retcode=0)
133
109
 
134
 
        self._check_diff(self.DIFF_2)
 
110
        # Check the diff is right
 
111
        self.assertEqual(self.capture('diff', retcode=1),
 
112
            self.DIFF_HEADER + self.DIFF_2 + '\n')
135
113
 
136
114
        # Make sure the file is the way it should be
137
115
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
143
121
        self.assertEqual(file('test_file').read(), self.MODIFIED)
144
122
 
145
123
    def test_shelf_with_two_revisions(self):
146
 
        self.tree = self.make_branch_and_tree('.')
 
124
        tree = self.make_branch_and_tree('.')
147
125
 
148
126
        cmd = 'shelve --all -r 1..2'
149
127
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
152
130
            'bzr: ERROR: shelve only accepts a single revision parameter.')
153
131
 
154
132
    def test_shelf_show_basic(self):
155
 
        self.tree = self.make_branch_and_tree('.')
156
 
        self.__create_and_add_test_file()
157
 
        self.__test_show(self.tree, '00')
 
133
        tree = self.make_branch_and_tree('.')
 
134
        self.__create_and_add_test_file(tree)
 
135
        self.__test_show(tree, '00')
158
136
 
159
137
    def __test_show(self, tree, patch):
160
138
        # Modify the test file
167
145
        self.assertEqual(self.capture('diff', retcode=0), '')
168
146
 
169
147
        # Check the shelf is right
170
 
        shelf = open(os.path.join(self.tree.basedir,
 
148
        shelf = open(os.path.join(tree.branch.base,
171
149
                    '.shelf/shelves/default', patch)).read()
172
150
        self.assertTrue('patch %s' % patch in shelf)
173
151
 
176
154
        self.assertEqual(shown, shelf)
177
155
 
178
156
    def test_shelf_show_multi(self):
179
 
        self.tree = self.make_branch_and_tree('.')
180
 
        self.__create_and_add_test_file()
181
 
        self.__test_show(self.tree, '00')
182
 
        self.__test_show(self.tree, '01')
183
 
        self.__test_show(self.tree, '02')
 
157
        tree = self.make_branch_and_tree('.')
 
158
        self.__create_and_add_test_file(tree)
 
159
        self.__test_show(tree, '00')
 
160
        self.__test_show(tree, '01')
 
161
        self.__test_show(tree, '02')
184
162
 
185
163
        # Now check we can show a previously shelved patch
186
 
        shelf = open(os.path.join(self.tree.basedir,
 
164
        shelf = open(os.path.join(tree.branch.base,
187
165
                    '.shelf/shelves/default/00')).read()
188
166
        self.assertTrue('patch 00' in shelf)
189
167
 
191
169
        shown = self.capture('shelf show 00', retcode=0)
192
170
        self.assertEqual(shown, shelf)
193
171
 
194
 
    def test_shelf_show_unspecified(self):
195
 
        self.tree = self.make_branch_and_tree('.')
196
 
        self.__create_and_add_test_file()
197
 
        self.__test_show(self.tree, '00')
198
 
        self.__test_show(self.tree, '01')
199
 
        self.__test_show(self.tree, '02')
200
 
 
201
 
        # Check that not specifying at patch gets us the most recent
202
 
        shelf = open(os.path.join(self.tree.basedir,
203
 
                    '.shelf/shelves/default/02')).read()
204
 
        self.assertTrue('patch 02' in shelf)
205
 
 
206
 
        # Check the shown output is right
207
 
        shown = self.capture('shelf show', retcode=0)
208
 
        self.assertEqual(shown, shelf)
209
 
 
210
172
    def test_shelf_show_with_no_patch(self):
211
 
        self.tree = self.make_branch_and_tree('.')
 
173
        tree = self.make_branch_and_tree('.')
212
174
        stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
213
175
        self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
214
176
 
215
177
    def test_shelf_unshelve_failure(self):
216
 
        self.tree = self.make_branch_and_tree('.')
 
178
        tree = self.make_branch_and_tree('.')
217
179
 
218
 
        self.__create_and_add_test_file()
 
180
        self.__create_and_add_test_file(tree)
219
181
 
220
182
        # Modify the test file
221
183
        file('test_file', 'w').write(self.MODIFIED)
224
186
        self.run_bzr('shelve', '--all', retcode=0)
225
187
 
226
188
        # Write an unapplyable patch into the shelf
227
 
        shelf = open(os.path.join(self.tree.basedir,
 
189
        shelf = open(os.path.join(tree.branch.base,
228
190
                    '.shelf/shelves/default/00'), 'w')
229
191
        shelf.write(self.DIFF_2)
230
192
        shelf.close()
233
195
        self.run_bzr('unshelve', '--all', retcode=3)
234
196
 
235
197
        # Make sure the patch is still there, eventhough it's broken
236
 
        shelf = open(os.path.join(self.tree.basedir,
 
198
        shelf = open(os.path.join(tree.branch.base,
237
199
                    '.shelf/shelves/default/00')).read()
238
200
        self.assertEqual(shelf, self.DIFF_2)
239
201
 
242
204
        self.assertEqual(diff, '')
243
205
 
244
206
    def test_shelf_unshelve_failure_two_hunks(self):
245
 
        self.tree = self.make_branch_and_tree('.')
 
207
        tree = self.make_branch_and_tree('.')
246
208
 
247
 
        self.__create_and_add_test_file()
248
 
        self.__create_and_add_test_file(filename='test_file2')
 
209
        self.__create_and_add_test_file(tree)
 
210
        self.__create_and_add_test_file(tree, filename='test_file2')
249
211
 
250
212
        # Modify the test files
251
213
        file('test_file', 'w').write(self.MODIFIED)
256
218
 
257
219
        # Put the changes to test_file back, the shelved patch won't apply now
258
220
        file('test_file', 'w').write(self.MODIFIED)
259
 
        self.tree.commit(message='screw up test_file')
 
221
        tree.commit(message='screw up test_file')
260
222
 
261
223
        # Unshelve, should fail
262
224
        self.run_bzr('unshelve', '--all', retcode=3)
271
233
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
272
234
 
273
235
    def test_shelf_after_unshelve(self):
274
 
        self.tree = self.make_branch_and_tree('.')
 
236
        tree = self.make_branch_and_tree('.')
275
237
 
276
 
        self.__create_and_add_test_file()
277
 
        self.__create_and_add_test_file(filename='test_file2')
 
238
        self.__create_and_add_test_file(tree)
 
239
        self.__create_and_add_test_file(tree, filename='test_file2')
278
240
 
279
241
        # Modify the test files
280
242
        file('test_file', 'w').write(self.MODIFIED)
292
254
        self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
293
255
 
294
256
        # Check ls works
295
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
296
 
        for line in lines:
 
257
        list = self.capture('shelf ls', retcode=0).split('\n')
 
258
        for line in list:
297
259
            self.assertFalse(line.startswith(' 01'))
298
260
 
299
261
        # Unshelve, if unshelve is confused by the backup it will fail
300
262
        self.run_bzr('unshelve', '--all', retcode=0)
301
263
 
302
264
    def test_shelf_delete(self):
303
 
        self.tree = self.make_branch_and_tree('.')
 
265
        tree = self.make_branch_and_tree('.')
304
266
 
305
 
        self.__create_and_add_test_file()
306
 
        self.__create_and_add_test_file(filename='test_file2')
 
267
        self.__create_and_add_test_file(tree)
 
268
        self.__create_and_add_test_file(tree, filename='test_file2')
307
269
 
308
270
        # Modify the test files
309
 
        # write in binary mode because on win32 line-endings should be LF
310
 
        f = file('test_file', 'wb')
311
 
        f.write(self.MODIFIED)
312
 
        f.close()
313
 
        f = file('test_file2', 'wb')
314
 
        f.write(self.MODIFIED)
315
 
        f.close()
316
 
        new_date = _patch_header_date(self.tree, 
317
 
            self.tree.inventory.path2id('test_file'), 'test_file')
 
271
        file('test_file', 'w').write(self.MODIFIED)
 
272
        file('test_file2', 'w').write(self.MODIFIED)
318
273
 
319
274
        # Shelve the changes
320
275
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
321
276
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
322
277
 
323
 
        self._check_shelf('00', new_date=new_date)
324
 
 
325
278
        # Delete 00
326
279
        self.run_bzr('shelf', 'delete', '00', retcode=0)
327
280
 
328
 
        # We should now have 01 but not 00, but we should have 00~
 
281
        # We should now have 01 but not 00
329
282
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
330
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/00~'))
331
283
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
332
284
 
333
 
        # Check the backup is right
334
 
        self._check_shelf('00~', new_date=new_date)
335
 
 
336
285
        # Check ls works
337
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
338
 
        for line in lines:
 
286
        list = self.capture('shelf ls', retcode=0).split('\n')
 
287
        for line in list:
339
288
            self.assertFalse(line.startswith(' 00'))
340
289
 
341
290
        # Unshelve should unshelve 01
343
292
        self.assertEqual(file('test_file2').read(), self.MODIFIED)
344
293
 
345
294
    def test_shelf_gaps(self):
346
 
        self.tree = self.make_branch_and_tree('.')
347
 
        self.__create_and_add_test_file()
 
295
        tree = self.make_branch_and_tree('.')
 
296
        self.__create_and_add_test_file(tree)
348
297
        file('test_file', 'w').write(self.MODIFIED)
349
298
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
350
299
        file('test_file', 'w').write(self.MODIFIED)
360
309
        self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
361
310
 
362
311
    def test_shelf_upgrade(self):
363
 
        self.tree = self.make_branch_and_tree('.')
 
312
        tree = self.make_branch_and_tree('.')
364
313
 
365
 
        self.__create_and_add_test_file()
 
314
        self.__create_and_add_test_file(tree)
366
315
 
367
316
        # Modify then shelve, so we're not upgrading to 00, just for kicks
368
317
        file('test_file', 'w').write(self.MODIFIED)
400
349
        # Shelve should work now
401
350
        self.run_bzr('shelve', '--all', retcode=0)
402
351
 
403
 
    def test_shelf_p1_patch(self):
404
 
        self.tree = self.make_branch_and_tree('.')
 
352
    def test_shelf_p0_patch(self):
 
353
        tree = self.make_branch_and_tree('.')
405
354
 
406
 
        self.__create_and_add_test_file()
 
355
        self.__create_and_add_test_file(tree)
407
356
 
408
357
        # Run a benign shelf command to setup .shelf for us
409
358
        self.run_bzr('shelf', 'ls', retcode=0)
410
359
 
411
 
        old_tree = self.tree.basis_tree()
412
 
        old_date = _patch_header_date(old_tree, 
413
 
                                      old_tree.inventory.path2id('test_file'),
414
 
                                      'test_file')
415
 
        new_date = _patch_header_date(self.tree, 
416
 
                                      self.tree.inventory.path2id('test_file'),
417
 
                                      'test_file')
418
360
        # Fake a -p0 shelved patch
419
 
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
420
 
                               'new_date' : new_date}
421
 
        diff = diff.replace('--- ', '--- a/')
422
 
        diff = diff.replace('+++ ', '+++ b/')
 
361
        diff = self.DIFF_1
 
362
        diff = diff.replace('a/', '')
 
363
        diff = diff.replace('b/', '')
423
364
        open('.shelf/shelves/default/00', 'w').write(diff)
424
365
 
425
366
        # This should work
426
367
        self.run_bzr('unshelve', '--all', retcode=0)
427
368
 
428
 
        self._check_diff()
 
369
        # Check the diff is right
 
370
        self.assertEqual(self.capture('diff', retcode=1),
 
371
            self.DIFF_HEADER + self.DIFF_1 + '\n')
429
372
 
430
373
    def test_shelf_shelve_in_subdir(self):
431
 
        self.tree = self.make_branch_and_tree('.')
432
 
 
433
 
        subdir = 'subdir'
434
 
        os.mkdir(subdir)
435
 
        self.tree.add(subdir)
436
 
        os.chdir(subdir)
437
 
 
438
 
        self.__create_and_add_test_file()
 
374
        tree = self.make_branch_and_tree('.')
 
375
 
 
376
        self.__create_and_add_test_file(tree)
439
377
 
440
378
        # Modify the test file
441
 
        # write in binary mode because on win32 line-endings should be LF
442
 
        f = file('test_file', 'wb')
443
 
        f.write(self.MODIFIED)
444
 
        f.close()
 
379
        file('test_file', 'w').write(self.MODIFIED)
445
380
 
446
381
        # Shelve the changes
447
382
        self.run_bzr('shelve', '--all', retcode=0)
453
388
        # Unshelve, should succeed
454
389
        self.run_bzr('unshelve', '--all', retcode=0)
455
390
 
456
 
        self._check_diff(filename='subdir/test_file')
457
 
 
458
 
        # Make sure relative filenames work ok
459
 
        self.run_bzr('shelve', 'test_file', '--all', retcode=0)
460
 
 
461
 
    def test_shelf_shelf_bogus_subcommand(self):
462
 
        self.tree = self.make_branch_and_tree('.')
463
 
        self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
464
 
 
465
 
    def test_shelf_OOO_unshelve(self):
466
 
        self.tree = self.make_branch_and_tree('.')
467
 
 
468
 
        for i in range(1, 5):
469
 
            self.__create_and_add_test_file(filename='test_file%d' % i)
470
 
 
471
 
        # Modify the test files
472
 
        for i in range(1, 5):
473
 
            file('test_file%d' % i, 'w').write(self.MODIFIED)
474
 
 
475
 
        # Shelve the changes
476
 
        for i in range(1, 5):
477
 
            self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
478
 
 
479
 
        # Check shelving worked
480
 
        for i in range(1, 5):
481
 
            self.assertEqual(file('test_file%d' % i).read(), self.ORIGINAL)
482
 
 
483
 
        # We should now have 00-03
484
 
        for i in range(0, 4):
485
 
            self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
486
 
 
487
 
        # Unshelve 00
488
 
        self.run_bzr('unshelve', '--all', '00', retcode=0)
489
 
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
490
 
 
491
 
        # Check ls works
492
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
493
 
        for line in lines:
494
 
            self.assertFalse(line.startswith(' 00'))
495
 
 
496
 
        # Check we can reshelve once we've unshelved out of order, should be 04
497
 
        self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
498
 
        self.run_bzr('shelve', '--all')
499
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
500
 
 
501
 
        # Check ls works
502
 
        text = self.capture('shelf ls', retcode=0)
503
 
        for line in text.split('\n'):
504
 
            self.assertFalse(line.startswith(' 00'))
505
 
 
506
 
        # We now have 01,02,03,04
507
 
        # Unshelve 02
508
 
        self.run_bzr('unshelve', '--all', '02', retcode=0)
509
 
        self.assertEqual(file('test_file3').read(), self.MODIFIED)
510
 
 
511
 
        # Unshelve the default, this is the reshelved 00, hence modifies file 1
512
 
        self.run_bzr('unshelve', '--all', retcode=0)
513
 
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
514
 
 
515
 
    def test_shelf_switch_basic(self):
516
 
        self.tree = self.make_branch_and_tree('.')
517
 
        self.__create_and_add_test_file()
518
 
 
519
 
        # This should go to "default"
520
 
        file('test_file', 'w').write(self.MODIFIED)
521
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
522
 
 
523
 
        # Switch to "other"
524
 
        self.run_bzr('shelf', 'switch', 'other', retcode=0)
525
 
        file('test_file', 'w').write(self.MODIFIED)
526
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
527
 
 
528
 
        # Check it worked
529
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
530
 
        self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
531
 
        self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
532
 
 
533
 
        # Switch back
534
 
        self.run_bzr('shelf', 'switch', 'default', retcode=0)
535
 
        file('test_file', 'w').write(self.MODIFIED)
536
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
537
 
 
538
 
        # Check that worked
539
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
540
 
        self.assertFalse(os.path.exists('.shelf/shelves/other/01'))
541
 
 
542
 
    def test_shelf_bad_patch_arg(self):
543
 
        self.tree = self.make_branch_and_tree('.')
544
 
 
545
 
        # Check the bad arg handling
546
 
        stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
547
 
        self.assertTrue("Patch '01' doesn't exist on shelf" in error)
548
 
 
549
 
        stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
550
 
        self.assertTrue("Invalid patch name 'foo'" in error)
551
 
 
552
 
        # Hex and is cracky, so it shouldn't work
553
 
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
554
 
        self.assertTrue("Invalid patch name '0x00'" in error)
 
391
        # Check the diff is right
 
392
        self.assertEqual(self.capture('diff', retcode=1),
 
393
            self.DIFF_HEADER + self.DIFF_1 + '\n')