~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-07-18 20:57:43 UTC
  • mfrom: (419.1.1 bzrtools.win32)
  • Revision ID: abentley@panoramicfeedback.com-20060718205743-f2f5055504731722
Merge shelf win32 fix

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
3
4
import bzrlib.tests
4
5
import os.path
5
6
 
6
7
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
7
8
    ORIGINAL = '\n\nhello test world\n\n'
8
9
    MODIFIED = '\n\ngoodbye test world\n\n'
9
 
    DIFF_HEADER = "=== modified file 'a/test_file'\n"
10
 
    DIFF_1 = """--- a/test_file\t
11
 
+++ b/test_file\t
 
10
    DIFF_HEADER = "=== modified file '%(filename)s'\n"
 
11
    DIFF_1 = """--- %(filename)s\t%(old_date)s
 
12
+++ %(filename)s\t%(new_date)s
12
13
@@ -1,4 +1,4 @@
13
14
 
14
15
 
16
17
+goodbye test world
17
18
 
18
19
"""
19
 
    DIFF_2 = """--- a/test_file\t
20
 
+++ b/test_file\t
 
20
    DIFF_2 = """--- test_file\t%(old_date)s
 
21
+++ test_file\t%(new_date)s
21
22
@@ -1,4 +1,4 @@
22
23
 
23
24
 
25
26
+hello test world
26
27
 
27
28
"""
 
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
 
28
56
    def test_shelf(self):
29
57
        self.__test_loop(1)
30
58
 
32
60
        self.__test_loop(10)
33
61
 
34
62
    def __test_loop(self, count):
35
 
        tree = self.make_branch_and_tree('.')
36
 
        self.__create_and_add_test_file(tree)
 
63
        self.tree = self.make_branch_and_tree('.')
 
64
        self.__create_and_add_test_file()
37
65
 
38
66
        while count > 0:
39
67
            count -= 1
40
68
 
41
69
            # Modify the test file
42
 
            file('test_file', 'w').write(self.MODIFIED)
 
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()
43
74
 
44
 
            # Check the diff is right
45
 
            self.assertEqual(self.capture('diff', retcode=1),
46
 
                self.DIFF_HEADER + self.DIFF_1 + '\n')
 
75
            self._check_diff()
 
76
            
 
77
            new_date = _patch_header_date(self.tree, 
 
78
                self.tree.inventory.path2id('test_file'), 'test_file')
47
79
 
48
80
            # Shelve the changes
49
81
            self.run_bzr('shelve', '--all', retcode=0)
54
86
            # Make sure the file is actually back the way it was
55
87
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
56
88
 
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)
 
89
            self._check_shelf('00', new_date=new_date)
62
90
 
63
91
            # Unshelve
64
92
            self.run_bzr('unshelve', '--all', retcode=0)
65
93
 
66
 
            # Check the diff is right again
67
 
            self.assertEqual(self.capture('diff', retcode=1),
68
 
                self.DIFF_HEADER + self.DIFF_1 + '\n')
 
94
            self._check_diff()
69
95
 
70
96
            # Check the shelved patch was backed up
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)
 
97
            self._check_shelf('00~', new_date=new_date)
75
98
 
76
99
            # Make sure the file is back the way it should be
77
100
            self.assertEqual(file('test_file').read(), self.MODIFIED)
78
101
 
79
102
    def test_shelf_nothing_to_shelve(self):
80
103
        import os.path
81
 
        tree = self.make_branch_and_tree('.')
82
 
        self.__create_and_add_test_file(tree)
 
104
        self.tree = self.make_branch_and_tree('.')
 
105
        self.__create_and_add_test_file()
83
106
 
84
107
        # Shelve the changes
85
108
        self.run_bzr('shelve', '--all', retcode=3)
86
109
 
