git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] unset GREP_OPTIONS in test-lib.sh

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Nov 22, 2009, 15:58 UTC
Message-ID
<4B095F91.8030305@lsrfire.ath.cx>
In-Reply-To
<7v1vjvebem.fsf@alter.siamese.dyndns.org>
Junio C Hamano schrieb:
> Do we kill that environment variable when we call out to external grep in
> grep.c?  If not, we should.  An alternative is to teach our internal one
> to also honor it, but I personally do not find it too attractive to mimic
> the design mistake of GREP_OPTIONS myself.

We don't. Here's a patch with a simple test case that makes git grep unset GREP_OPTIONS before it calls the 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>
---
 builtin-grep.c  |    4 ++++
 t/t7002-grep.sh |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index 01be9bf..9a9e3fc 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -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;
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index ae5290a..dd0da6c 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -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
 '
-- 
1.6.5.3
Previous: Junio C HamanoNext: Carlo Marcelo Arenas Belon
Message 3 of 12 in “unset GREP_OPTIONS in test-lib.sh”
  1. unset GREP_OPTIONS in test-lib.shBert Wesarg, Nov 18, 2009
  2. Junio C HamanoNov 18, 2009
  3. René ScharfeNov 22, 2009
  4. Carlo Marcelo Arenas BelonNov 23, 2009
  5. Junio C HamanoNov 23, 2009
  6. René ScharfeNov 23, 2009
  7. mergetool--lib: simplify guess_merge_tool()René Scharfe, Nov 23, 2009
  8. David AguilarNov 27, 2009
  9. Junio C HamanoNov 23, 2009
  10. René ScharfeNov 23, 2009
  11. Junio C HamanoNov 24, 2009
  12. Bert WesargMar 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.