diff --git a/grep.c b/grep.c index 35c18b7e28fd8f064f4d7759653c77078a2e5672..22639cde2c2ffeb4fc60a1585b88f3524dcf1c7b 100644 --- a/grep.c +++ b/grep.c @@ -873,6 +873,10 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, count++; if (opt->status_only) return 1; + if (opt->name_only) { + show_name(opt, name); + return 1; + } if (opt->count) goto next_line; if (binary_match_only) { @@ -882,10 +886,6 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, opt->output(opt, " matches\n", 9); return 1; } - if (opt->name_only) { - show_name(opt, name); - return 1; - } /* Hit at this line. If we haven't shown the * pre-context lines, we would need to show them. */ diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index 91970eacd66723557a8bfa862ef737e5d75f6a67..4a12d97922b34e95c1d42319361e8c02f2246a62 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -33,6 +33,12 @@ test_expect_success 'git grep -c ina a' ' test_cmp expect actual ' +test_expect_success 'git grep -l ina a' ' + echo a >expect && + git grep -l ina a >actual && + test_cmp expect actual +' + test_expect_success 'git grep -L bar a' ' echo a >expect && git grep -L bar a >actual &&