87
 
        if os.path.exists(os.path.join(tree.branch.base,
 
110
        if os.path.exists(os.path.join(self.tree.branch.base,
88
111
                '.shelf/shelves/default/00')):
89
112
            self.fail("Shelf exists, but it shouldn't")
90
113
 
91
 
    def __create_and_add_test_file(self, tree, filename='test_file'):
92
 
        f = open(filename, 'w')
 
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')
93
117
        f.write(self.ORIGINAL)
94
118
        f.close()
95
 
        tree.add(tree.relpath(os.path.join(os.getcwd(), filename)))
96
 
        tree.commit(message='add %s' % filename)
 
119
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), filename)))
 
120
        self.tree.commit(message='add %s' % filename)
97
121
 
98
122
    def test_shelf_with_revision(self):
99
 
        tree = self.make_branch_and_tree('.')
 
123
        self.tree = self.make_branch_and_tree('.')
100
124
 
101
 
        self.__create_and_add_test_file(tree)
 
125
        self.__create_and_add_test_file()
102
126
 
103
127
        # Modify the test file and commit it
104
128
        self.build_tree_contents([('test_file', self.MODIFIED)])
105
 
        tree.commit(message='update test_file')
 
129
        self.tree.commit(message='update test_file')
106
130
 
107
131
        # Shelve the changes
108
132
        self.run_bzr('shelve', '--all', '-r', '1', retcode=0)
109
133
 
110
 
        # Check the diff is right
111
 
        self.assertEqual(self.capture('diff', retcode=1),
112
 
            self.DIFF_HEADER + self.DIFF_2 + '\n')
 
134
        self._check_diff(self.DIFF_2)
113
135
 
114
136
        # Make sure the file is the way it should be
115
137
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
121
143
        self.assertEqual(file('test_file').read(), self.MODIFIED)
122
144
 
123
145
    def test_shelf_with_two_revisions(self):
124
 
        tree = self.make_branch_and_tree('.')
 
146
        self.tree = self.make_branch_and_tree('.')
125
147
 
126
148
        cmd = 'shelve --all -r 1..2'
127
149
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
130
152
            'bzr: ERROR: shelve only accepts a single revision parameter.')
131
153
 
132
154
    def test_shelf_show_basic(self):
133
 
        tree = self.make_branch_and_tree('.')
134
 
        self.__create_and_add_test_file(tree)
135
 
        self.__test_show(tree, '00')
 
155
        self.tree = self.make_branch_and_tree('.')
 
156
        self.__create_and_add_test_file()
 
157
        self.__test_show(self.tree, '00')
136
158
 
137
159
    def __test_show(self, tree, patch):
138
160
        # Modify the test file
145
167
        self.assertEqual(self.capture('diff', retcode=0), '')
146
168
 
147
169
        # Check the shelf is right
