Skip to content

Commit b482759

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73a1d05 commit b482759

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

builtin-grep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
433433

434434
if (opt->color_external && strlen(opt->color_external) > 0)
435435
push_arg(opt->color_external);
436+
} else {
437+
unsetenv("GREP_COLOR");
438+
unsetenv("GREP_COLORS");
436439
}
440+
unsetenv("GREP_OPTIONS");
437441

438442
hit = 0;
439443
argc = nr;

t/t7002-grep.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ test_expect_success 'grep -e A --and --not -e B' '
213213
test_cmp expected actual
214214
'
215215

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+
216221
test_expect_success 'grep -f, non-existent file' '
217222
test_must_fail git grep -f patterns
218223
'

0 commit comments

Comments
 (0)