@matheusbsbs / matheus-bagliano / commits / b482759983
Fork 0

grep: unset GREP_OPTIONS before spawning external grep

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>

René Scharfe committed Nov 22, 2009 at 16:58 UTC b48275998399561780af85d429da3caceeecd2fe
2 files changed +9
builtin-grep.c
+4
@@ -433,7 +433,11 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
433
434 if (opt->color_external && strlen(opt->color_external) > 0)
435 push_arg(opt->color_external);
436 + } else {
437 + unsetenv("GREP_COLOR");
438 + unsetenv("GREP_COLORS");
439 }
440 + unsetenv("GREP_OPTIONS");
441
442 hit = 0;
443 argc = nr;
t/t7002-grep.sh
+5
@@ -213,6 +213,11 @@ test_expect_success 'grep -e A --and --not -e B' '
213 test_cmp expected actual
214 '
215
216 +test_expect_success 'grep should ignore GREP_OPTIONS' '
217 + GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
218 + test_cmp expected actual
219 +'
220 +
221 test_expect_success 'grep -f, non-existent file' '
222 test_must_fail git grep -f patterns
223 '