From 08d383f23e80e418c844952fcc4e2e635962c292 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 10 Apr 2020 11:27:50 +0000 Subject: interactive: refactor code asking the user for interactive input There are quite a few code locations (e.g. `git clean --interactive`) where Git asks the user for an answer. In preparation for fixing a bug shared by all of them, and also to DRY up the code, let's refactor it. Please note that most of these callers trimmed white-space both at the beginning and at the end of the answer, instead of trimming only the end (as the caller in `add-patch.c` does). Therefore, technically speaking, we change behavior in this patch. At the same time, it can be argued that this is actually a bug fix. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- prompt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'prompt.c') diff --git a/prompt.c b/prompt.c index 6d5885d009..098dcfb7cf 100644 --- a/prompt.c +++ b/prompt.c @@ -74,3 +74,13 @@ char *git_prompt(const char *prompt, int flags) } return r; } + +int git_read_line_interactively(struct strbuf *line) +{ + int ret = strbuf_getline_lf(line, stdin); + + if (ret != EOF) + strbuf_trim_trailing_newline(line); + + return ret; +} -- cgit v1.2.3