28
29
def _check_diff(self, diff=DIFF_1, filename='test_file'):
29
keys = { 'filename' : filename }
30
old_tree = self.tree.basis_tree()
31
old_date = _patch_header_date(old_tree,
32
old_tree.inventory.path2id(filename),
34
new_date = _patch_header_date(self.tree,
35
self.tree.inventory.path2id(filename),
37
keys = { 'filename' : filename , 'old_date': old_date,
30
39
hdr = self.DIFF_HEADER % keys
32
41
self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
34
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file'):
35
diff = diff % { 'filename' : filename }
36
shelf = open(os.path.join(self.tree.branch.base,
43
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
45
old_tree = self.tree.basis_tree()
46
old_date = _patch_header_date(old_tree,
47
old_tree.inventory.path2id(filename),
49
diff = diff % { 'filename' : filename, 'old_date': old_date,
51
shelf = open(os.path.join(self.tree.basedir,
37
52
'.shelf/shelves/default/' + idx)).read()
38
53
shelf = shelf[shelf.index('\n') + 1:] # skip the message
39
54
self.assertEqual(shelf, diff)
169
187
shown = self.capture('shelf show 00', retcode=0)
170
188
self.assertEqual(shown, shelf)
190
def test_shelf_show_unspecified(self):
191
self.tree = self.make_branch_and_tree('.')
192
self.__create_and_add_test_file()
193
self.__test_show(self.tree, '00')
194
self.__test_show(self.tree, '01')
195
self.__test_show(self.tree, '02')
197
# Check that not specifying at patch gets us the most recent
198
shelf = open(os.path.join(self.tree.basedir,
199
'.shelf/shelves/default/02')).read()
200
self.assertTrue('patch 02' in shelf)
202
# Check the shown output is right
203
shown = self.capture('shelf show', retcode=0)
204
self.assertEqual(shown, shelf)
172
206
def test_shelf_show_with_no_patch(self):
173
207
self.tree = self.make_branch_and_tree('.')
174
208
stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
270
304
# Modify the test files
271
305
file('test_file', 'w').write(self.MODIFIED)
272
306
file('test_file2', 'w').write(self.MODIFIED)
307
new_date = _patch_header_date(self.tree,
308
self.tree.inventory.path2id('test_file'), 'test_file')
274
310
# Shelve the changes
275
311
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
276
312
self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
278
self._check_shelf('00')
314
self._check_shelf('00', new_date=new_date)
281
317
self.run_bzr('shelf', 'delete', '00', retcode=0)
363
399
# Run a benign shelf command to setup .shelf for us
364
400
self.run_bzr('shelf', 'ls', retcode=0)
402
old_tree = self.tree.basis_tree()
403
old_date = _patch_header_date(old_tree,
404
old_tree.inventory.path2id('test_file'),
406
new_date = _patch_header_date(self.tree,
407
self.tree.inventory.path2id('test_file'),
366
409
# Fake a -p0 shelved patch
367
diff = self.DIFF_1 % { 'filename' : 'test_file' }
410
diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
411
'new_date' : new_date}
368
412
diff = diff.replace('--- ', '--- a/')
369
413
diff = diff.replace('+++ ', '+++ b/')
370
414
open('.shelf/shelves/default/00', 'w').write(diff)
405
449
def test_shelf_shelf_bogus_subcommand(self):
406
450
self.tree = self.make_branch_and_tree('.')
407
451
self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
453
def test_shelf_OOO_unshelve(self):
454
self.tree = self.make_branch_and_tree('.')
456
for i in range(1, 5):
457
self.__create_and_add_test_file(filename='test_file%d' % i)
459
# Modify the test files
460
for i in range(1, 5):
461
file('test_file%d' % i, 'w').write(self.MODIFIED)
464
for i in range(1, 5):
465
self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
467
# Check shelving worked
468
for i in range(1, 5):
469
self.assertEqual(file('test_file%d' % i).read(), self.ORIGINAL)
471
# We should now have 00-03
472
for i in range(0, 4):
473
self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
476
self.run_bzr('unshelve', '--all', '00', retcode=0)
477
self.assertEqual(file('test_file1').read(), self.MODIFIED)
480
lines = self.capture('shelf ls', retcode=0).split('\n')
482
self.assertFalse(line.startswith(' 00'))
484
# Check we can reshelve once we've unshelved out of order, should be 04
485
self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
486
self.run_bzr('shelve', '--all')
487
self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
490
text = self.capture('shelf ls', retcode=0)
491
for line in text.split('\n'):
492
self.assertFalse(line.startswith(' 00'))
494
# We now have 01,02,03,04
496
self.run_bzr('unshelve', '--all', '02', retcode=0)
497
self.assertEqual(file('test_file3').read(), self.MODIFIED)
499
# Unshelve the default, this is the reshelved 00, hence modifies file 1
500
self.run_bzr('unshelve', '--all', retcode=0)
501
self.assertEqual(file('test_file1').read(), self.MODIFIED)
503
def test_shelf_switch_basic(self):
504
self.tree = self.make_branch_and_tree('.')
505
self.__create_and_add_test_file()
507
# This should go to "default"
508
file('test_file', 'w').write(self.MODIFIED)
509
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
512
self.run_bzr('shelf', 'switch', 'other', retcode=0)
513
file('test_file', 'w').write(self.MODIFIED)
514
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
517
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
518
self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
519
self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
522
self.run_bzr('shelf', 'switch', 'default', retcode=0)
523
file('test_file', 'w').write(self.MODIFIED)
524
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
527
self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
528
self.assertFalse(os.path.exists('.shelf/shelves/other/01'))