Skip to content

Commit

Permalink
grep: fix "--quiet" overwriting current output
Browse files Browse the repository at this point in the history
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 <wimschuermann@googlemail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Wilhelm Schuermann authored and Junio C Hamano committed Mar 19, 2015
1 parent 282616c commit c2048f0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit c2048f0

Please sign in to comment.