Skip to content

Commit 0db7696

Browse files
artagnongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6bc1a23 commit 0db7696

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

builtin/revert.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,18 +719,24 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
719719
unsigned char commit_sha1[20];
720720
enum replay_action action;
721721
char *end_of_object_name;
722-
int saved, status;
722+
int saved, status, padding;
723723

724-
if (!prefixcmp(bol, "pick ")) {
724+
if (!prefixcmp(bol, "pick")) {
725725
action = CHERRY_PICK;
726-
bol += strlen("pick ");
727-
} else if (!prefixcmp(bol, "revert ")) {
726+
bol += strlen("pick");
727+
} else if (!prefixcmp(bol, "revert")) {
728728
action = REVERT;
729-
bol += strlen("revert ");
729+
bol += strlen("revert");
730730
} else
731731
return NULL;
732732

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");
734740
saved = *end_of_object_name;
735741
*end_of_object_name = '\0';
736742
status = get_sha1(bol, commit_sha1);

t/t3510-cherry-pick-sequence.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ test_expect_success 'malformed instruction sheet 3' '
492492
test_must_fail git cherry-pick --continue
493493
'
494494

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+
495506
test_expect_success 'commit descriptions in insn sheet are optional' '
496507
pristine_detach initial &&
497508
test_must_fail git cherry-pick base..anotherpick &&

0 commit comments

Comments
 (0)