diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-05-30 14:15:16 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-05-30 14:15:16 -0700 |
| commit | d019b80d4f2b73cb353c57722729c4d88ad08cb1 (patch) | |
| tree | 3d9f9d09fb9864bdf9d3e75cbfd8ab5003efde8e /add-patch.c | |
| parent | 99d3cbe21b5c4c09c6befa9f505dac41dfea9c1d (diff) | |
| parent | d3f616a4e56f359d84a9d439aa03dca1fe9ac280 (diff) | |
| download | git-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.c | 7 |
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: |
