summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grep.c7
-rwxr-xr-xt/t7810-grep.sh12
2 files changed, 17 insertions, 2 deletions
diff --git a/grep.c b/grep.c
index c668034739..94f7290eb7 100644
--- a/grep.c
+++ b/grep.c
@@ -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;
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 46aaebc475..63b3039243 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -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