From: Wilhelm Schuermann Date: Wed, 18 Mar 2015 18:00:13 +0000 (+0100) Subject: grep: fix "--quiet" overwriting current output X-Git-Tag: v2.3.5~10^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c2048f0b394fc5d5644956481b39f3d099cbe51c grep: fix "--quiet" overwriting current output When grep is called with the --quiet option, the pager is initialized despite not being used. When the pager is "less", anything output by previous commands and not ended with a newline is overwritten: $ echo -n aaa; echo bbb aaabbb $ echo -n aaa; git grep -q foo; echo bbb bbb This can be worked around, for example, by making sure STDOUT is not a TTY or more directly by setting git's pager to "cat": $ echo -n aaa; git grep -q foo > /dev/null; echo bbb aaabbb $ echo -n aaa; PAGER=cat git grep -q foo; echo bbb aaabbb But prevent calling the pager in the first place, which would also save an unnecessary fork(). Signed-off-by: Wilhelm Schuermann Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/builtin/grep.c b/builtin/grep.c index b8d440d0e0..39fa4cb434 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -887,7 +887,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) } } - if (!show_in_pager) + if (!show_in_pager && !opt.status_only) setup_pager(); if (!use_index && (untracked || cached))