diff options
| author | Johannes Sixt <j6t@kdbg.org> | 2025-07-31 18:07:36 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-07-31 14:17:54 -0700 |
| commit | 711a20827b7e99cda7329872c0e75860ddfb08bc (patch) | |
| tree | 688136007eebcbfef782111e3b20fabf54838142 /prompt.c | |
| parent | Git 2.50 (diff) | |
| download | git-711a20827b7e99cda7329872c0e75860ddfb08bc.tar.gz git-711a20827b7e99cda7329872c0e75860ddfb08bc.zip | |
interactive: do strip trailing CRLF from input
`git reset -p file` on a Windows CMD refuses to do anything useful
with this error message:
(1/5) Unstage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? n
'nly one letter is expected, got 'n
The letter 'O' at the beginning of the line is overwritten by an
apostrophe, so, clearly the parser sees the string "n\r".
strbuf_trim_trailing_newline() removes trailing CRLF from the string.
In particular, it first removes LF if present, and if that was the
case, it also removes CR if present.
git_read_line_interactively() clearly intends to remove CRLF as it
calls strbuf_trim_trailing_newline(). However, input is gathered using
strbuf_getline_lf(), which already removes the trailing LF. Now
strbuf_trim_trailing_newline() does not see LF, so that it does not
remove CR, either, and leaves it for the caller to process.
Call strbuf_getline() instead, which removes both LF and CR.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
| -rw-r--r-- | prompt.c | 8 |
1 files changed, 1 insertions, 7 deletions
@@ -77,12 +77,6 @@ char *git_prompt(const char *prompt, int flags) int git_read_line_interactively(struct strbuf *line) { - int ret; - fflush(stdout); - ret = strbuf_getline_lf(line, stdin); - if (ret != EOF) - strbuf_trim_trailing_newline(line); - - return ret; + return strbuf_getline(line, stdin); } |
