git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: Bert Wesarg <bert.wesarg@googlemail.com>, git@vger.kernel.org
Subject: Re: [PATCH] unset GREP_OPTIONS in test-lib.sh
Date: Sun, 22 Nov 2009 16:58:09 +0100	[thread overview]
Message-ID: <4B095F91.8030305@lsrfire.ath.cx> (raw)
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

  reply	other threads:[~2009-11-22 15:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-18 16:15 [PATCH] unset GREP_OPTIONS in test-lib.sh Bert Wesarg
2009-11-18 22:05 ` Junio C Hamano
2009-11-22 15:58   ` René Scharfe [this message]
2009-11-23 11:22     ` Carlo Marcelo Arenas Belon
2009-11-23 18:27       ` Junio C Hamano
2009-11-23 23:18         ` René Scharfe
2009-11-23 23:29           ` [PATCH] mergetool--lib: simplify guess_merge_tool() René Scharfe
2009-11-27  3:22             ` David Aguilar
2009-11-23 23:52           ` [PATCH] unset GREP_OPTIONS in test-lib.sh Junio C Hamano
2009-11-23 23:59             ` René Scharfe
2009-11-24  0:35               ` Junio C Hamano
2010-03-07 10:30   ` Bert Wesarg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B095F91.8030305@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).