3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
13 int main(int argc, const char **argv)
15 printf("Hello world.\n");
21 test_expect_success setup '
25 echo foo_mmap bar mmap
26 echo foo mmap bar_mmap
27 echo foo_mmap bar mmap baz
51 echo "line without leading space1"
52 echo " line with leading space1"
53 echo " line with leading space2"
54 echo " line with leading space3"
55 echo "line without leading space2"
62 test_expect_success 'grep should not segfault with a bad input' '
63 test_must_fail git grep "("
69 HEAD) HC='HEAD:' L='HEAD' ;;
70 '') HC= L='in working tree' ;;
73 test_expect_success "grep -w $L" '
75 echo ${HC}file:1:foo mmap bar
76 echo ${HC}file:3:foo_mmap bar mmap
77 echo ${HC}file:4:foo mmap bar_mmap
78 echo ${HC}file:5:foo_mmap bar mmap baz
80 git -c grep.linenumber=false grep -n -w -e mmap $H >actual &&
81 test_cmp expected actual
84 test_expect_success "grep -w $L" '
86 echo ${HC}file:1:foo mmap bar
87 echo ${HC}file:3:foo_mmap bar mmap
88 echo ${HC}file:4:foo mmap bar_mmap
89 echo ${HC}file:5:foo_mmap bar mmap baz
91 git -c grep.linenumber=true grep -w -e mmap $H >actual &&
92 test_cmp expected actual
95 test_expect_success "grep -w $L" '
97 echo ${HC}file:foo mmap bar
98 echo ${HC}file:foo_mmap bar mmap
99 echo ${HC}file:foo mmap bar_mmap
100 echo ${HC}file:foo_mmap bar mmap baz
102 git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual &&
103 test_cmp expected actual
106 test_expect_success "grep -w $L (w)" '
108 test_must_fail git grep -n -w -e "^w" $H >actual &&
109 test_cmp expected actual
112 test_expect_success "grep -w $L (x)" '
114 echo ${HC}x:1:x x xx x
116 git grep -n -w -e "x xx* x" $H >actual &&
117 test_cmp expected actual
120 test_expect_success "grep -w $L (y-1)" '
124 git grep -n -w -e "^y" $H >actual &&
125 test_cmp expected actual
128 test_expect_success "grep -w $L (y-2)" '
130 if git grep -n -w -e "^y y" $H >actual
132 echo should not have matched
136 test_cmp expected actual
140 test_expect_success "grep -w $L (z)" '
142 if git grep -n -w -e "^z" $H >actual
144 echo should not have matched
148 test_cmp expected actual
152 test_expect_success "grep $L (t-1)" '
153 echo "${HC}t/t:1:test" >expected &&
154 git grep -n -e test $H >actual &&
155 test_cmp expected actual
158 test_expect_success "grep $L (t-2)" '
159 echo "${HC}t:1:test" >expected &&
162 git grep -n -e test $H
164 test_cmp expected actual
167 test_expect_success "grep $L (t-3)" '
168 echo "${HC}t/t:1:test" >expected &&
171 git grep --full-name -n -e test $H
173 test_cmp expected actual
176 test_expect_success "grep -c $L (no /dev/null)" '
177 ! git grep -c test $H | grep /dev/null
180 test_expect_success "grep --max-depth -1 $L" '
182 echo ${HC}t/a/v:1:vvv
186 git grep --max-depth -1 -n -e vvv $H >actual &&
187 test_cmp expected actual
190 test_expect_success "grep --max-depth 0 $L" '
194 git grep --max-depth 0 -n -e vvv $H >actual &&
195 test_cmp expected actual
198 test_expect_success "grep --max-depth 0 -- '*' $L" '
200 echo ${HC}t/a/v:1:vvv
204 git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
205 test_cmp expected actual
208 test_expect_success "grep --max-depth 1 $L" '
213 git grep --max-depth 1 -n -e vvv $H >actual &&
214 test_cmp expected actual
217 test_expect_success "grep --max-depth 0 -- t $L" '
221 git grep --max-depth 0 -n -e vvv $H -- t >actual &&
222 test_cmp expected actual
225 test_expect_success "grep --max-depth 0 -- . t $L" '
230 git grep --max-depth 0 -n -e vvv $H -- . t >actual &&
231 test_cmp expected actual
234 test_expect_success "grep --max-depth 0 -- t . $L" '
239 git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
240 test_cmp expected actual
242 test_expect_success "grep $L with grep.extendedRegexp=false" '
243 echo "${HC}ab:a+bc" >expected &&
244 git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
245 test_cmp expected actual
248 test_expect_success "grep $L with grep.extendedRegexp=true" '
249 echo "${HC}ab:abc" >expected &&
250 git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
251 test_cmp expected actual
254 test_expect_success "grep $L with grep.patterntype=basic" '
255 echo "${HC}ab:a+bc" >expected &&
256 git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
257 test_cmp expected actual
260 test_expect_success "grep $L with grep.patterntype=extended" '
261 echo "${HC}ab:abc" >expected &&
262 git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
263 test_cmp expected actual
266 test_expect_success "grep $L with grep.patterntype=fixed" '
267 echo "${HC}ab:a+b*c" >expected &&
268 git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
269 test_cmp expected actual
272 test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
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 &&
275 test_cmp expected actual
278 test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
279 echo "${HC}ab:abc" >expected &&
281 -c grep.patternType=default \
282 -c grep.extendedRegexp=true \
283 grep "a+b*c" $H ab >actual &&
284 test_cmp expected actual
287 test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
288 echo "${HC}ab:abc" >expected &&
290 -c grep.extendedRegexp=true \
291 -c grep.patternType=default \
292 grep "a+b*c" $H ab >actual &&
293 test_cmp expected actual
296 test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
297 echo "${HC}ab:abc" >expected &&
299 -c grep.patternType=extended \
300 -c grep.extendedRegexp=false \
301 grep "a+b*c" $H ab >actual &&
302 test_cmp expected actual
305 test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
306 echo "${HC}ab:a+bc" >expected &&
308 -c grep.patternType=basic \
309 -c grep.extendedRegexp=true \
310 grep "a+b*c" $H ab >actual &&
311 test_cmp expected actual
314 test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
315 echo "${HC}ab:abc" >expected &&
317 -c grep.extendedRegexp=false \
318 -c grep.patternType=extended \
319 grep "a+b*c" $H ab >actual &&
320 test_cmp expected actual
323 test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
324 echo "${HC}ab:a+bc" >expected &&
326 -c grep.extendedRegexp=true \
327 -c grep.patternType=basic \
328 grep "a+b*c" $H ab >actual &&
329 test_cmp expected actual
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
338 test_expect_success "grep --count -h $L" '
340 git grep --count -h -e b $H -- ab >actual &&
341 test_cmp expected actual
348 test_expect_success 'grep -l -C' '
349 git grep -l -C1 foo >actual &&
350 test_cmp expected actual
356 test_expect_success 'grep -l -C' '
357 git grep -c -C1 foo >actual &&
358 test_cmp expected actual
361 test_expect_success 'grep -L -C' '
362 git ls-files >expected &&
363 git grep -L -C1 nonexistent_string >actual &&
364 test_cmp expected actual
368 file:foo mmap bar_mmap
371 test_expect_success 'grep -e A --and -e B' '
372 git grep -e "foo mmap" --and -e bar_mmap >actual &&
373 test_cmp expected actual
377 file:foo_mmap bar mmap
378 file:foo_mmap bar mmap baz
382 test_expect_success 'grep ( -e A --or -e B ) --and -e B' '
383 git grep \( -e foo_ --or -e baz \) \
384 --and -e " mmap" >actual &&
385 test_cmp expected actual
392 test_expect_success 'grep -e A --and --not -e B' '
393 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
394 test_cmp expected actual
397 test_expect_success 'grep should ignore GREP_OPTIONS' '
398 GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
399 test_cmp expected actual
402 test_expect_success 'grep -f, non-existent file' '
403 test_must_fail git grep -f patterns
409 file:foo_mmap bar mmap
410 file:foo mmap bar_mmap
411 file:foo_mmap bar mmap baz
418 test_expect_success 'grep -f, one pattern' '
419 git grep -f pattern >actual &&
420 test_cmp expected actual
426 file:foo_mmap bar mmap
427 file:foo mmap bar_mmap
428 file:foo_mmap bar mmap baz
439 test_expect_success 'grep -f, multiple patterns' '
440 git grep -f patterns >actual &&
441 test_cmp expected actual
444 test_expect_success 'grep, multiple patterns' '
445 git grep "$(cat patterns)" >actual &&
446 test_cmp expected actual
452 file:foo_mmap bar mmap
453 file:foo mmap bar_mmap
454 file:foo_mmap bar mmap baz
468 test_expect_success 'grep -f, ignore empty lines' '
469 git grep -f patterns >actual &&
470 test_cmp expected actual
473 test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' '
474 git grep -f - <patterns >actual &&
475 test_cmp expected actual
484 test_expect_success 'grep -q, silently report matches' '
486 git grep -q mmap >actual &&
487 test_cmp empty actual &&
488 test_must_fail git grep -q qfwfq >actual &&
489 test_cmp empty actual
492 test_expect_success 'grep -C1 hunk mark between files' '
493 git grep -C1 "^[yz]" >actual &&
494 test_cmp expected actual
497 test_expect_success 'log grep setup' '
500 GIT_AUTHOR_NAME="With * Asterisk" \
501 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
502 git commit -a -m "second" &&
506 git commit -a -m "third" &&
510 GIT_AUTHOR_NAME="Night Fall" \
511 GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \
512 git commit -a -m "fourth"
515 test_expect_success 'log grep (1)' '
516 git log --author=author --pretty=tformat:%s >actual &&
518 echo third && echo initial
520 test_cmp expect actual
523 test_expect_success 'log grep (2)' '
524 git log --author=" * " -F --pretty=tformat:%s >actual &&
528 test_cmp expect actual
531 test_expect_success 'log grep (3)' '
532 git log --author="^A U" --pretty=tformat:%s >actual &&
534 echo third && echo initial
536 test_cmp expect actual
539 test_expect_success 'log grep (4)' '
540 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
544 test_cmp expect actual
547 test_expect_success 'log grep (5)' '
548 git log --author=Thor -F --pretty=tformat:%s >actual &&
550 echo third && echo initial
552 test_cmp expect actual
555 test_expect_success 'log grep (6)' '
556 git log --author=-0700 --pretty=tformat:%s >actual &&
558 test_cmp expect actual
561 test_expect_success 'log grep (7)' '
562 git log -g --grep-reflog="commit: third" --pretty=tformat:%s >actual &&
563 echo third >expect &&
564 test_cmp expect actual
567 test_expect_success 'log grep (8)' '
568 git log -g --grep-reflog="commit: third" --grep-reflog="commit: second" --pretty=tformat:%s >actual &&
570 echo third && echo second
572 test_cmp expect actual
575 test_expect_success 'log grep (9)' '
576 git log -g --grep-reflog="commit: third" --author="Thor" --pretty=tformat:%s >actual &&
577 echo third >expect &&
578 test_cmp expect actual
581 test_expect_success 'log grep (9)' '
582 git log -g --grep-reflog="commit: third" --author="non-existant" --pretty=tformat:%s >actual &&
584 test_cmp expect actual
587 test_expect_success 'log --grep-reflog can only be used under -g' '
588 test_must_fail git log --grep-reflog="commit: third"
591 test_expect_success 'log with multiple --grep uses union' '
592 git log --grep=i --grep=r --format=%s >actual &&
594 echo fourth && echo third && echo initial
596 test_cmp expect actual
599 test_expect_success 'log --all-match with multiple --grep uses intersection' '
600 git log --all-match --grep=i --grep=r --format=%s >actual &&
604 test_cmp expect actual
607 test_expect_success 'log with multiple --author uses union' '
608 git log --author="Thor" --author="Aster" --format=%s >actual &&
610 echo third && echo second && echo initial
612 test_cmp expect actual
615 test_expect_success 'log --all-match with multiple --author still uses union' '
616 git log --all-match --author="Thor" --author="Aster" --format=%s >actual &&
618 echo third && echo second && echo initial
620 test_cmp expect actual
623 test_expect_success 'log --grep --author uses intersection' '
624 # grep matches only third and fourth
625 # author matches only initial and third
626 git log --author="A U Thor" --grep=r --format=%s >actual &&
630 test_cmp expect actual
633 test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' '
634 # grep matches initial and second but not third
635 # author matches only initial and third
636 git log --author="A U Thor" --grep=s --grep=l --format=%s >actual &&
640 test_cmp expect actual
643 test_expect_success 'log ---all-match -grep --author --author still takes union of authors and intersects with grep' '
644 # grep matches only initial and third
645 # author matches all but second
646 git log --all-match --author="Thor" --author="Night" --grep=i --format=%s >actual &&
648 echo third && echo initial
650 test_cmp expect actual
653 test_expect_success 'log --grep --author --author takes union of authors and intersects with grep' '
654 # grep matches only initial and third
655 # author matches all but second
656 git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
658 echo third && echo initial
660 test_cmp expect actual
663 test_expect_success 'log --all-match --grep --grep --author takes intersection' '
664 # grep matches only third
665 # author matches only initial and third
666 git log --all-match --author="A U Thor" --grep=i --grep=r --format=%s >actual &&
670 test_cmp expect actual
673 test_expect_success 'log --author does not search in timestamp' '
675 git log --author="$GIT_AUTHOR_DATE" >actual &&
676 test_cmp expect actual
679 test_expect_success 'log --committer does not search in timestamp' '
681 git log --committer="$GIT_COMMITTER_DATE" >actual &&
682 test_cmp expect actual
685 test_expect_success 'grep with CE_VALID file' '
686 git update-index --assume-unchanged t/t &&
688 test "$(git grep test)" = "t/t:test" &&
689 git update-index --no-assume-unchanged t/t &&
694 hello.c=#include <stdio.h>
698 test_expect_success 'grep -p with userdiff' '
699 git config diff.custom.funcname "^#" &&
700 echo "hello.c diff=custom" >.gitattributes &&
701 git grep -p return >actual &&
702 test_cmp expected actual
706 hello.c=int main(int argc, const char **argv)
710 test_expect_success 'grep -p' '
711 rm -f .gitattributes &&
712 git grep -p return >actual &&
713 test_cmp expected actual
717 hello.c-#include <stdio.h>
718 hello.c=int main(int argc, const char **argv)
720 hello.c- printf("Hello world.\n");
724 test_expect_success 'grep -p -B5' '
725 git grep -p -B5 return >actual &&
726 test_cmp expected actual
730 hello.c=int main(int argc, const char **argv)
732 hello.c- printf("Hello world.\n");
734 hello.c- /* char ?? */
738 test_expect_success 'grep -W' '
739 git grep -W return >actual &&
740 test_cmp expected actual
744 hello.c= printf("Hello world.\n");
746 hello.c- /* char ?? */
749 test_expect_success 'grep -W with userdiff' '
750 test_when_finished "rm -f .gitattributes" &&
751 git config diff.custom.xfuncname "(printf.*|})$" &&
752 echo "hello.c diff=custom" >.gitattributes &&
753 git grep -W return >actual &&
754 test_cmp expected actual
757 test_expect_success 'grep from a subdirectory to search wider area (1)' '
760 cd s && git grep "x x x" ..
764 test_expect_success 'grep from a subdirectory to search wider area (2)' '
768 ( git grep xxyyzz .. >out ; echo $? >status )
770 test 1 = $(cat status)
775 hello.c:int main(int argc, const char **argv)
778 test_expect_success 'grep -Fi' '
779 git grep -Fi "CHAR *" >actual &&
780 test_cmp expected actual
783 test_expect_success 'outside of git repository' '
785 mkdir -p non/git/sub &&
786 echo hello >non/git/file1 &&
787 echo world >non/git/sub/file2 &&
791 } >non/expect.full &&
792 echo file2:world >non/expect.sub &&
794 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
795 export GIT_CEILING_DIRECTORIES &&
797 test_must_fail git grep o &&
798 git grep --no-index o >../actual.full &&
799 test_cmp ../expect.full ../actual.full
801 test_must_fail git grep o &&
802 git grep --no-index o >../../actual.sub &&
803 test_cmp ../../expect.sub ../../actual.sub
806 echo ".*o*" >non/git/.gitignore &&
808 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
809 export GIT_CEILING_DIRECTORIES &&
811 test_must_fail git grep o &&
812 git grep --no-index --exclude-standard o >../actual.full &&
813 test_cmp ../expect.full ../actual.full &&
816 echo ".gitignore:.*o*"
818 } >../expect.with.ignored &&
819 git grep --no-index --no-exclude o >../actual.full &&
820 test_cmp ../expect.with.ignored ../actual.full
824 test_expect_success 'inside git repository but with --no-index' '
826 mkdir -p is/git/sub &&
827 echo hello >is/git/file1 &&
828 echo world >is/git/sub/file2 &&
829 echo ".*o*" >is/git/.gitignore &&
833 } >is/expect.unignored &&
835 echo ".gitignore:.*o*" &&
836 cat is/expect.unignored
838 : >is/expect.empty &&
839 echo file2:world >is/expect.sub &&
843 test_must_fail git grep o >../actual.full &&
844 test_cmp ../expect.empty ../actual.full &&
846 git grep --untracked o >../actual.unignored &&
847 test_cmp ../expect.unignored ../actual.unignored &&
849 git grep --no-index o >../actual.full &&
850 test_cmp ../expect.full ../actual.full &&
852 git grep --no-index --exclude-standard o >../actual.unignored &&
853 test_cmp ../expect.unignored ../actual.unignored &&
856 test_must_fail git grep o >../../actual.sub &&
857 test_cmp ../../expect.empty ../../actual.sub &&
859 git grep --no-index o >../../actual.sub &&
860 test_cmp ../../expect.sub ../../actual.sub &&
862 git grep --untracked o >../../actual.sub &&
863 test_cmp ../../expect.sub ../../actual.sub
867 test_expect_success 'setup double-dash tests' '
868 cat >double-dash <<EOF &&
879 test_expect_success 'grep -- pattern' '
880 git grep -- "->" >actual &&
881 test_cmp expected actual
883 test_expect_success 'grep -- pattern -- pathspec' '
884 git grep -- "->" -- double-dash >actual &&
885 test_cmp expected actual
887 test_expect_success 'grep -e pattern -- path' '
888 git grep -e "->" -- double-dash >actual &&
889 test_cmp expected actual
895 test_expect_success 'grep -e -- -- path' '
896 git grep -e -- -- double-dash >actual &&
897 test_cmp expected actual
901 hello.c:int main(int argc, const char **argv)
902 hello.c: printf("Hello world.\n");
905 test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
906 git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
907 test_cmp expected actual
910 test_expect_success LIBPCRE 'grep -P pattern' '
911 git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
912 test_cmp expected actual
915 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
917 test_must_fail git -c grep.extendedregexp=true \
918 grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
919 test_cmp empty actual
922 test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
923 git -c grep.extendedregexp=true \
924 grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
925 test_cmp expected actual
928 test_expect_success LIBPCRE 'grep -P -v pattern' '
933 git grep -P -v "abc" ab >actual &&
934 test_cmp expected actual
937 test_expect_success LIBPCRE 'grep -P -i pattern' '
938 cat >expected <<-EOF &&
939 hello.c: printf("Hello world.\n");
941 git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
942 test_cmp expected actual
945 test_expect_success LIBPCRE 'grep -P -w pattern' '
947 echo "hello_world:Hello world"
948 echo "hello_world:HeLLo world"
950 git grep -P -w "He((?i)ll)o" hello_world >actual &&
951 test_cmp expected actual
954 test_expect_success 'grep -G invalidpattern properly dies ' '
955 test_must_fail git grep -G "a["
958 test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' '
959 test_must_fail git -c grep.patterntype=basic grep "a["
962 test_expect_success 'grep -E invalidpattern properly dies ' '
963 test_must_fail git grep -E "a["
966 test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' '
967 test_must_fail git -c grep.patterntype=extended grep "a["
970 test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
971 test_must_fail git grep -P "a["
974 test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
975 test_must_fail git -c grep.patterntype=perl grep "a["
978 test_expect_success 'grep -G -E -F pattern' '
979 echo "ab:a+b*c" >expected &&
980 git grep -G -E -F "a+b*c" ab >actual &&
981 test_cmp expected actual
984 test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' '
985 echo "ab:a+b*c" >expected &&
987 -c grep.patterntype=basic \
988 -c grep.patterntype=extended \
989 -c grep.patterntype=fixed \
990 grep "a+b*c" ab >actual &&
991 test_cmp expected actual
994 test_expect_success 'grep -E -F -G pattern' '
995 echo "ab:a+bc" >expected &&
996 git grep -E -F -G "a+b*c" ab >actual &&
997 test_cmp expected actual
1000 test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' '
1001 echo "ab:a+bc" >expected &&
1003 -c grep.patterntype=extended \
1004 -c grep.patterntype=fixed \
1005 -c grep.patterntype=basic \
1006 grep "a+b*c" ab >actual &&
1007 test_cmp expected actual
1010 test_expect_success 'grep -F -G -E pattern' '
1011 echo "ab:abc" >expected &&
1012 git grep -F -G -E "a+b*c" ab >actual &&
1013 test_cmp expected actual
1016 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' '
1017 echo "ab:abc" >expected &&
1019 -c grep.patterntype=fixed \
1020 -c grep.patterntype=basic \
1021 -c grep.patterntype=extended \
1022 grep "a+b*c" ab >actual &&
1023 test_cmp expected actual
1026 test_expect_success 'grep -G -F -P -E pattern' '
1028 test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
1029 test_cmp empty actual
1032 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
1034 test_must_fail git \
1035 -c grep.patterntype=fixed \
1036 -c grep.patterntype=basic \
1037 -c grep.patterntype=perl \
1038 -c grep.patterntype=extended \
1039 grep "a\x{2b}b\x{2a}c" ab >actual &&
1040 test_cmp empty actual
1043 test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
1044 echo "ab:a+b*c" >expected &&
1045 git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
1046 test_cmp expected actual
1049 test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
1050 echo "ab:a+b*c" >expected &&
1052 -c grep.patterntype=fixed \
1053 -c grep.patterntype=basic \
1054 -c grep.patterntype=extended \
1055 -c grep.patterntype=perl \
1056 grep "a\x{2b}b\x{2a}c" ab >actual &&
1057 test_cmp expected actual
1060 test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
1061 echo "ab:a+b*c" >expected &&
1063 -c grep.patterntype=fixed \
1064 grep -P "a\x{2b}b\x{2a}c" ab >actual &&
1065 test_cmp expected actual
1068 test_expect_success 'grep -F pattern with grep.patternType=basic' '
1069 echo "ab:a+b*c" >expected &&
1071 -c grep.patterntype=basic \
1072 grep -F "*c" ab >actual &&
1073 test_cmp expected actual
1076 test_expect_success 'grep -G pattern with grep.patternType=fixed' '
1082 -c grep.patterntype=fixed \
1083 grep -G "a+b" ab >actual &&
1084 test_cmp expected actual
1087 test_expect_success 'grep -E pattern with grep.patternType=fixed' '
1094 -c grep.patterntype=fixed \
1095 grep -E "a+" ab >actual &&
1096 test_cmp expected actual
1100 git config "$1" "$2" &&
1101 test_when_finished "git config --unset $1"
1105 hello.c<RED>:<RESET>int main(int argc, const char **argv)
1106 hello.c<RED>-<RESET>{
1108 hello.c<RED>:<RESET> /* char ?? */
1109 hello.c<RED>-<RESET>}
1111 hello_world<RED>:<RESET>Hello_world
1112 hello_world<RED>-<RESET>HeLLo_world
1115 test_expect_success 'grep --color, separator' '
1116 test_config color.grep.context normal &&
1117 test_config color.grep.filename normal &&
1118 test_config color.grep.function normal &&
1119 test_config color.grep.linenumber normal &&
1120 test_config color.grep.match normal &&
1121 test_config color.grep.selected normal &&
1122 test_config color.grep.separator red &&
1124 git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
1125 test_decode_color >actual &&
1126 test_cmp expected actual
1130 hello.c:int main(int argc, const char **argv)
1131 hello.c: /* char ?? */
1133 hello_world:Hello_world
1136 test_expect_success 'grep --break' '
1137 git grep --break -e char -e lo_w hello.c hello_world >actual &&
1138 test_cmp expected actual
1142 hello.c:int main(int argc, const char **argv)
1145 hello.c: /* char ?? */
1148 hello_world:Hello_world
1149 hello_world-HeLLo_world
1152 test_expect_success 'grep --break with context' '
1153 git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
1154 test_cmp expected actual
1159 int main(int argc, const char **argv)
1165 test_expect_success 'grep --heading' '
1166 git grep --heading -e char -e lo_w hello.c hello_world >actual &&
1167 test_cmp expected actual
1171 <BOLD;GREEN>hello.c<RESET>
1172 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1173 6: /* <BLACK;BYELLOW>char<RESET> ?? */
1175 <BOLD;GREEN>hello_world<RESET>
1176 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
1179 test_expect_success 'mimic ack-grep --group' '
1180 test_config color.grep.context normal &&
1181 test_config color.grep.filename "bold green" &&
1182 test_config color.grep.function normal &&
1183 test_config color.grep.linenumber normal &&
1184 test_config color.grep.match "black yellow" &&
1185 test_config color.grep.selected normal &&
1186 test_config color.grep.separator normal &&
1188 git grep --break --heading -n --color \
1189 -e char -e lo_w hello.c hello_world |
1190 test_decode_color >actual &&
1191 test_cmp expected actual
1195 space: line with leading space1
1196 space: line with leading space2
1197 space: line with leading space3
1200 test_expect_success LIBPCRE 'grep -E "^ "' '
1201 git grep -E "^ " space >actual &&
1202 test_cmp expected actual
1205 test_expect_success LIBPCRE 'grep -P "^ "' '
1206 git grep -P "^ " space >actual &&
1207 test_cmp expected actual