35
28
def _check_diff(self, diff=DIFF_1, filename='test_file'):
36
old_tree = self.tree.basis_tree()
40
old_date = _patch_header_date(old_tree,
41
old_tree.inventory.path2id(filename),
43
new_date = _patch_header_date(self.tree,
44
self.tree.inventory.path2id(filename), filename)
48
keys = { 'filename' : filename , 'old_date': old_date,
29
keys = { 'filename' : filename }
50
30
hdr = self.DIFF_HEADER % keys
52
32
self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
54
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
56
old_tree = self.tree.basis_tree()
59
old_date = _patch_header_date(old_tree,
60
old_tree.inventory.path2id(filename),
64
diff = diff % { 'filename' : filename, 'old_date': old_date,
66
shelf = open(os.path.join(self.tree.basedir,
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,
67
37
'.shelf/shelves/default/' + idx)).read()
68
38
shelf = shelf[shelf.index('\n') + 1:] # skip the message
69
39
self.assertEqual(shelf, diff)
208
169
shown = self.capture('shelf show 00', retcode=0)
209
170
self.assertEqual(shown, shelf)
211
def test_shelf_show_unspecified(self):
212
self.tree = self.make_branch_and_tree('.')
213
self.__create_and_add_test_file()
214
self.__test_show(self.tree, '00')
215
self.__test_show(self.tree, '01')
216
self.__test_show(self.tree, '02')
218
# Check that not specifying at patch gets us the most recent
219
shelf = open(os.path.join(self.tree.basedir,
220
'.shelf/shelves/default/02')).read()
221
self.assertTrue('patch 02' in shelf)
223
# Check the shown output is right
224
shown = self.capture('shelf show', retcode=0)
225
self.assertEqual(shown, shelf)
227
172
def test_shelf_show_with_no_patch(self):
228
173
self.tree = self.make_branch_and_tree('.')
229
174
stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
319
264
def test_shelf_delete(self):
320
265
self.tree = self.make_branch_and_tree('.')
321
self.tree.lock_write()
323
self.__create_and_add_test_file()
324
self.__create_and_add_test_file(filename='test_file2')
326
# Modify the test files
327
# write in binary mode because on win32 line-endings should be LF
328
f = file('test_file', 'wb')
329
f.write(self.MODIFIED)
331
f = file('test_file2', 'wb')
332
f.write(self.MODIFIED)
334
new_date = _patch_header_date(self.tree,
335
self.tree.inventory.path2id('test_file'), 'test_file')
267
self.__create_and_add_test_file()
268
self.__create_and_add_test_file(filename='test_file2')
270
# Modify the test files
271
file('test_file', 'w').write(self.MODIFIED)
272
file('test_file2', 'w').write(self.MODIFIED)
339
274
# Shelve the changes
340
275
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
341
276
self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
343
self._check_shelf('00', new_date=new_date)
278
self._check_shelf('00')
346
281
self.run_bzr('shelf', 'delete', '00', retcode=0)
486
405
def test_shelf_shelf_bogus_subcommand(self):
487
406
self.tree = self.make_branch_and_tree('.')
488
407
self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
490
def test_shelf_OOO_unshelve(self):
491
self.tree = self.make_branch_and_tree('.')
493
for i in range(1, 5):
494
self.__create_and_add_test_file(filename='test_file%d' % i)
496
# Modify the test files
497
for i in range(1, 5):
498
file('test_file%d' % i, 'w').write(self.MODIFIED)
501
for i in range(1, 5):
502
self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
504
# Check shelving worked
505
for i in range(1, 5):
506
self.assertEqual(file('test_file%d' % i).read(), self.ORIGINAL)
508
# We should now have 00-03
509
for i in range(0, 4):
510
self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
513
self.run_bzr('unshelve', '--all', '00', retcode=0)
514
self.assertEqual(file('test_file1').read(), self.MODIFIED)
517
lines = self.capture('shelf ls', retcode=0).split('\n')
519
self.assertFalse(line.startswith(' 00'))
521
# Check we can reshelve once we've unshelved out of order, should be 04
522
self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
523
self.run_bzr('shelve', '--all')
524
self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
527
text = self.capture('shelf ls', retcode=0)
528
for line in text.split('\n'):
529
self.assertFalse(line.startswith(' 00'))
531
# We now have 01,02,03,04
533
self.run_bzr('unshelve', '--all', '02', retcode=0)
534
self.assertEqual(file('test_file3').read(), self.MODIFIED)
536
# Unshelve the default, this is the reshelved 00, hence modifies file 1
537
self.run_bzr('unshelve', '--all', retcode=0)
538
self.assertEqual(file('test_file1').read(), self.MODIFIED)
540
def test_shelf_switch_basic(self):
541
self.tree = self.make_branch_and_tree('.')
542
self.__create_and_add_test_file()
544
# This should go to "default"
545
file('test_file', 'w').write(self.MODIFIED)
546
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
549
self.run_bzr('shelf', 'switch', 'other', retcode=0)
550
file('test_file', 'w').write(self.MODIFIED)
551
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
554
self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
555
self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
556
self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
559
self.run_bzr('shelf', 'switch', 'default', retcode=0)
560
file('test_file', 'w').write(self.MODIFIED)
561
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
564
self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
565
self.assertFalse(os.path.exists('.shelf/shelves/other/01'))
567
def test_shelf_bad_patch_arg(self):
568
self.tree = self.make_branch_and_tree('.')
570
# Check the bad arg handling
571
stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
572
self.assertTrue("Patch '01' doesn't exist on shelf" in error)
574
stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
575
self.assertTrue("Invalid patch name 'foo'" in error)
577
# Hex and is cracky, so it shouldn't work
578
stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
579
self.assertTrue("Invalid patch name '0x00'" in error)
581
def test_color_hunk_selector(self):
582
"""Make sure NoColor is raised iff terminal.has_ansi_colors is False"""
583
hs = ShelveHunkSelector([])
584
hs = UnshelveHunkSelector([])
586
from bzrlib.plugins.bzrtools import terminal
588
from bzrtools import terminal
589
old_has_ansi_colors = terminal.has_ansi_colors
590
terminal.has_ansi_colors = lambda: False
592
self.assertRaises(NoColor, ShelveHunkSelector, [], True)
593
self.assertRaises(NoColor, UnshelveHunkSelector, [], True)
594
terminal.has_ansi_colors = lambda: True
595
hs = ShelveHunkSelector([], color=True)
596
hs = UnshelveHunkSelector([], color=True)
598
terminal.has_ansi_colors = old_has_ansi_colors
600
def test_no_color(self):
601
"""Ensure --no-color switch can be passed"""
602
self.tree = self.make_branch_and_tree('.')
606
self.tree.add(subdir)
609
self.__create_and_add_test_file()
611
# Modify the test file
612
# write in binary mode because on win32 line-endings should be LF
613
f = file('test_file', 'wb')
614
f.write(self.MODIFIED)
616
stdout, error = self.run_bzr_captured(['shelve', '--all',
618
stdout, error = self.run_bzr_captured(['unshelve', '--all',
621
def test_shelf_help(self):
622
self.assertContainsRe(cmd_shelf().help(),
623
'list\n.*List the patches on the current shelf')