revert: tolerate extra spaces, tabs in insn sheet
Tolerate extra spaces and tabs as part of the the field separator in '.git/sequencer/todo', for people with fat fingers. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ramkumar Ramachandra committed
Dec 14, 2011 at 22:24 UTC
0db76962d156c196a23a98014c1585246f561a5d
2 files changed
+23
-6
builtin/revert.c
+12
-6
@@ -719,18 +719,24 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
719
unsigned char commit_sha1[20];
720
enum replay_action action;
721
char *end_of_object_name;
722
- int saved, status;
722
+ int saved, status, padding;
723
724
- if (!prefixcmp(bol, "pick ")) {
724
+ if (!prefixcmp(bol, "pick")) {
725
action = CHERRY_PICK;
726
- bol += strlen("pick ");
727
- } else if (!prefixcmp(bol, "revert ")) {
726
+ bol += strlen("pick");
727
+ } else if (!prefixcmp(bol, "revert")) {
728
action = REVERT;
729
- bol += strlen("revert ");
729
+ bol += strlen("revert");
730
} else
731
return NULL;
732
733
- end_of_object_name = bol + strcspn(bol, " \n");
733
+ /* Eat up extra spaces/ tabs before object name */
734
+ padding = strspn(bol, " \t");
735
+ if (!padding)
736
+ return NULL;
737
+ bol += padding;
738
+
739
+ end_of_object_name = bol + strcspn(bol, " \t\n");
740
saved = *end_of_object_name;
741
*end_of_object_name = '\0';
742
status = get_sha1(bol, commit_sha1);
t/t3510-cherry-pick-sequence.sh
+11
@@ -492,6 +492,17 @@ test_expect_success 'malformed instruction sheet 3' '
492
test_must_fail git cherry-pick --continue
493
'
494
495
+test_expect_success 'instruction sheet, fat-fingers version' '
496
+ pristine_detach initial &&
497
+ test_must_fail git cherry-pick base..anotherpick &&
498
+ echo "c" >foo &&
499
+ git add foo &&
500
+ git commit &&
501
+ sed "s/pick \([0-9a-f]*\)/pick \1 /" .git/sequencer/todo >new_sheet &&
502
+ cp new_sheet .git/sequencer/todo &&
503
+ git cherry-pick --continue
504
+'
505
+
506
test_expect_success 'commit descriptions in insn sheet are optional' '
507
pristine_detach initial &&
508
test_must_fail git cherry-pick base..anotherpick &&