Skip to content

Commit

Permalink
Merge branch 'rs/grep-h-c'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Mar 18, 2014
2 parents 6f75e48 + f76d947 commit 6f6be80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
7 changes: 5 additions & 2 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 41 additions & 29 deletions t/t7810-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ do

test_expect_success "grep -w $L (w)" '
: >expected &&
test_must_fail git grep -n -w -e "^w" >actual &&
test_must_fail git grep -n -w -e "^w" $H >actual &&
test_cmp expected actual
'

Expand Down Expand Up @@ -240,92 +240,104 @@ do
test_cmp expected actual
'
test_expect_success "grep $L with grep.extendedRegexp=false" '
echo "ab:a+bc" >expected &&
git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
echo "${HC}ab:a+bc" >expected &&
git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

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

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

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

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

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

test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
echo "ab:abc" >expected &&
echo "${HC}ab:abc" >expected &&
git \
-c grep.patternType=default \
-c grep.extendedRegexp=true \
grep "a+b*c" ab >actual &&
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
echo "ab:abc" >expected &&
echo "${HC}ab:abc" >expected &&
git \
-c grep.extendedRegexp=true \
-c grep.patternType=default \
grep "a+b*c" ab >actual &&
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
echo "ab:abc" >expected &&
test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
echo "${HC}ab:abc" >expected &&
git \
-c grep.patternType=extended \
-c grep.extendedRegexp=false \
grep "a+b*c" ab >actual &&
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
echo "ab:a+bc" >expected &&
test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
echo "${HC}ab:a+bc" >expected &&
git \
-c grep.patternType=basic \
-c grep.extendedRegexp=true \
grep "a+b*c" ab >actual &&
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
echo "ab:abc" >expected &&
test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
echo "${HC}ab:abc" >expected &&
git \
-c grep.extendedRegexp=false \
-c grep.patternType=extended \
grep "a+b*c" ab >actual &&
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'

test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
echo "ab:a+bc" >expected &&
test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
echo "${HC}ab:a+bc" >expected &&
git \
-c grep.extendedRegexp=true \
-c grep.patternType=basic \
grep "a+b*c" ab >actual &&
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
Expand Down

0 comments on commit 6f6be80

Please sign in to comment.