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" >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 "ab:a+bc" >expected &&
244 git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
245 test_cmp expected actual
248 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 &&
251 test_cmp expected actual
254 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 &&
257 test_cmp expected actual
260 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 &&
263 test_cmp expected actual
266 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 &&
269 test_cmp expected actual
272 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 &&
275 test_cmp expected actual
278 test_expect_success
"grep $L with grep.patternType=default and grep.extendedRegexp=true" '
279 echo "ab:abc" >expected &&
281 -c grep.patternType=default \
282 -c grep.extendedRegexp=true \
283 grep "a+b*c" ab >actual &&
284 test_cmp expected actual
287 test_expect_success
"grep $L with grep.extendedRegexp=true and grep.patternType=default" '
288 echo "ab:abc" >expected &&
290 -c grep.extendedRegexp=true \
291 -c grep.patternType=default \
292 grep "a+b*c" ab >actual &&
293 test_cmp expected actual
296 test_expect_success
'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
297 echo "ab:abc" >expected &&
299 -c grep.patternType=extended \
300 -c grep.extendedRegexp=false \
301 grep "a+b*c" ab >actual &&
302 test_cmp expected actual
305 test_expect_success
'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
306 echo "ab:a+bc" >expected &&
308 -c grep.patternType=basic \
309 -c grep.extendedRegexp=true \
310 grep "a+b*c" ab >actual &&
311 test_cmp expected actual
314 test_expect_success
'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
315 echo "ab:abc" >expected &&
317 -c grep.extendedRegexp=false \
318 -c grep.patternType=extended \
319 grep "a+b*c" ab >actual &&
320 test_cmp expected actual
323 test_expect_success
'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
324 echo "ab:a+bc" >expected &&
326 -c grep.extendedRegexp=true \
327 -c grep.patternType=basic \
328 grep "a+b*c" ab >actual &&
329 test_cmp expected actual
336 test_expect_success
'grep -l -C' '
337 git grep -l -C1 foo >actual &&
338 test_cmp expected actual
344 test_expect_success
'grep -l -C' '
345 git grep -c -C1 foo >actual &&
346 test_cmp expected actual
349 test_expect_success
'grep -L -C' '
350 git ls-files >expected &&
351 git grep -L -C1 nonexistent_string >actual &&
352 test_cmp expected actual
356 file:foo mmap bar_mmap
359 test_expect_success
'grep -e A --and -e B' '
360 git grep -e "foo mmap" --and -e bar_mmap >actual &&
361 test_cmp expected actual
365 file:foo_mmap bar mmap
366 file:foo_mmap bar mmap baz
370 test_expect_success
'grep ( -e A --or -e B ) --and -e B' '
371 git grep \( -e foo_ --or -e baz \) \
372 --and -e " mmap" >actual &&
373 test_cmp expected actual
380 test_expect_success
'grep -e A --and --not -e B' '
381 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
382 test_cmp expected actual
385 test_expect_success
'grep should ignore GREP_OPTIONS' '
386 GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
387 test_cmp expected actual
390 test_expect_success
'grep -f, non-existent file' '
391 test_must_fail git grep -f patterns
397 file:foo_mmap bar mmap
398 file:foo mmap bar_mmap
399 file:foo_mmap bar mmap baz
406 test_expect_success
'grep -f, one pattern' '
407 git grep -f pattern >actual &&
408 test_cmp expected actual
414 file:foo_mmap bar mmap
415 file:foo mmap bar_mmap
416 file:foo_mmap bar mmap baz
427 test_expect_success
'grep -f, multiple patterns' '
428 git grep -f patterns >actual &&
429 test_cmp expected actual
432 test_expect_success
'grep, multiple patterns' '
433 git grep "$(cat patterns)" >actual &&
434 test_cmp expected actual
440 file:foo_mmap bar mmap
441 file:foo mmap bar_mmap
442 file:foo_mmap bar mmap baz
456 test_expect_success
'grep -f, ignore empty lines' '
457 git grep -f patterns >actual &&
458 test_cmp expected actual
461 test_expect_success
'grep -f, ignore empty lines, read patterns from stdin' '
462 git grep -f - <patterns >actual &&
463 test_cmp expected actual
472 test_expect_success
'grep -q, silently report matches' '
474 git grep -q mmap >actual &&
475 test_cmp empty actual &&
476 test_must_fail git grep -q qfwfq >actual &&
477 test_cmp empty actual
480 test_expect_success
'grep -C1 hunk mark between files' '
481 git grep -C1 "^[yz]" >actual &&
482 test_cmp expected actual
485 test_expect_success
'log grep setup' '
488 GIT_AUTHOR_NAME="With * Asterisk" \
489 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
490 git commit -a -m "second" &&
494 git commit -a -m "third" &&
498 GIT_AUTHOR_NAME="Night Fall" \
499 GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \
500 git commit -a -m "fourth"
503 test_expect_success
'log grep (1)' '
504 git log --author=author --pretty=tformat:%s >actual &&
506 echo third && echo initial
508 test_cmp expect actual
511 test_expect_success
'log grep (2)' '
512 git log --author=" * " -F --pretty=tformat:%s >actual &&
516 test_cmp expect actual
519 test_expect_success
'log grep (3)' '
520 git log --author="^A U" --pretty=tformat:%s >actual &&
522 echo third && echo initial
524 test_cmp expect actual
527 test_expect_success
'log grep (4)' '
528 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
532 test_cmp expect actual
535 test_expect_success
'log grep (5)' '
536 git log --author=Thor -F --pretty=tformat:%s >actual &&
538 echo third && echo initial
540 test_cmp expect actual
543 test_expect_success
'log grep (6)' '
544 git log --author=-0700 --pretty=tformat:%s >actual &&
546 test_cmp expect actual
549 test_expect_success
'log --grep --author implicitly uses all-match' '
550 # grep matches initial and second but not third
551 # author matches only initial and third
552 git log --author="A U Thor" --grep=s --grep=l --format=%s >actual &&
556 test_cmp expect actual
559 test_expect_success
'log with multiple --author uses union' '
560 git log --author="Thor" --author="Aster" --format=%s >actual &&
562 echo third && echo second && echo initial
564 test_cmp expect actual
567 test_expect_success
'log with --grep and multiple --author uses all-match' '
568 git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
570 echo third && echo initial
572 test_cmp expect actual
575 test_expect_success
'log with --grep and multiple --author uses all-match' '
576 git log --author="Thor" --author="Night" --grep=q --format=%s >actual &&
578 test_cmp expect actual
581 test_expect_success
'grep with CE_VALID file' '
582 git update-index --assume-unchanged t/t &&
584 test "$(git grep test)" = "t/t:test" &&
585 git update-index --no-assume-unchanged t/t &&
590 hello.c=#include <stdio.h>
594 test_expect_success
'grep -p with userdiff' '
595 git config diff.custom.funcname "^#" &&
596 echo "hello.c diff=custom" >.gitattributes &&
597 git grep -p return >actual &&
598 test_cmp expected actual
602 hello.c=int main(int argc, const char **argv)
606 test_expect_success
'grep -p' '
607 rm -f .gitattributes &&
608 git grep -p return >actual &&
609 test_cmp expected actual
613 hello.c-#include <stdio.h>
614 hello.c=int main(int argc, const char **argv)
616 hello.c- printf("Hello world.\n");
620 test_expect_success
'grep -p -B5' '
621 git grep -p -B5 return >actual &&
622 test_cmp expected actual
626 hello.c=int main(int argc, const char **argv)
628 hello.c- printf("Hello world.\n");
630 hello.c- /* char ?? */
634 test_expect_success
'grep -W' '
635 git grep -W return >actual &&
636 test_cmp expected actual
640 hello.c= printf("Hello world.\n");
642 hello.c- /* char ?? */
645 test_expect_success
'grep -W with userdiff' '
646 test_when_finished "rm -f .gitattributes" &&
647 git config diff.custom.xfuncname "(printf.*|})$" &&
648 echo "hello.c diff=custom" >.gitattributes &&
649 git grep -W return >actual &&
650 test_cmp expected actual
653 test_expect_success
'grep from a subdirectory to search wider area (1)' '
656 cd s && git grep "x x x" ..
660 test_expect_success
'grep from a subdirectory to search wider area (2)' '
664 ( git grep xxyyzz .. >out ; echo $? >status )
666 test 1 = $(cat status)
671 hello.c:int main(int argc, const char **argv)
674 test_expect_success
'grep -Fi' '
675 git grep -Fi "CHAR *" >actual &&
676 test_cmp expected actual
679 test_expect_success
'outside of git repository' '
681 mkdir -p non/git/sub &&
682 echo hello >non/git/file1 &&
683 echo world >non/git/sub/file2 &&
687 } >non/expect.full &&
688 echo file2:world >non/expect.sub &&
690 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
691 export GIT_CEILING_DIRECTORIES &&
693 test_must_fail git grep o &&
694 git grep --no-index o >../actual.full &&
695 test_cmp ../expect.full ../actual.full
697 test_must_fail git grep o &&
698 git grep --no-index o >../../actual.sub &&
699 test_cmp ../../expect.sub ../../actual.sub
702 echo ".*o*" >non/git/.gitignore &&
704 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
705 export GIT_CEILING_DIRECTORIES &&
707 test_must_fail git grep o &&
708 git grep --no-index --exclude-standard o >../actual.full &&
709 test_cmp ../expect.full ../actual.full &&
712 echo ".gitignore:.*o*"
714 } >../expect.with.ignored &&
715 git grep --no-index --no-exclude o >../actual.full &&
716 test_cmp ../expect.with.ignored ../actual.full
720 test_expect_success
'inside git repository but with --no-index' '
722 mkdir -p is/git/sub &&
723 echo hello >is/git/file1 &&
724 echo world >is/git/sub/file2 &&
725 echo ".*o*" >is/git/.gitignore &&
729 } >is/expect.unignored &&
731 echo ".gitignore:.*o*" &&
732 cat is/expect.unignored
734 : >is/expect.empty &&
735 echo file2:world >is/expect.sub &&
739 test_must_fail git grep o >../actual.full &&
740 test_cmp ../expect.empty ../actual.full &&
742 git grep --untracked o >../actual.unignored &&
743 test_cmp ../expect.unignored ../actual.unignored &&
745 git grep --no-index o >../actual.full &&
746 test_cmp ../expect.full ../actual.full &&
748 git grep --no-index --exclude-standard o >../actual.unignored &&
749 test_cmp ../expect.unignored ../actual.unignored &&
752 test_must_fail git grep o >../../actual.sub &&
753 test_cmp ../../expect.empty ../../actual.sub &&
755 git grep --no-index o >../../actual.sub &&
756 test_cmp ../../expect.sub ../../actual.sub &&
758 git grep --untracked o >../../actual.sub &&
759 test_cmp ../../expect.sub ../../actual.sub
763 test_expect_success
'setup double-dash tests' '
764 cat >double-dash <<EOF &&
775 test_expect_success
'grep -- pattern' '
776 git grep -- "->" >actual &&
777 test_cmp expected actual
779 test_expect_success
'grep -- pattern -- pathspec' '
780 git grep -- "->" -- double-dash >actual &&
781 test_cmp expected actual
783 test_expect_success
'grep -e pattern -- path' '
784 git grep -e "->" -- double-dash >actual &&
785 test_cmp expected actual
791 test_expect_success
'grep -e -- -- path' '
792 git grep -e -- -- double-dash >actual &&
793 test_cmp expected actual
797 hello.c:int main(int argc, const char **argv)
798 hello.c: printf("Hello world.\n");
801 test_expect_success LIBPCRE
'grep --perl-regexp pattern' '
802 git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
803 test_cmp expected actual
806 test_expect_success LIBPCRE
'grep -P pattern' '
807 git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
808 test_cmp expected actual
811 test_expect_success
'grep pattern with grep.extendedRegexp=true' '
813 test_must_fail git -c grep.extendedregexp=true \
814 grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
815 test_cmp empty actual
818 test_expect_success LIBPCRE
'grep -P pattern with grep.extendedRegexp=true' '
819 git -c grep.extendedregexp=true \
820 grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
821 test_cmp expected actual
824 test_expect_success LIBPCRE
'grep -P -v pattern' '
829 git grep -P -v "abc" ab >actual &&
830 test_cmp expected actual
833 test_expect_success LIBPCRE
'grep -P -i pattern' '
834 cat >expected <<-EOF &&
835 hello.c: printf("Hello world.\n");
837 git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
838 test_cmp expected actual
841 test_expect_success LIBPCRE
'grep -P -w pattern' '
843 echo "hello_world:Hello world"
844 echo "hello_world:HeLLo world"
846 git grep -P -w "He((?i)ll)o" hello_world >actual &&
847 test_cmp expected actual
850 test_expect_success
'grep -G invalidpattern properly dies ' '
851 test_must_fail git grep -G "a["
854 test_expect_success
'grep invalidpattern properly dies with grep.patternType=basic' '
855 test_must_fail git -c grep.patterntype=basic grep "a["
858 test_expect_success
'grep -E invalidpattern properly dies ' '
859 test_must_fail git grep -E "a["
862 test_expect_success
'grep invalidpattern properly dies with grep.patternType=extended' '
863 test_must_fail git -c grep.patterntype=extended grep "a["
866 test_expect_success LIBPCRE
'grep -P invalidpattern properly dies ' '
867 test_must_fail git grep -P "a["
870 test_expect_success LIBPCRE
'grep invalidpattern properly dies with grep.patternType=perl' '
871 test_must_fail git -c grep.patterntype=perl grep "a["
874 test_expect_success
'grep -G -E -F pattern' '
875 echo "ab:a+b*c" >expected &&
876 git grep -G -E -F "a+b*c" ab >actual &&
877 test_cmp expected actual
880 test_expect_success
'grep pattern with grep.patternType=basic, =extended, =fixed' '
881 echo "ab:a+b*c" >expected &&
883 -c grep.patterntype=basic \
884 -c grep.patterntype=extended \
885 -c grep.patterntype=fixed \
886 grep "a+b*c" ab >actual &&
887 test_cmp expected actual
890 test_expect_success
'grep -E -F -G pattern' '
891 echo "ab:a+bc" >expected &&
892 git grep -E -F -G "a+b*c" ab >actual &&
893 test_cmp expected actual
896 test_expect_success
'grep pattern with grep.patternType=extended, =fixed, =basic' '
897 echo "ab:a+bc" >expected &&
899 -c grep.patterntype=extended \
900 -c grep.patterntype=fixed \
901 -c grep.patterntype=basic \
902 grep "a+b*c" ab >actual &&
903 test_cmp expected actual
906 test_expect_success
'grep -F -G -E pattern' '
907 echo "ab:abc" >expected &&
908 git grep -F -G -E "a+b*c" ab >actual &&
909 test_cmp expected actual
912 test_expect_success
'grep pattern with grep.patternType=fixed, =basic, =extended' '
913 echo "ab:abc" >expected &&
915 -c grep.patterntype=fixed \
916 -c grep.patterntype=basic \
917 -c grep.patterntype=extended \
918 grep "a+b*c" ab >actual &&
919 test_cmp expected actual
922 test_expect_success
'grep -G -F -P -E pattern' '
924 test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
925 test_cmp empty actual
928 test_expect_success
'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
931 -c grep.patterntype=fixed \
932 -c grep.patterntype=basic \
933 -c grep.patterntype=perl \
934 -c grep.patterntype=extended \
935 grep "a\x{2b}b\x{2a}c" ab >actual &&
936 test_cmp empty actual
939 test_expect_success LIBPCRE
'grep -G -F -E -P pattern' '
940 echo "ab:a+b*c" >expected &&
941 git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
942 test_cmp expected actual
945 test_expect_success LIBPCRE
'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
946 echo "ab:a+b*c" >expected &&
948 -c grep.patterntype=fixed \
949 -c grep.patterntype=basic \
950 -c grep.patterntype=extended \
951 -c grep.patterntype=perl \
952 grep "a\x{2b}b\x{2a}c" ab >actual &&
953 test_cmp expected actual
956 test_expect_success LIBPCRE
'grep -P pattern with grep.patternType=fixed' '
957 echo "ab:a+b*c" >expected &&
959 -c grep.patterntype=fixed \
960 grep -P "a\x{2b}b\x{2a}c" ab >actual &&
961 test_cmp expected actual
964 test_expect_success
'grep -F pattern with grep.patternType=basic' '
965 echo "ab:a+b*c" >expected &&
967 -c grep.patterntype=basic \
968 grep -F "*c" ab >actual &&
969 test_cmp expected actual
972 test_expect_success
'grep -G pattern with grep.patternType=fixed' '
978 -c grep.patterntype=fixed \
979 grep -G "a+b" ab >actual &&
980 test_cmp expected actual
983 test_expect_success
'grep -E pattern with grep.patternType=fixed' '
990 -c grep.patterntype=fixed \
991 grep -E "a+" ab >actual &&
992 test_cmp expected actual
996 git config
"$1" "$2" &&
997 test_when_finished
"git config --unset $1"
1001 hello.c<RED>:<RESET>int main(int argc, const char **argv)
1002 hello.c<RED>-<RESET>{
1004 hello.c<RED>:<RESET> /* char ?? */
1005 hello.c<RED>-<RESET>}
1007 hello_world<RED>:<RESET>Hello_world
1008 hello_world<RED>-<RESET>HeLLo_world
1011 test_expect_success
'grep --color, separator' '
1012 test_config color.grep.context normal &&
1013 test_config color.grep.filename normal &&
1014 test_config color.grep.function normal &&
1015 test_config color.grep.linenumber normal &&
1016 test_config color.grep.match normal &&
1017 test_config color.grep.selected normal &&
1018 test_config color.grep.separator red &&
1020 git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
1021 test_decode_color >actual &&
1022 test_cmp expected actual
1026 hello.c:int main(int argc, const char **argv)
1027 hello.c: /* char ?? */
1029 hello_world:Hello_world
1032 test_expect_success
'grep --break' '
1033 git grep --break -e char -e lo_w hello.c hello_world >actual &&
1034 test_cmp expected actual
1038 hello.c:int main(int argc, const char **argv)
1041 hello.c: /* char ?? */
1044 hello_world:Hello_world
1045 hello_world-HeLLo_world
1048 test_expect_success
'grep --break with context' '
1049 git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
1050 test_cmp expected actual
1055 int main(int argc, const char **argv)
1061 test_expect_success
'grep --heading' '
1062 git grep --heading -e char -e lo_w hello.c hello_world >actual &&
1063 test_cmp expected actual
1067 <BOLD;GREEN>hello.c<RESET>
1068 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1069 6: /* <BLACK;BYELLOW>char<RESET> ?? */
1071 <BOLD;GREEN>hello_world<RESET>
1072 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
1075 test_expect_success
'mimic ack-grep --group' '
1076 test_config color.grep.context normal &&
1077 test_config color.grep.filename "bold green" &&
1078 test_config color.grep.function normal &&
1079 test_config color.grep.linenumber normal &&
1080 test_config color.grep.match "black yellow" &&
1081 test_config color.grep.selected normal &&
1082 test_config color.grep.separator normal &&
1084 git grep --break --heading -n --color \
1085 -e char -e lo_w hello.c hello_world |
1086 test_decode_color >actual &&
1087 test_cmp expected actual
1091 space: line with leading space1
1092 space: line with leading space2
1093 space: line with leading space3
1096 test_expect_success LIBPCRE
'grep -E "^ "' '
1097 git grep -E "^ " space >actual &&
1098 test_cmp expected actual
1101 test_expect_success LIBPCRE
'grep -P "^ "' '
1102 git grep -P "^ " space >actual &&
1103 test_cmp expected actual