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
This patch prevents calling the pager in the first place, saving an unnecessary fork() call.
Signed-off-by: Wilhelm Schuermann <wimschuermann@googlemail.com> --- builtin/grep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/grep.c +1 −1
diff --git a/builtin/grep.c b/builtin/grep.c index e77f7cf..fe7b9fd 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -885,7 +885,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))
-- 2.3.3.dirty