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

grep: support -h (no header) with --count

Suppress printing the header (filename) with -h even if in -c/--count
mode.  GNU grep and OpenBSD's grep do the same.
Signed-off-by: NRene Scharfe <l.s.r@web.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 9afad7a1
......@@ -1562,8 +1562,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
*/
if (opt->count && count) {
char buf[32];
output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
output_sep(opt, ':');
if (opt->pathname) {
output_color(opt, gs->name, strlen(gs->name),
opt->color_filename);
output_sep(opt, ':');
}
snprintf(buf, sizeof(buf), "%u\n", count);
opt->output(opt, buf, strlen(buf));
return 1;
......
......@@ -328,6 +328,18 @@ do
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'
test_expect_success "grep --count $L" '
echo ${HC}ab:3 >expected &&
git grep --count -e b $H -- ab >actual &&
test_cmp expected actual
'
test_expect_success "grep --count -h $L" '
echo 3 >expected &&
git grep --count -h -e b $H -- ab >actual &&
test_cmp expected actual
'
done
cat >expected <<EOF
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册