提交 321ffcc0 编写于 作者: R René Scharfe 提交者: Junio C Hamano

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: NDmitry Potapov <dpotapov@gmail.com>
Signed-off-by: NRene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c30c10cf
......@@ -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.
*/
......
......@@ -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 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册