Skip to content

Commit

Permalink
grep: unset GREP_OPTIONS before spawning external grep
Browse files Browse the repository at this point in the history
While we're at it, also unset GREP_COLOR and GREP_COLORS in case colouring
is not enabled, to be on the safe side.  The presence of these variables
alone is not sufficient to trigger coloured output with GNU grep, but
other implementations may behave differently.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Nov 23, 2009
1 parent 73a1d05 commit b482759
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)

if (opt->color_external && strlen(opt->color_external) > 0)
push_arg(opt->color_external);
} else {
unsetenv("GREP_COLOR");
unsetenv("GREP_COLORS");
}
unsetenv("GREP_OPTIONS");

hit = 0;
argc = nr;
Expand Down
5 changes: 5 additions & 0 deletions t/t7002-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ test_expect_success 'grep -e A --and --not -e B' '
test_cmp expected actual
'

test_expect_success 'grep should ignore GREP_OPTIONS' '
GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
test_cmp expected actual
'

test_expect_success 'grep -f, non-existent file' '
test_must_fail git grep -f patterns
'
Expand Down

0 comments on commit b482759

Please sign in to comment.