aboutsummaryrefslogtreecommitdiff
path: root/add-patch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-05-30 14:15:16 -0700
committerJunio C Hamano <gitster@pobox.com>2024-05-30 14:15:16 -0700
commitd019b80d4f2b73cb353c57722729c4d88ad08cb1 (patch)
tree3d9f9d09fb9864bdf9d3e75cbfd8ab5003efde8e /add-patch.c
parent99d3cbe21b5c4c09c6befa9f505dac41dfea9c1d (diff)
parentd3f616a4e56f359d84a9d439aa03dca1fe9ac280 (diff)
downloadgit-d019b80d4f2b73cb353c57722729c4d88ad08cb1.tar.xz
Merge branch 'jc/add-patch-enforce-single-letter-input'
"git add -p" learned to complain when an answer with more than one letter is given to a prompt that expects a single letter answer. * jc/add-patch-enforce-single-letter-input: add-patch: enforce only one-letter response to prompts
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/add-patch.c b/add-patch.c
index 2252895c28..814de57c4a 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1227,6 +1227,7 @@ static int prompt_yesno(struct add_p_state *s, const char *prompt)
fflush(stdout);
if (read_single_character(s) == EOF)
return -1;
+ /* do not limit to 1-byte input to allow 'no' etc. */
switch (tolower(s->answer.buf[0])) {
case 'n': return 0;
case 'y': return 1;
@@ -1510,6 +1511,12 @@ static int patch_update_file(struct add_p_state *s,
if (!s->answer.len)
continue;
ch = tolower(s->answer.buf[0]);
+
+ /* 'g' takes a hunk number and '/' takes a regexp */
+ if (s->answer.len != 1 && (ch != 'g' && ch != '/')) {
+ err(s, _("Only one letter is expected, got '%s'"), s->answer.buf);
+ continue;
+ }
if (ch == 'y') {
hunk->use = USE_HUNK;
soft_increment: