3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
15 int main(int argc, const char **argv)
17 printf("Hello world.\n");
23 test_expect_success setup '
27 echo foo_mmap bar mmap
28 echo foo mmap bar_mmap
29 echo foo_mmap bar mmap baz
53 echo "line without leading space1"
54 echo " line with leading space1"
55 echo " line with leading space2"
56 echo " line with leading space3"
57 echo "line without leading space2"
64 test_expect_success 'grep should not segfault with a bad input' '
65 test_must_fail git grep "("
71 HEAD) HC='HEAD:' L='HEAD' ;;
72 '') HC= L='in working tree' ;;
75 test_expect_success "grep -w $L" '
77 echo ${HC}file:1:foo mmap bar
78 echo ${HC}file:3:foo_mmap bar mmap
79 echo ${HC}file:4:foo mmap bar_mmap
80 echo ${HC}file:5:foo_mmap bar mmap baz
82 git -c grep.linenumber=false grep -n -w -e mmap $H >actual &&
83 test_cmp expected actual
86 test_expect_success "grep -w $L" '
88 echo ${HC}file:1:foo mmap bar
89 echo ${HC}file:3:foo_mmap bar mmap
90 echo ${HC}file:4:foo mmap bar_mmap
91 echo ${HC}file:5:foo_mmap bar mmap baz
93 git -c grep.linenumber=true grep -w -e mmap $H >actual &&
94 test_cmp expected actual
97 test_expect_success "grep -w $L" '
99 echo ${HC}file:foo mmap bar
100 echo ${HC}file:foo_mmap bar mmap
101 echo ${HC}file:foo mmap bar_mmap
102 echo ${HC}file:foo_mmap bar mmap baz
104 git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual &&
105 test_cmp expected actual
108 test_expect_success "grep -w $L (w)" '
110 test_must_fail git grep -n -w -e "^w" $H >actual &&
111 test_cmp expected actual
114 test_expect_success "grep -w $L (x)" '
116 echo ${HC}x:1:x x xx x
118 git grep -n -w -e "x xx* x" $H >actual &&
119 test_cmp expected actual
122 test_expect_success "grep -w $L (y-1)" '
126 git grep -n -w -e "^y" $H >actual &&
127 test_cmp expected actual
130 test_expect_success "grep -w $L (y-2)" '
132 if git grep -n -w -e "^y y" $H >actual
134 echo should not have matched
138 test_cmp expected actual
142 test_expect_success "grep -w $L (z)" '
144 if git grep -n -w -e "^z" $H >actual
146 echo should not have matched
150 test_cmp expected actual
154 test_expect_success "grep $L (t-1)" '
155 echo "${HC}t/t:1:test" >expected &&
156 git grep -n -e test $H >actual &&
157 test_cmp expected actual
160 test_expect_success "grep $L (t-2)" '
161 echo "${HC}t:1:test" >expected &&
164 git grep -n -e test $H
166 test_cmp expected actual
169 test_expect_success "grep $L (t-3)" '
170 echo "${HC}t/t:1:test" >expected &&
173 git grep --full-name -n -e test $H
175 test_cmp expected actual
178 test_expect_success "grep -c $L (no /dev/null)" '
179 ! git grep -c test $H | grep /dev/null
182 test_expect_success "grep --max-depth -1 $L" '
184 echo ${HC}t/a/v:1:vvv
188 git grep --max-depth -1 -n -e vvv $H >actual &&
189 test_cmp expected actual
192 test_expect_success "grep --max-depth 0 $L" '
196 git grep --max-depth 0 -n -e vvv $H >actual &&
197 test_cmp expected actual
200 test_expect_success "grep --max-depth 0 -- '*' $L" '
202 echo ${HC}t/a/v:1:vvv
206 git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
207 test_cmp expected actual
210 test_expect_success "grep --max-depth 1 $L" '
215 git grep --max-depth 1 -n -e vvv $H >actual &&
216 test_cmp expected actual
219 test_expect_success "grep --max-depth 0 -- t $L" '
223 git grep --max-depth 0 -n -e vvv $H -- t >actual &&
224 test_cmp expected actual
227 test_expect_success "grep --max-depth 0 -- . t $L" '
232 git grep --max-depth 0 -n -e vvv $H -- . t >actual &&
233 test_cmp expected actual
236 test_expect_success "grep --max-depth 0 -- t . $L" '
241 git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
242 test_cmp expected actual
244 test_expect_success "grep $L with grep.extendedRegexp=false" '
245 echo "${HC}ab:a+bc" >expected &&
246 git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
247 test_cmp expected actual
250 test_expect_success "grep $L with grep.extendedRegexp=true" '
251 echo "${HC}ab:abc" >expected &&
252 git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
253 test_cmp expected actual
256 test_expect_success "grep $L with grep.patterntype=basic" '
257 echo "${HC}ab:a+bc" >expected &&
258 git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
259 test_cmp expected actual
262 test_expect_success "grep $L with grep.patterntype=extended" '
263 echo "${HC}ab:abc" >expected &&
264 git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
265 test_cmp expected actual
268 test_expect_success "grep $L with grep.patterntype=fixed" '
269 echo "${HC}ab:a+b*c" >expected &&
270 git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
271 test_cmp expected actual
274 test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
275 echo "${HC}ab:a+b*c" >expected &&
276 git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual &&
277 test_cmp expected actual
280 test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
281 echo "${HC}ab:abc" >expected &&
283 -c grep.patternType=default \
284 -c grep.extendedRegexp=true \
285 grep "a+b*c" $H ab >actual &&
286 test_cmp expected actual
289 test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
290 echo "${HC}ab:abc" >expected &&
292 -c grep.extendedRegexp=true \
293 -c grep.patternType=default \
294 grep "a+b*c" $H ab >actual &&
295 test_cmp expected actual
298 test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
299 echo "${HC}ab:abc" >expected &&
301 -c grep.patternType=extended \
302 -c grep.extendedRegexp=false \
303 grep "a+b*c" $H ab >actual &&
304 test_cmp expected actual
307 test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
308 echo "${HC}ab:a+bc" >expected &&
310 -c grep.patternType=basic \
311 -c grep.extendedRegexp=true \
312 grep "a+b*c" $H ab >actual &&
313 test_cmp expected actual
316 test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
317 echo "${HC}ab:abc" >expected &&
319 -c grep.extendedRegexp=false \
320 -c grep.patternType=extended \
321 grep "a+b*c" $H ab >actual &&
322 test_cmp expected actual
325 test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
326 echo "${HC}ab:a+bc" >expected &&
328 -c grep.extendedRegexp=true \
329 -c grep.patternType=basic \
330 grep "a+b*c" $H ab >actual &&
331 test_cmp expected actual
334 test_expect_success "grep --count $L" '
335 echo ${HC}ab:3 >expected &&
336 git grep --count -e b $H -- ab >actual &&
337 test_cmp expected actual
340 test_expect_success "grep --count -h $L" '
342 git grep --count -h -e b $H -- ab >actual &&
343 test_cmp expected actual
350 test_expect_success 'grep -l -C' '
351 git grep -l -C1 foo >actual &&
352 test_cmp expected actual
358 test_expect_success 'grep -l -C' '
359 git grep -c -C1 foo >actual &&
360 test_cmp expected actual
363 test_expect_success 'grep -L -C' '
364 git ls-files >expected &&
365 git grep -L -C1 nonexistent_string >actual &&
366 test_cmp expected actual
370 file:foo mmap bar_mmap
373 test_expect_success 'grep -e A --and -e B' '
374 git grep -e "foo mmap" --and -e bar_mmap >actual &&
375 test_cmp expected actual
379 file:foo_mmap bar mmap
380 file:foo_mmap bar mmap baz
384 test_expect_success 'grep ( -e A --or -e B ) --and -e B' '
385 git grep \( -e foo_ --or -e baz \) \
386 --and -e " mmap" >actual &&
387 test_cmp expected actual
394 test_expect_success 'grep -e A --and --not -e B' '
395 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
396 test_cmp expected actual
399 test_expect_success 'grep should ignore GREP_OPTIONS' '
400 GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
401 test_cmp expected actual
404 test_expect_success 'grep -f, non-existent file' '
405 test_must_fail git grep -f patterns
411 file:foo_mmap bar mmap
412 file:foo mmap bar_mmap
413 file:foo_mmap bar mmap baz
420 test_expect_success 'grep -f, one pattern' '
421 git grep -f pattern >actual &&
422 test_cmp expected actual
428 file:foo_mmap bar mmap
429 file:foo mmap bar_mmap
430 file:foo_mmap bar mmap baz
441 test_expect_success 'grep -f, multiple patterns' '
442 git grep -f patterns >actual &&
443 test_cmp expected actual
446 test_expect_success 'grep, multiple patterns' '
447 git grep "$(cat patterns)" >actual &&
448 test_cmp expected actual
454 file:foo_mmap bar mmap
455 file:foo mmap bar_mmap
456 file:foo_mmap bar mmap baz
470 test_expect_success 'grep -f, ignore empty lines' '
471 git grep -f patterns >actual &&
472 test_cmp expected actual
475 test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' '
476 git grep -f - <patterns >actual &&
477 test_cmp expected actual
486 test_expect_success 'grep -q, silently report matches' '
488 git grep -q mmap >actual &&
489 test_cmp empty actual &&
490 test_must_fail git grep -q qfwfq >actual &&
491 test_cmp empty actual
494 test_expect_success 'grep -C1 hunk mark between files' '
495 git grep -C1 "^[yz]" >actual &&
496 test_cmp expected actual
499 test_expect_success 'log grep setup' '
502 GIT_AUTHOR_NAME="With * Asterisk" \
503 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
504 git commit -a -m "second" &&
508 git commit -a -m "third" &&
512 GIT_AUTHOR_NAME="Night Fall" \
513 GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \
514 git commit -a -m "fourth"
517 test_expect_success 'log grep (1)' '
518 git log --author=author --pretty=tformat:%s >actual &&
520 echo third && echo initial
522 test_cmp expect actual
525 test_expect_success 'log grep (2)' '
526 git log --author=" * " -F --pretty=tformat:%s >actual &&
530 test_cmp expect actual
533 test_expect_success 'log grep (3)' '
534 git log --author="^A U" --pretty=tformat:%s >actual &&
536 echo third && echo initial
538 test_cmp expect actual
541 test_expect_success 'log grep (4)' '
542 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
546 test_cmp expect actual
549 test_expect_success 'log grep (5)' '
550 git log --author=Thor -F --pretty=tformat:%s >actual &&
552 echo third && echo initial
554 test_cmp expect actual
557 test_expect_success 'log grep (6)' '
558 git log --author=-0700 --pretty=tformat:%s >actual &&
560 test_cmp expect actual
563 test_expect_success 'log grep (7)' '
564 git log -g --grep-reflog="commit: third" --pretty=tformat:%s >actual &&
565 echo third >expect &&
566 test_cmp expect actual
569 test_expect_success 'log grep (8)' '
570 git log -g --grep-reflog="commit: third" --grep-reflog="commit: second" --pretty=tformat:%s >actual &&
572 echo third && echo second
574 test_cmp expect actual
577 test_expect_success 'log grep (9)' '
578 git log -g --grep-reflog="commit: third" --author="Thor" --pretty=tformat:%s >actual &&
579 echo third >expect &&
580 test_cmp expect actual
583 test_expect_success 'log grep (9)' '
584 git log -g --grep-reflog="commit: third" --author="non-existant" --pretty=tformat:%s >actual &&
586 test_cmp expect actual
589 test_expect_success 'log --grep-reflog can only be used under -g' '
590 test_must_fail git log --grep-reflog="commit: third"
593 test_expect_success 'log with multiple --grep uses union' '
594 git log --grep=i --grep=r --format=%s >actual &&
596 echo fourth && echo third && echo initial
598 test_cmp expect actual
601 test_expect_success 'log --all-match with multiple --grep uses intersection' '
602 git log --all-match --grep=i --grep=r --format=%s >actual &&
606 test_cmp expect actual
609 test_expect_success 'log with multiple --author uses union' '
610 git log --author="Thor" --author="Aster" --format=%s >actual &&
612 echo third && echo second && echo initial
614 test_cmp expect actual
617 test_expect_success 'log --all-match with multiple --author still uses union' '
618 git log --all-match --author="Thor" --author="Aster" --format=%s >actual &&
620 echo third && echo second && echo initial
622 test_cmp expect actual
625 test_expect_success 'log --grep --author uses intersection' '
626 # grep matches only third and fourth
627 # author matches only initial and third
628 git log --author="A U Thor" --grep=r --format=%s >actual &&
632 test_cmp expect actual
635 test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' '
636 # grep matches initial and second but not third
637 # author matches only initial and third
638 git log --author="A U Thor" --grep=s --grep=l --format=%s >actual &&
642 test_cmp expect actual
645 test_expect_success 'log ---all-match -grep --author --author still takes union of authors and intersects with grep' '
646 # grep matches only initial and third
647 # author matches all but second
648 git log --all-match --author="Thor" --author="Night" --grep=i --format=%s >actual &&
650 echo third && echo initial
652 test_cmp expect actual
655 test_expect_success 'log --grep --author --author takes union of authors and intersects with grep' '
656 # grep matches only initial and third
657 # author matches all but second
658 git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
660 echo third && echo initial
662 test_cmp expect actual
665 test_expect_success 'log --all-match --grep --grep --author takes intersection' '
666 # grep matches only third
667 # author matches only initial and third
668 git log --all-match --author="A U Thor" --grep=i --grep=r --format=%s >actual &&
672 test_cmp expect actual
675 test_expect_success 'log --author does not search in timestamp' '
677 git log --author="$GIT_AUTHOR_DATE" >actual &&
678 test_cmp expect actual
681 test_expect_success 'log --committer does not search in timestamp' '
683 git log --committer="$GIT_COMMITTER_DATE" >actual &&
684 test_cmp expect actual
687 test_expect_success 'grep with CE_VALID file' '
688 git update-index --assume-unchanged t/t &&
690 test "$(git grep test)" = "t/t:test" &&
691 git update-index --no-assume-unchanged t/t &&
696 hello.c=#include <stdio.h>
700 test_expect_success 'grep -p with userdiff' '
701 git config diff.custom.funcname "^#" &&
702 echo "hello.c diff=custom" >.gitattributes &&
703 git grep -p return >actual &&
704 test_cmp expected actual
708 hello.c=int main(int argc, const char **argv)
712 test_expect_success 'grep -p' '
713 rm -f .gitattributes &&
714 git grep -p return >actual &&
715 test_cmp expected actual
719 hello.c-#include <stdio.h>
721 hello.c=int main(int argc, const char **argv)
723 hello.c- printf("Hello world.\n");
727 test_expect_success 'grep -p -B5' '
728 git grep -p -B5 return >actual &&
729 test_cmp expected actual
733 hello.c=int main(int argc, const char **argv)
735 hello.c- printf("Hello world.\n");
737 hello.c- /* char ?? */
741 test_expect_success 'grep -W' '
742 git grep -W return >actual &&
743 test_cmp expected actual
747 hello.c-#include <assert.h>
748 hello.c:#include <stdio.h>
751 test_expect_success 'grep -W shows no trailing empty lines' '
752 git grep -W stdio >actual &&
753 test_cmp expected actual
757 hello.c= printf("Hello world.\n");
759 hello.c- /* char ?? */
762 test_expect_success 'grep -W with userdiff' '
763 test_when_finished "rm -f .gitattributes" &&
764 git config diff.custom.xfuncname "(printf.*|})$" &&
765 echo "hello.c diff=custom" >.gitattributes &&
766 git grep -W return >actual &&
767 test_cmp expected actual
770 test_expect_success 'grep from a subdirectory to search wider area (1)' '
773 cd s && git grep "x x x" ..
777 test_expect_success 'grep from a subdirectory to search wider area (2)' '
781 ( git grep xxyyzz .. >out ; echo $? >status )
783 test 1 = $(cat status)
788 hello.c:int main(int argc, const char **argv)
791 test_expect_success 'grep -Fi' '
792 git grep -Fi "CHAR *" >actual &&
793 test_cmp expected actual
796 test_expect_success 'outside of git repository' '
798 mkdir -p non/git/sub &&
799 echo hello >non/git/file1 &&
800 echo world >non/git/sub/file2 &&
804 } >non/expect.full &&
805 echo file2:world >non/expect.sub &&
807 GIT_CEILING_DIRECTORIES="$(pwd)/non" &&
808 export GIT_CEILING_DIRECTORIES &&
810 test_must_fail git grep o &&
811 git grep --no-index o >../actual.full &&
812 test_cmp ../expect.full ../actual.full &&
814 test_must_fail git grep o &&
815 git grep --no-index o >../../actual.sub &&
816 test_cmp ../../expect.sub ../../actual.sub
819 echo ".*o*" >non/git/.gitignore &&
821 GIT_CEILING_DIRECTORIES="$(pwd)/non" &&
822 export GIT_CEILING_DIRECTORIES &&
824 test_must_fail git grep o &&
825 git grep --no-index --exclude-standard o >../actual.full &&
826 test_cmp ../expect.full ../actual.full &&
829 echo ".gitignore:.*o*" &&
831 } >../expect.with.ignored &&
832 git grep --no-index --no-exclude o >../actual.full &&
833 test_cmp ../expect.with.ignored ../actual.full
837 test_expect_success 'outside of git repository with fallbackToNoIndex' '
839 mkdir -p non/git/sub &&
840 echo hello >non/git/file1 &&
841 echo world >non/git/sub/file2 &&
842 cat <<-\EOF >non/expect.full &&
846 echo file2:world >non/expect.sub &&
848 GIT_CEILING_DIRECTORIES="$(pwd)/non" &&
849 export GIT_CEILING_DIRECTORIES &&
851 test_must_fail git -c grep.fallbackToNoIndex=false grep o &&
852 git -c grep.fallbackToNoIndex=true grep o >../actual.full &&
853 test_cmp ../expect.full ../actual.full &&
855 test_must_fail git -c grep.fallbackToNoIndex=false grep o &&
856 git -c grep.fallbackToNoIndex=true grep o >../../actual.sub &&
857 test_cmp ../../expect.sub ../../actual.sub
860 echo ".*o*" >non/git/.gitignore &&
862 GIT_CEILING_DIRECTORIES="$(pwd)/non" &&
863 export GIT_CEILING_DIRECTORIES &&
865 test_must_fail git -c grep.fallbackToNoIndex=false grep o &&
866 git -c grep.fallbackToNoIndex=true grep --exclude-standard o >../actual.full &&
867 test_cmp ../expect.full ../actual.full &&
870 echo ".gitignore:.*o*" &&
872 } >../expect.with.ignored &&
873 git -c grep.fallbackToNoIndex grep --no-exclude o >../actual.full &&
874 test_cmp ../expect.with.ignored ../actual.full
878 test_expect_success 'inside git repository but with --no-index' '
880 mkdir -p is/git/sub &&
881 echo hello >is/git/file1 &&
882 echo world >is/git/sub/file2 &&
883 echo ".*o*" >is/git/.gitignore &&
887 } >is/expect.unignored &&
889 echo ".gitignore:.*o*" &&
890 cat is/expect.unignored
892 : >is/expect.empty &&
893 echo file2:world >is/expect.sub &&
897 test_must_fail git grep o >../actual.full &&
898 test_cmp ../expect.empty ../actual.full &&
900 git grep --untracked o >../actual.unignored &&
901 test_cmp ../expect.unignored ../actual.unignored &&
903 git grep --no-index o >../actual.full &&
904 test_cmp ../expect.full ../actual.full &&
906 git grep --no-index --exclude-standard o >../actual.unignored &&
907 test_cmp ../expect.unignored ../actual.unignored &&
910 test_must_fail git grep o >../../actual.sub &&
911 test_cmp ../../expect.empty ../../actual.sub &&
913 git grep --no-index o >../../actual.sub &&
914 test_cmp ../../expect.sub ../../actual.sub &&
916 git grep --untracked o >../../actual.sub &&
917 test_cmp ../../expect.sub ../../actual.sub
921 test_expect_success 'setup double-dash tests' '
922 cat >double-dash <<EOF &&
933 test_expect_success 'grep -- pattern' '
934 git grep -- "->" >actual &&
935 test_cmp expected actual
937 test_expect_success 'grep -- pattern -- pathspec' '
938 git grep -- "->" -- double-dash >actual &&
939 test_cmp expected actual
941 test_expect_success 'grep -e pattern -- path' '
942 git grep -e "->" -- double-dash >actual &&
943 test_cmp expected actual
949 test_expect_success 'grep -e -- -- path' '
950 git grep -e -- -- double-dash >actual &&
951 test_cmp expected actual
955 hello.c:int main(int argc, const char **argv)
956 hello.c: printf("Hello world.\n");
959 test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
960 git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
961 test_cmp expected actual
964 test_expect_success LIBPCRE 'grep -P pattern' '
965 git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
966 test_cmp expected actual
969 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
971 test_must_fail git -c grep.extendedregexp=true \
972 grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
973 test_cmp empty actual
976 test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
977 git -c grep.extendedregexp=true \
978 grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
979 test_cmp expected actual
982 test_expect_success LIBPCRE 'grep -P -v pattern' '
987 git grep -P -v "abc" ab >actual &&
988 test_cmp expected actual
991 test_expect_success LIBPCRE 'grep -P -i pattern' '
992 cat >expected <<-EOF &&
993 hello.c: printf("Hello world.\n");
995 git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
996 test_cmp expected actual
999 test_expect_success LIBPCRE 'grep -P -w pattern' '
1001 echo "hello_world:Hello world"
1002 echo "hello_world:HeLLo world"
1004 git grep -P -w "He((?i)ll)o" hello_world >actual &&
1005 test_cmp expected actual
1008 test_expect_success 'grep -G invalidpattern properly dies ' '
1009 test_must_fail git grep -G "a["
1012 test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' '
1013 test_must_fail git -c grep.patterntype=basic grep "a["
1016 test_expect_success 'grep -E invalidpattern properly dies ' '
1017 test_must_fail git grep -E "a["
1020 test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' '
1021 test_must_fail git -c grep.patterntype=extended grep "a["
1024 test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
1025 test_must_fail git grep -P "a["
1028 test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
1029 test_must_fail git -c grep.patterntype=perl grep "a["
1032 test_expect_success 'grep -G -E -F pattern' '
1033 echo "ab:a+b*c" >expected &&
1034 git grep -G -E -F "a+b*c" ab >actual &&
1035 test_cmp expected actual
1038 test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' '
1039 echo "ab:a+b*c" >expected &&
1041 -c grep.patterntype=basic \
1042 -c grep.patterntype=extended \
1043 -c grep.patterntype=fixed \
1044 grep "a+b*c" ab >actual &&
1045 test_cmp expected actual
1048 test_expect_success 'grep -E -F -G pattern' '
1049 echo "ab:a+bc" >expected &&
1050 git grep -E -F -G "a+b*c" ab >actual &&
1051 test_cmp expected actual
1054 test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' '
1055 echo "ab:a+bc" >expected &&
1057 -c grep.patterntype=extended \
1058 -c grep.patterntype=fixed \
1059 -c grep.patterntype=basic \
1060 grep "a+b*c" ab >actual &&
1061 test_cmp expected actual
1064 test_expect_success 'grep -F -G -E pattern' '
1065 echo "ab:abc" >expected &&
1066 git grep -F -G -E "a+b*c" ab >actual &&
1067 test_cmp expected actual
1070 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' '
1071 echo "ab:abc" >expected &&
1073 -c grep.patterntype=fixed \
1074 -c grep.patterntype=basic \
1075 -c grep.patterntype=extended \
1076 grep "a+b*c" ab >actual &&
1077 test_cmp expected actual
1080 test_expect_success 'grep -G -F -P -E pattern' '
1082 test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
1083 test_cmp empty actual
1086 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
1088 test_must_fail git \
1089 -c grep.patterntype=fixed \
1090 -c grep.patterntype=basic \
1091 -c grep.patterntype=perl \
1092 -c grep.patterntype=extended \
1093 grep "a\x{2b}b\x{2a}c" ab >actual &&
1094 test_cmp empty actual
1097 test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
1098 echo "ab:a+b*c" >expected &&
1099 git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
1100 test_cmp expected actual
1103 test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
1104 echo "ab:a+b*c" >expected &&
1106 -c grep.patterntype=fixed \
1107 -c grep.patterntype=basic \
1108 -c grep.patterntype=extended \
1109 -c grep.patterntype=perl \
1110 grep "a\x{2b}b\x{2a}c" ab >actual &&
1111 test_cmp expected actual
1114 test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
1115 echo "ab:a+b*c" >expected &&
1117 -c grep.patterntype=fixed \
1118 grep -P "a\x{2b}b\x{2a}c" ab >actual &&
1119 test_cmp expected actual
1122 test_expect_success 'grep -F pattern with grep.patternType=basic' '
1123 echo "ab:a+b*c" >expected &&
1125 -c grep.patterntype=basic \
1126 grep -F "*c" ab >actual &&
1127 test_cmp expected actual
1130 test_expect_success 'grep -G pattern with grep.patternType=fixed' '
1136 -c grep.patterntype=fixed \
1137 grep -G "a+b" ab >actual &&
1138 test_cmp expected actual
1141 test_expect_success 'grep -E pattern with grep.patternType=fixed' '
1148 -c grep.patterntype=fixed \
1149 grep -E "a+" ab >actual &&
1150 test_cmp expected actual
1154 hello.c<RED>:<RESET>int main(int argc, const char **argv)
1155 hello.c<RED>-<RESET>{
1157 hello.c<RED>:<RESET> /* char ?? */
1158 hello.c<RED>-<RESET>}
1160 hello_world<RED>:<RESET>Hello_world
1161 hello_world<RED>-<RESET>HeLLo_world
1164 test_expect_success 'grep --color, separator' '
1165 test_config color.grep.context normal &&
1166 test_config color.grep.filename normal &&
1167 test_config color.grep.function normal &&
1168 test_config color.grep.linenumber normal &&
1169 test_config color.grep.match normal &&
1170 test_config color.grep.selected normal &&
1171 test_config color.grep.separator red &&
1173 git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
1174 test_decode_color >actual &&
1175 test_cmp expected actual
1179 hello.c:int main(int argc, const char **argv)
1180 hello.c: /* char ?? */
1182 hello_world:Hello_world
1185 test_expect_success 'grep --break' '
1186 git grep --break -e char -e lo_w hello.c hello_world >actual &&
1187 test_cmp expected actual
1191 hello.c:int main(int argc, const char **argv)
1194 hello.c: /* char ?? */
1197 hello_world:Hello_world
1198 hello_world-HeLLo_world
1201 test_expect_success 'grep --break with context' '
1202 git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
1203 test_cmp expected actual
1208 int main(int argc, const char **argv)
1214 test_expect_success 'grep --heading' '
1215 git grep --heading -e char -e lo_w hello.c hello_world >actual &&
1216 test_cmp expected actual
1220 <BOLD;GREEN>hello.c<RESET>
1221 4:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1222 8: /* <BLACK;BYELLOW>char<RESET> ?? */
1224 <BOLD;GREEN>hello_world<RESET>
1225 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
1228 test_expect_success 'mimic ack-grep --group' '
1229 test_config color.grep.context normal &&
1230 test_config color.grep.filename "bold green" &&
1231 test_config color.grep.function normal &&
1232 test_config color.grep.linenumber normal &&
1233 test_config color.grep.match "black yellow" &&
1234 test_config color.grep.selected normal &&
1235 test_config color.grep.separator normal &&
1237 git grep --break --heading -n --color \
1238 -e char -e lo_w hello.c hello_world |
1239 test_decode_color >actual &&
1240 test_cmp expected actual
1244 space: line with leading space1
1245 space: line with leading space2
1246 space: line with leading space3
1249 test_expect_success LIBPCRE 'grep -E "^ "' '
1250 git grep -E "^ " space >actual &&
1251 test_cmp expected actual
1254 test_expect_success LIBPCRE 'grep -P "^ "' '
1255 git grep -P "^ " space >actual &&
1256 test_cmp expected actual
1260 space-line without leading space1
1261 space: line <RED>with <RESET>leading space1
1262 space: line <RED>with <RESET>leading <RED>space2<RESET>
1263 space: line <RED>with <RESET>leading space3
1264 space:line without leading <RED>space2<RESET>
1267 test_expect_success 'grep --color -e A -e B with context' '
1268 test_config color.grep.context normal &&
1269 test_config color.grep.filename normal &&
1270 test_config color.grep.function normal &&
1271 test_config color.grep.linenumber normal &&
1272 test_config color.grep.matchContext normal &&
1273 test_config color.grep.matchSelected red &&
1274 test_config color.grep.selected normal &&
1275 test_config color.grep.separator normal &&
1277 git grep --color=always -C2 -e "with " -e space2 space |
1278 test_decode_color >actual &&
1279 test_cmp expected actual
1283 space-line without leading space1
1284 space- line with leading space1
1285 space: line <RED>with <RESET>leading <RED>space2<RESET>
1286 space- line with leading space3
1287 space-line without leading space2
1290 test_expect_success 'grep --color -e A --and -e B with context' '
1291 test_config color.grep.context normal &&
1292 test_config color.grep.filename normal &&
1293 test_config color.grep.function normal &&
1294 test_config color.grep.linenumber normal &&
1295 test_config color.grep.matchContext normal &&
1296 test_config color.grep.matchSelected red &&
1297 test_config color.grep.selected normal &&
1298 test_config color.grep.separator normal &&
1300 git grep --color=always -C2 -e "with " --and -e space2 space |
1301 test_decode_color >actual &&
1302 test_cmp expected actual
1306 space-line without leading space1
1307 space: line <RED>with <RESET>leading space1
1308 space- line with leading space2
1309 space: line <RED>with <RESET>leading space3
1310 space-line without leading space2
1313 test_expect_success 'grep --color -e A --and --not -e B with context' '
1314 test_config color.grep.context normal &&
1315 test_config color.grep.filename normal &&
1316 test_config color.grep.function normal &&
1317 test_config color.grep.linenumber normal &&
1318 test_config color.grep.matchContext normal &&
1319 test_config color.grep.matchSelected red &&
1320 test_config color.grep.selected normal &&
1321 test_config color.grep.separator normal &&
1323 git grep --color=always -C2 -e "with " --and --not -e space2 space |
1324 test_decode_color >actual &&
1325 test_cmp expected actual
1330 hello.c=int main(int argc, const char **argv)
1332 hello.c: pr<RED>int<RESET>f("<RED>Hello<RESET> world.\n");
1334 hello.c- /* char ?? */
1338 test_expect_success 'grep --color -e A --and -e B -p with context' '
1339 test_config color.grep.context normal &&
1340 test_config color.grep.filename normal &&
1341 test_config color.grep.function normal &&
1342 test_config color.grep.linenumber normal &&
1343 test_config color.grep.matchContext normal &&
1344 test_config color.grep.matchSelected red &&
1345 test_config color.grep.selected normal &&
1346 test_config color.grep.separator normal &&
1348 git grep --color=always -p -C3 -e int --and -e Hello --no-index hello.c |
1349 test_decode_color >actual &&
1350 test_cmp expected actual