@@ -98,6 +98,37 @@ test_expect_success 'grep should not segfault with a bad input' '
9898
9999test_invalid_grep_expression --and -e A
100100
101+ test_pattern_type () {
102+ H=$1 &&
103+ HC=$2 &&
104+ L=$3 &&
105+ type=$4 &&
106+ shift 4 &&
107+
108+ expected_str= &&
109+ case " $type " in
110+ BRE)
111+ expected_str=" ${HC} ab:a+bc"
112+ ;;
113+ ERE)
114+ expected_str=" ${HC} ab:abc"
115+ ;;
116+ FIX)
117+ expected_str=" ${HC} ab:a+b*c"
118+ ;;
119+ * )
120+ BUG " unknown pattern type '$type '"
121+ ;;
122+ esac &&
123+ config_str=" $@ " &&
124+
125+ test_expect_success " grep $L with '$config_str ' interpreted as $type " '
126+ echo $expected_str >expected &&
127+ git $config_str grep "a+b*c" $H ab >actual &&
128+ test_cmp expected actual
129+ '
130+ }
131+
101132for H in HEAD ' '
102133do
103134 case " $H " in
393424 git grep --no-recursive -n -e vvv $H -- t . >actual &&
394425 test_cmp expected actual
395426 '
396- test_expect_success " grep $L with grep.extendedRegexp=false" '
397- echo "${HC}ab:a+bc" >expected &&
398- git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
399- test_cmp expected actual
400- '
401427
402- test_expect_success " grep $L with grep.extendedRegexp=true" '
403- echo "${HC}ab:abc" >expected &&
404- git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
405- test_cmp expected actual
406- '
407428
408- test_expect_success " grep $L with grep.patterntype=basic" '
409- echo "${HC}ab:a+bc" >expected &&
410- git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
411- test_cmp expected actual
412- '
413-
414- test_expect_success " grep $L with grep.patterntype=extended" '
415- echo "${HC}ab:abc" >expected &&
416- git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
417- test_cmp expected actual
418- '
419-
420- test_expect_success " grep $L with grep.patterntype=fixed" '
421- echo "${HC}ab:a+b*c" >expected &&
422- git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
423- test_cmp expected actual
424- '
429+ test_pattern_type " $H " " $HC " " $L " BRE -c grep.extendedRegexp=false
430+ test_pattern_type " $H " " $HC " " $L " ERE -c grep.extendedRegexp=true
431+ test_pattern_type " $H " " $HC " " $L " BRE -c grep.patternType=basic
432+ test_pattern_type " $H " " $HC " " $L " ERE -c grep.patternType=extended
433+ test_pattern_type " $H " " $HC " " $L " FIX -c grep.patternType=fixed
425434
426435 test_expect_success PCRE " grep $L with grep.patterntype=perl" '
427436 echo "${HC}ab:a+b*c" >expected &&
433442 test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
434443 '
435444
436- test_expect_success " grep $L with grep.patternType=default and grep.extendedRegexp=true" '
437- echo "${HC}ab:abc" >expected &&
438- git \
439- -c grep.patternType=default \
440- -c grep.extendedRegexp=true \
441- grep "a+b*c" $H ab >actual &&
442- test_cmp expected actual
443- '
444-
445- test_expect_success " grep $L with grep.extendedRegexp=true and grep.patternType=default" '
446- echo "${HC}ab:abc" >expected &&
447- git \
448- -c grep.extendedRegexp=true \
449- -c grep.patternType=default \
450- grep "a+b*c" $H ab >actual &&
451- test_cmp expected actual
452- '
453-
454- test_expect_success " grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
455- echo "${HC}ab:abc" >expected &&
456- git \
457- -c grep.patternType=extended \
458- -c grep.extendedRegexp=false \
459- grep "a+b*c" $H ab >actual &&
460- test_cmp expected actual
461- '
462-
463- test_expect_success " grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
464- echo "${HC}ab:a+bc" >expected &&
465- git \
466- -c grep.patternType=basic \
467- -c grep.extendedRegexp=true \
468- grep "a+b*c" $H ab >actual &&
469- test_cmp expected actual
470- '
471-
472- test_expect_success " grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
473- echo "${HC}ab:abc" >expected &&
474- git \
475- -c grep.extendedRegexp=false \
476- -c grep.patternType=extended \
477- grep "a+b*c" $H ab >actual &&
478- test_cmp expected actual
479- '
480-
481- test_expect_success " grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
482- echo "${HC}ab:a+bc" >expected &&
483- git \
484- -c grep.extendedRegexp=true \
485- -c grep.patternType=basic \
486- grep "a+b*c" $H ab >actual &&
487- test_cmp expected actual
488- '
445+ test_pattern_type " $H " " $HC " " $L " ERE \
446+ -c grep.patternType=default \
447+ -c grep.extendedRegexp=true
448+ test_pattern_type " $H " " $HC " " $L " ERE \
449+ -c grep.extendedRegexp=true \
450+ -c grep.patternType=default
451+ test_pattern_type " $H " " $HC " " $L " ERE \
452+ -c grep.patternType=extended \
453+ -c grep.extendedRegexp=false
454+ test_pattern_type " $H " " $HC " " $L " BRE \
455+ -c grep.patternType=basic \
456+ -c grep.extendedRegexp=true
457+ test_pattern_type " $H " " $HC " " $L " ERE \
458+ -c grep.extendedRegexp=false \
459+ -c grep.patternType=extended
460+ test_pattern_type " $H " " $HC " " $L " BRE \
461+ -c grep.extendedRegexp=true \
462+ -c grep.patternType=basic
489463
490464 test_expect_success " grep --count $L " '
491465 echo ${HC}ab:3 >expected &&
0 commit comments