grep: unset GREP_OPTIONS before spawning external grep
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Sun, 22 Nov 2009 15:58:09 +0000 (16:58 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Nov 2009 00:20:59 +0000 (16:20 -0800)
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>
builtin-grep.c
t/t7002-grep.sh
index 01be9bf7ff74731969384cc91dad2e20d08d81bc..9a9e3fccd58adb9c984707e9398fa194ad7284a7 100644 (file)
@@ -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;
index ae5290ab43e8b51b32331768371e2a67d700064d..dd0da6c0bf45524b75de9dbaf67bbbef724fdf4e 100755 (executable)
@@ -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
 '