Skip to content

Commit 321ffcc

Browse files
René Scharfegitster
authored andcommitted
grep: --name-only over binary
As with the option -c/--count, git grep with the option -l/--name-only should work the same with binary files as with text files because there is no danger of messing up the terminal with control characters from the contents of matching files. GNU grep does the same. Move the check for ->name_only before the one for binary_match_only, thus making the latter irrelevant for git grep -l. Reported-by: Dmitry Potapov <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c30c10c commit 321ffcc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

grep.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
873873
count++;
874874
if (opt->status_only)
875875
return 1;
876+
if (opt->name_only) {
877+
show_name(opt, name);
878+
return 1;
879+
}
876880
if (opt->count)
877881
goto next_line;
878882
if (binary_match_only) {
@@ -882,10 +886,6 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
882886
opt->output(opt, " matches\n", 9);
883887
return 1;
884888
}
885-
if (opt->name_only) {
886-
show_name(opt, name);
887-
return 1;
888-
}
889889
/* Hit at this line. If we haven't shown the
890890
* pre-context lines, we would need to show them.
891891
*/

t/t7008-grep-binary.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ test_expect_success 'git grep -c ina a' '
3333
test_cmp expect actual
3434
'
3535

36+
test_expect_success 'git grep -l ina a' '
37+
echo a >expect &&
38+
git grep -l ina a >actual &&
39+
test_cmp expect actual
40+
'
41+
3642
test_expect_success 'git grep -L bar a' '
3743
echo a >expect &&
3844
git grep -L bar a >actual &&

0 commit comments

Comments
 (0)