148
 
        shelf = open(os.path.join(tree.branch.base,
 
170
        shelf = open(os.path.join(self.tree.basedir,
149
171
                    '.shelf/shelves/default', patch)).read()
150
172
        self.assertTrue('patch %s' % patch in shelf)
151
173
 
154
176
        self.assertEqual(shown, shelf)
155
177
 
156
178
    def test_shelf_show_multi(self):
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')
 
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')
162
184
 
163
185
        # Now check we can show a previously shelved patch
164
 
        shelf = open(os.path.join(tree.branch.base,
 
186
        shelf = open(os.path.join(self.tree.basedir,
165
187
                    '.shelf/shelves/default/00')).read()
166
188
        self.assertTrue('patch 00' in shelf)
167
189
 
169
191
        shown = self.capture('shelf show 00', retcode=0)
170
192
        self.assertEqual(shown, shelf)
171
193
 
 
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
 
172
210
    def test_shelf_show_with_no_patch(self):
173
 
        tree = self.make_branch_and_tree('.')
 
211
        self.tree = self.make_branch_and_tree('.')
174
212
        stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
175
213
        self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
176
214
 
177
215
    def test_shelf_unshelve_failure(self):
178
 
        tree = self.make_branch_and_tree('.')
 
216
        self.tree = self.make_branch_and_tree('.')
179
217
 
180
 
        self.__create_and_add_test_file(tree)
 
218
        self.__create_and_add_test_file()
181
219
 
182
220
        # Modify the test file
183
221
        file('test_file', 'w').write(self.MODIFIED)
186
224
        self.run_bzr('shelve', '--all', retcode=0)
187
225
 
188
226
        # Write an unapplyable patch into the shelf
189
 
        shelf = open(os.path.join(tree.branch.base,
 
227
        shelf = open(os.path.join(self.tree.basedir,
190
228
                    '.shelf/shelves/default/00'), 'w')
191
229
        shelf.write(self.DIFF_2)
192
230
        shelf.close()
195
233
        self.run_bzr('unshelve', '--all', retcode=3)
196
234
 
197
235
        # Make sure the patch is still there, eventhough it's broken
198
 
        shelf = open(os.path.join(tree.branch.base,
 
236
        shelf = open(os.path.join(self.tree.basedir,
199
237
                    '.shelf/shelves/default/00')).read()
200
238
        self.assertEqual(shelf, self.DIFF_2)
201
239
 
204
242
        self.assertEqual(diff, '')
205
243
 
206
244
    def test_shelf_unshelve_failure_two_hunks(self):
207
 
        tree = self.make_branch_and_tree('.')
 
245
        self.tree = self.make_branch_and_tree('.')
208
246
 
209
 
        self.__create_and_add_test_file(tree)
210
 
        self.__create_and_add_test_file(tree, filename='test_file2')
 
247
        self.__create_and_add_test_file()
 
248
        self.__create_and_add_test_file(filename='test_file2')
211
249
 
212
250
        # Modify the test files
213
251
        file('test_file', 'w').write(self.MODIFIED)
218
256
 
219
257
        # Put the changes to test_file back, the shelved patch won't apply now
220
258
        file('test_file', 'w').write(self.MODIFIED)
221
 
        tree.commit(message='screw up test_file')
 
259
        self.tree.commit(message='screw up test_file')
222
260
 
223
261
        # Unshelve, should fail
224
262
        self.run_bzr('unshelve', '--all', retcode=3)
233
271
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
234
272
 
235
273
    def test_shelf_after_unshelve(self):
236
 
        tree = self.make_branch_and_tree('.')
 
274
        self.tree = self.make_branch_and_tree('.')
237
275
 
238
 
        self.__create_and_add_test_file(tree)
239
 
        self.__create_and_add_test_file(tree, filename='test_file2')
 
276
        self.__create_and_add_test_file()
 
277
        self.__create_and_add_test_file(filename='test_file2')
240
278
 
241
279
        # Modify the test files
242
280
        file('test_file', 'w').write(self.MODIFIED)
254
292
        self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
255
293
 
256
294
        # Check ls works
257
 
        list = self.capture('shelf ls', retcode=0).split('\n')
258
 
        for line in list:
 
295
        lines = self.capture('shelf ls', retcode=0).split('\n')
 
296
        for line in lines:
259
297
            self.assertFalse(line.startswith(' 01'))
260
298
 
261
299
        # Unshelve, if unshelve is confused by the backup it will fail
262
300
        self.run_bzr('unshelve', '--all', retcode=0)
263
301
 
264
302
    def test_shelf_delete(self):
265
 
        tree = self.make_branch_and_tree('.')
 
303
        self.tree = self.make_branch_and_tree('.')
266
304
 
267
 
        self.__create_and_add_test_file(tree)
268
 
        self.__create_and_add_test_file(tree, filename='test_file2')
 
305
        self.__create_and_add_test_file()
 
306
        self.__create_and_add_test_file(filename='test_file2')
269
307
 
270
308
        # Modify the test files
271
 
        file('test_file', 'w').write(self.MODIFIED)
272
 
        file('test_file2', 'w').write(self.MODIFIED)
 
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')
273
318
 
274
319
        # Shelve the changes
275
320
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
276
321
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
277
322
 
 
323
        self._check_shelf('00', new_date=new_date)
 
324
 
278
325
        # Delete 00
279
326
        self.run_bzr('shelf', 'delete', '00', retcode=0)
280
327
 
281
 
        # We should now have 01 but not 00
 
328
        # We should now have 01 but not 00, but we should have 00~
282
329
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
 
330
        self.assertTrue(os.path.exists('.shelf/shelves/default/00~'))
283
331
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
284
332
 
 
333
        # Check the backup is right
 
334
        self._check_shelf('00~', new_date=new_date)
 
335
 
285
336
        # Check ls works
286
 
        list = self.capture('shelf ls', retcode=0).split('\n')
287
 
        for line in list:
 
337
        lines = self.capture('shelf ls', retcode=0).split('\n')
 
338
        for line in lines:
288
339
            self.assertFalse(line.startswith(' 00'))
289
340
 
290
341
        # Unshelve should unshelve 01
292
343
        self.assertEqual(file('test_file2').read(), self.MODIFIED)
293
344
 
294
345
    def test_shelf_gaps(self):
295
 
        tree = self.make_branch_and_tree('.')
296
 
        self.__create_and_add_test_file(tree)
 
346
        self.tree = self.make_branch_and_tree('.')
 
347
        self.__create_and_add_test_file()
297
348
        file('test_file', 'w').write(self.MODIFIED)
298
349
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
299
350
        file('test_file', 'w').write(self.MODIFIED)
309
360
        self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
310
361
 
311
362
    def test_shelf_upgrade(self):
312
 
        tree = self.make_branch_and_tree('.')
 
363
        self.tree = self.make_branch_and_tree('.')
313
364
 
314
 
        self.__create_and_add_test_file(tree)
 
365
        self.__create_and_add_test_file()
315
366
 
316
367
        # Modify then shelve, so we're not upgrading to 00, just for kicks
317
368
        file('test_file', 'w').write(self.MODIFIED)
349
400
        # Shelve should work now
350
401
        self.run_bzr('shelve', '--all', retcode=0)
351
402
 
352
 
    def test_shelf_p0_patch(self):
353
 
        tree = self.make_branch_and_tree('.')
 
403
    def test_shelf_p1_patch(self):
 
404
        self.tree = self.make_branch_and_tree('.')
354
405
 
355
 
        self.__create_and_add_test_file(tree)
 
406
        self.__create_and_add_test_file()
356
407
 
357
408
        # Run a benign shelf command to setup .shelf for us
358
409
        self.run_bzr('shelf', 'ls', retcode=0)
359
410
 
 
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')
360
418
        # Fake a -p0 shelved patch
361
 
        diff = self.DIFF_1
362
 
        diff = diff.replace('a/', '')
363
 
        diff = diff.replace('b/', '')
 
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/')
364
423
        open('.shelf/shelves/default/00', 'w').write(diff)
365
424
 
366
425
        # This should work
367
426
        self.run_bzr('unshelve', '--all', retcode=0)
368
427
 
369
 
        # Check the diff is right
370
 
        self.assertEqual(self.capture('diff', retcode=1),
371
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
428
        self._check_diff()
372
429
 
373
430
    def test_shelf_shelve_in_subdir(self):
374
 
        tree = self.make_branch_and_tree('.')
375
 
 
376
 
        self.__create_and_add_test_file(tree)
 
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()
377
439
 
378
440
        # Modify the test file
379
 
        file('test_file', 'w').write(self.MODIFIED)
 
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()
380
445
 
381
446
        # Shelve the changes
382
447
        self.run_bzr('shelve', '--all', retcode=0)
388
453
        # Unshelve, should succeed
389
454
        self.run_bzr('unshelve', '--all', retcode=0)
390
455
 
391
 
        # Check the diff is right
392
 
        self.assertEqual(self.capture('diff', retcode=1),
393
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
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)