Skip to content

Commit 711a208

Browse files
j6tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16bd9f2 commit 711a208

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

prompt.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ char *git_prompt(const char *prompt, int flags)
7777

7878
int git_read_line_interactively(struct strbuf *line)
7979
{
80-
int ret;
81-
8280
fflush(stdout);
83-
ret = strbuf_getline_lf(line, stdin);
84-
if (ret != EOF)
85-
strbuf_trim_trailing_newline(line);
86-
87-
return ret;
81+
return strbuf_getline(line, stdin);
8882
}

0 commit comments

Comments
 (0)