Skip to contentSkip to conversation

git grep -I bug

DISCUSSION Jeremy O'Brien 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I am running git version 1.6.1.2.309.g2ea3.

When I use

git grep -I "string_to_match"

to ignore binary files in my grep, binary files are returned anyway.

When I do a regular

grep "string_to_match" *

grep does not show the binary files. I believe this is a bug.

Thanks,
Jeremy O'Brien

#1 lore raw
Quoted 7 lines · Jeremy O'Brien

I am running git version 1.6.1.2.309.g2ea3.

When I use

git grep -I "string_to_match"

to ignore binary files in my grep, binary files are returned anyway.

One sanity check. What does 'git grep --cached -I "string_to_match"' do in that case?

If it works as expected but without --cached it doesn't, then I think the following patch will fix it.

-- >8 --
Subject: grep: pass -I (ignore binary) down to external grep

The external-grep codepath forgets to pass this option. Fix it.

---
 builtin-grep.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
builtin-grep.c +2 -0
index bebf15c..c799fdd 100644
@@ -297,6 +297,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 		push_arg("-l");
 	if (opt->unmatch_name_only)
 		push_arg("-L");
+	if (opt->binary == GREP_BINARY_NOMATCH)
+		push_arg("-I");
 	if (opt->null_following_name)
 		/* in GNU grep git's "-z" translates to "-Z" */
 		push_arg("-Z");
#2 lore raw
Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Jeremy O'Brien

I am running git version 1.6.1.2.309.g2ea3.

Quoted 9 lines
Quoted 5 lines

When I use

git grep -I "string_to_match"

to ignore binary files in my grep, binary files are returned anyway.

One sanity check. What does 'git grep --cached -I "string_to_match"' do in that case?

It works as expected. It is interesting that while my Linux install was affected by this bug, my Mac OS X install did not seem to be affected by it, while running the same version of git.

#3 lore raw
Quoted 11 lines · Jeremy O'Brien
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Jeremy O'Brien

I am running git version 1.6.1.2.309.g2ea3.

When I use

git grep -I "string_to_match"

to ignore binary files in my grep, binary files are returned anyway.

Quoted 7 lines
Quoted 3 lines

One sanity check. What does 'git grep --cached -I "string_to_match"' do in that case?

It works as expected. It is interesting that while my Linux install was affected by this bug, my Mac OS X install did not seem to be affected by it, while running the same version of git.

Perhaps your Mac OSX binary was built without external grep support.

Did the patch fix the issue, by the way?

#4 lore raw
Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Jeremy O'Brien
Quoted 13 lines · Junio C Hamano
Quoted 7 lines · Jeremy O'Brien

I am running git version 1.6.1.2.309.g2ea3.

When I use

git grep -I "string_to_match"

to ignore binary files in my grep, binary files are returned anyway.

One sanity check. What does 'git grep --cached -I "string_to_match"' do in that case?

Quoted 7 lines
Quoted 3 lines

It works as expected. It is interesting that while my Linux install was affected by this bug, my Mac OS X install did not seem to be affected by it, while running the same version of git.

Perhaps your Mac OSX binary was built without external grep support.

Did the patch fix the issue, by the way?

I'm assuming that was the problem. And yes, the patch fixed it just fine, thank you.