Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6f6be80

Browse files
committed
Merge branch 'rs/grep-h-c'
"git grep" learns to handle combination of "-h (no header)" and "-c (counts)". * rs/grep-h-c: grep: support -h (no header) with --count t7810: add missing variables to tests in loop
2 parents 6f75e48 + f76d947 commit 6f6be80

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

grep.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
15621562
*/
15631563
if (opt->count && count) {
15641564
char buf[32];
1565-
output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
1566-
output_sep(opt, ':');
1565+
if (opt->pathname) {
1566+
output_color(opt, gs->name, strlen(gs->name),
1567+
opt->color_filename);
1568+
output_sep(opt, ':');
1569+
}
15671570
snprintf(buf, sizeof(buf), "%u\n", count);
15681571
opt->output(opt, buf, strlen(buf));
15691572
return 1;

t/t7810-grep.sh

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ do
105105

106106
test_expect_success "grep -w $L (w)" '
107107
: >expected &&
108-
test_must_fail git grep -n -w -e "^w" >actual &&
108+
test_must_fail git grep -n -w -e "^w" $H >actual &&
109109
test_cmp expected actual
110110
'
111111

@@ -240,92 +240,104 @@ do
240240
test_cmp expected actual
241241
'
242242
test_expect_success "grep $L with grep.extendedRegexp=false" '
243-
echo "ab:a+bc" >expected &&
244-
git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
243+
echo "${HC}ab:a+bc" >expected &&
244+
git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
245245
test_cmp expected actual
246246
'
247247

248248
test_expect_success "grep $L with grep.extendedRegexp=true" '
249-
echo "ab:abc" >expected &&
250-
git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
249+
echo "${HC}ab:abc" >expected &&
250+
git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
251251
test_cmp expected actual
252252
'
253253

254254
test_expect_success "grep $L with grep.patterntype=basic" '
255-
echo "ab:a+bc" >expected &&
256-
git -c grep.patterntype=basic grep "a+b*c" ab >actual &&
255+
echo "${HC}ab:a+bc" >expected &&
256+
git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
257257
test_cmp expected actual
258258
'
259259

260260
test_expect_success "grep $L with grep.patterntype=extended" '
261-
echo "ab:abc" >expected &&
262-
git -c grep.patterntype=extended grep "a+b*c" ab >actual &&
261+
echo "${HC}ab:abc" >expected &&
262+
git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
263263
test_cmp expected actual
264264
'
265265

266266
test_expect_success "grep $L with grep.patterntype=fixed" '
267-
echo "ab:a+b*c" >expected &&
268-
git -c grep.patterntype=fixed grep "a+b*c" ab >actual &&
267+
echo "${HC}ab:a+b*c" >expected &&
268+
git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
269269
test_cmp expected actual
270270
'
271271

272272
test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
273-
echo "ab:a+b*c" >expected &&
274-
git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual &&
273+
echo "${HC}ab:a+b*c" >expected &&
274+
git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual &&
275275
test_cmp expected actual
276276
'
277277

278278
test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
279-
echo "ab:abc" >expected &&
279+
echo "${HC}ab:abc" >expected &&
280280
git \
281281
-c grep.patternType=default \
282282
-c grep.extendedRegexp=true \
283-
grep "a+b*c" ab >actual &&
283+
grep "a+b*c" $H ab >actual &&
284284
test_cmp expected actual
285285
'
286286

287287
test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
288-
echo "ab:abc" >expected &&
288+
echo "${HC}ab:abc" >expected &&
289289
git \
290290
-c grep.extendedRegexp=true \
291291
-c grep.patternType=default \
292-
grep "a+b*c" ab >actual &&
292+
grep "a+b*c" $H ab >actual &&
293293
test_cmp expected actual
294294
'
295295

296-
test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
297-
echo "ab:abc" >expected &&
296+
test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
297+
echo "${HC}ab:abc" >expected &&
298298
git \
299299
-c grep.patternType=extended \
300300
-c grep.extendedRegexp=false \
301-
grep "a+b*c" ab >actual &&
301+
grep "a+b*c" $H ab >actual &&
302302
test_cmp expected actual
303303
'
304304

305-
test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
306-
echo "ab:a+bc" >expected &&
305+
test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
306+
echo "${HC}ab:a+bc" >expected &&
307307
git \
308308
-c grep.patternType=basic \
309309
-c grep.extendedRegexp=true \
310-
grep "a+b*c" ab >actual &&
310+
grep "a+b*c" $H ab >actual &&
311311
test_cmp expected actual
312312
'
313313

314-
test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
315-
echo "ab:abc" >expected &&
314+
test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
315+
echo "${HC}ab:abc" >expected &&
316316
git \
317317
-c grep.extendedRegexp=false \
318318
-c grep.patternType=extended \
319-
grep "a+b*c" ab >actual &&
319+
grep "a+b*c" $H ab >actual &&
320320
test_cmp expected actual
321321
'
322322

323-
test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
324-
echo "ab:a+bc" >expected &&
323+
test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
324+
echo "${HC}ab:a+bc" >expected &&
325325
git \
326326
-c grep.extendedRegexp=true \
327327
-c grep.patternType=basic \
328-
grep "a+b*c" ab >actual &&
328+
grep "a+b*c" $H ab >actual &&
329+
test_cmp expected actual
330+
'
331+
332+
test_expect_success "grep --count $L" '
333+
echo ${HC}ab:3 >expected &&
334+
git grep --count -e b $H -- ab >actual &&
335+
test_cmp expected actual
336+
'
337+
338+
test_expect_success "grep --count -h $L" '
339+
echo 3 >expected &&
340+
git grep --count -h -e b $H -- ab >actual &&
329341
test_cmp expected actual
330342
'
331343
done

0 commit comments

Comments
 (0)