t7810-grep: test multiple --author with --all-match
[git/mjg.git] / t / t7810-grep.sh
blob9bc63a3c2d5fd78ae5f66ea932528f8c213c956a
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
9 . ./test-lib.sh
11 cat >hello.c <<EOF
12 #include <stdio.h>
13 int main(int argc, const char **argv)
15 printf("Hello world.\n");
16 return 0;
17 /* char ?? */
19 EOF
21 test_expect_success setup '
23 echo foo mmap bar
24 echo foo_mmap bar
25 echo foo_mmap bar mmap
26 echo foo mmap bar_mmap
27 echo foo_mmap bar mmap baz
28 } >file &&
30 echo Hello world
31 echo HeLLo world
32 echo Hello_world
33 echo HeLLo_world
34 } >hello_world &&
36 echo "a+b*c"
37 echo "a+bc"
38 echo "abc"
39 } >ab &&
40 echo vvv >v &&
41 echo ww w >w &&
42 echo x x xx x >x &&
43 echo y yy >y &&
44 echo zzz > z &&
45 mkdir t &&
46 echo test >t/t &&
47 echo vvv >t/v &&
48 mkdir t/a &&
49 echo vvv >t/a/v &&
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"
56 } >space &&
57 git add . &&
58 test_tick &&
59 git commit -m initial
62 test_expect_success 'grep should not segfault with a bad input' '
63 test_must_fail git grep "("
66 for H in HEAD ''
68 case "$H" in
69 HEAD) HC='HEAD:' L='HEAD' ;;
70 '') HC= L='in working tree' ;;
71 esac
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
79 } >expected &&
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
90 } >expected &&
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
101 } >expected &&
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)" '
107 : >expected &&
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
115 } >expected &&
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)" '
122 echo ${HC}y:1:y yy
123 } >expected &&
124 git grep -n -w -e "^y" $H >actual &&
125 test_cmp expected actual
128 test_expect_success "grep -w $L (y-2)" '
129 : >expected &&
130 if git grep -n -w -e "^y y" $H >actual
131 then
132 echo should not have matched
133 cat actual
134 false
135 else
136 test_cmp expected actual
140 test_expect_success "grep -w $L (z)" '
141 : >expected &&
142 if git grep -n -w -e "^z" $H >actual
143 then
144 echo should not have matched
145 cat actual
146 false
147 else
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 &&
161 cd t &&
162 git grep -n -e test $H
163 ) >actual &&
164 test_cmp expected actual
167 test_expect_success "grep $L (t-3)" '
168 echo "${HC}t/t:1:test" >expected &&
170 cd t &&
171 git grep --full-name -n -e test $H
172 ) >actual &&
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
183 echo ${HC}t/v:1:vvv
184 echo ${HC}v:1:vvv
185 } >expected &&
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" '
192 echo ${HC}v:1:vvv
193 } >expected &&
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
201 echo ${HC}t/v:1:vvv
202 echo ${HC}v:1:vvv
203 } >expected &&
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" '
210 echo ${HC}t/v:1:vvv
211 echo ${HC}v:1:vvv
212 } >expected &&
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" '
219 echo ${HC}t/v:1:vvv
220 } >expected &&
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" '
227 echo ${HC}t/v:1:vvv
228 echo ${HC}v:1:vvv
229 } >expected &&
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" '
236 echo ${HC}t/v:1:vvv
237 echo ${HC}v:1:vvv
238 } >expected &&
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 &&
280 git \
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 &&
289 git \
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 &&
298 git \
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 &&
307 git \
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 &&
316 git \
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 &&
325 git \
326 -c grep.extendedRegexp=true \
327 -c grep.patternType=basic \
328 grep "a+b*c" ab >actual &&
329 test_cmp expected actual
331 done
333 cat >expected <<EOF
334 file
336 test_expect_success 'grep -l -C' '
337 git grep -l -C1 foo >actual &&
338 test_cmp expected actual
341 cat >expected <<EOF
342 file:5
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
355 cat >expected <<EOF
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
364 cat >expected <<EOF
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
376 cat >expected <<EOF
377 file:foo mmap bar
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
394 cat >expected <<EOF
395 file:foo mmap bar
396 file:foo_mmap bar
397 file:foo_mmap bar mmap
398 file:foo mmap bar_mmap
399 file:foo_mmap bar mmap baz
402 cat >pattern <<EOF
403 mmap
406 test_expect_success 'grep -f, one pattern' '
407 git grep -f pattern >actual &&
408 test_cmp expected actual
411 cat >expected <<EOF
412 file:foo mmap bar
413 file:foo_mmap bar
414 file:foo_mmap bar mmap
415 file:foo mmap bar_mmap
416 file:foo_mmap bar mmap baz
417 t/a/v:vvv
418 t/v:vvv
419 v:vvv
422 cat >patterns <<EOF
423 mmap
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
437 cat >expected <<EOF
438 file:foo mmap bar
439 file:foo_mmap bar
440 file:foo_mmap bar mmap
441 file:foo mmap bar_mmap
442 file:foo_mmap bar mmap baz
443 t/a/v:vvv
444 t/v:vvv
445 v:vvv
448 cat >patterns <<EOF
450 mmap
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
466 cat >expected <<EOF
467 y:y yy
469 z:zzz
472 test_expect_success 'grep -q, silently report matches' '
473 >empty &&
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' '
486 echo a >>file &&
487 test_tick &&
488 GIT_AUTHOR_NAME="With * Asterisk" \
489 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
490 git commit -a -m "second" &&
492 echo a >>file &&
493 test_tick &&
494 git commit -a -m "third" &&
496 echo a >>file &&
497 test_tick &&
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
507 } >expect &&
508 test_cmp expect actual
511 test_expect_success 'log grep (2)' '
512 git log --author=" * " -F --pretty=tformat:%s >actual &&
514 echo second
515 } >expect &&
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
523 } >expect &&
524 test_cmp expect actual
527 test_expect_success 'log grep (4)' '
528 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
530 echo second
531 } >expect &&
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
539 } >expect &&
540 test_cmp expect actual
543 test_expect_success 'log grep (6)' '
544 git log --author=-0700 --pretty=tformat:%s >actual &&
545 >expect &&
546 test_cmp expect actual
549 test_expect_success 'log with multiple --grep uses union' '
550 git log --grep=i --grep=r --format=%s >actual &&
552 echo fourth && echo third && echo initial
553 } >expect &&
554 test_cmp expect actual
557 test_expect_success 'log --all-match with multiple --grep uses intersection' '
558 git log --all-match --grep=i --grep=r --format=%s >actual &&
560 echo third
561 } >expect &&
562 test_cmp expect actual
565 test_expect_success 'log --grep --author implicitly uses all-match' '
566 # grep matches initial and second but not third
567 # author matches only initial and third
568 git log --author="A U Thor" --grep=s --grep=l --format=%s >actual &&
570 echo initial
571 } >expect &&
572 test_cmp expect actual
575 test_expect_success 'log with multiple --author uses union' '
576 git log --author="Thor" --author="Aster" --format=%s >actual &&
578 echo third && echo second && echo initial
579 } >expect &&
580 test_cmp expect actual
583 test_expect_success 'log --all-match with multiple --author still uses union' '
584 git log --all-match --author="Thor" --author="Aster" --format=%s >actual &&
586 echo third && echo second && echo initial
587 } >expect &&
588 test_cmp expect actual
591 test_expect_success 'log with --grep and multiple --author uses all-match' '
592 git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
594 echo third && echo initial
595 } >expect &&
596 test_cmp expect actual
599 test_expect_success 'log with --grep and multiple --author uses all-match' '
600 git log --author="Thor" --author="Night" --grep=q --format=%s >actual &&
601 >expect &&
602 test_cmp expect actual
605 test_expect_success 'grep with CE_VALID file' '
606 git update-index --assume-unchanged t/t &&
607 rm t/t &&
608 test "$(git grep test)" = "t/t:test" &&
609 git update-index --no-assume-unchanged t/t &&
610 git checkout t/t
613 cat >expected <<EOF
614 hello.c=#include <stdio.h>
615 hello.c: return 0;
618 test_expect_success 'grep -p with userdiff' '
619 git config diff.custom.funcname "^#" &&
620 echo "hello.c diff=custom" >.gitattributes &&
621 git grep -p return >actual &&
622 test_cmp expected actual
625 cat >expected <<EOF
626 hello.c=int main(int argc, const char **argv)
627 hello.c: return 0;
630 test_expect_success 'grep -p' '
631 rm -f .gitattributes &&
632 git grep -p return >actual &&
633 test_cmp expected actual
636 cat >expected <<EOF
637 hello.c-#include <stdio.h>
638 hello.c=int main(int argc, const char **argv)
639 hello.c-{
640 hello.c- printf("Hello world.\n");
641 hello.c: return 0;
644 test_expect_success 'grep -p -B5' '
645 git grep -p -B5 return >actual &&
646 test_cmp expected actual
649 cat >expected <<EOF
650 hello.c=int main(int argc, const char **argv)
651 hello.c-{
652 hello.c- printf("Hello world.\n");
653 hello.c: return 0;
654 hello.c- /* char ?? */
655 hello.c-}
658 test_expect_success 'grep -W' '
659 git grep -W return >actual &&
660 test_cmp expected actual
663 cat >expected <<EOF
664 hello.c= printf("Hello world.\n");
665 hello.c: return 0;
666 hello.c- /* char ?? */
669 test_expect_success 'grep -W with userdiff' '
670 test_when_finished "rm -f .gitattributes" &&
671 git config diff.custom.xfuncname "(printf.*|})$" &&
672 echo "hello.c diff=custom" >.gitattributes &&
673 git grep -W return >actual &&
674 test_cmp expected actual
677 test_expect_success 'grep from a subdirectory to search wider area (1)' '
678 mkdir -p s &&
680 cd s && git grep "x x x" ..
684 test_expect_success 'grep from a subdirectory to search wider area (2)' '
685 mkdir -p s &&
687 cd s || exit 1
688 ( git grep xxyyzz .. >out ; echo $? >status )
689 ! test -s out &&
690 test 1 = $(cat status)
694 cat >expected <<EOF
695 hello.c:int main(int argc, const char **argv)
698 test_expect_success 'grep -Fi' '
699 git grep -Fi "CHAR *" >actual &&
700 test_cmp expected actual
703 test_expect_success 'outside of git repository' '
704 rm -fr non &&
705 mkdir -p non/git/sub &&
706 echo hello >non/git/file1 &&
707 echo world >non/git/sub/file2 &&
709 echo file1:hello &&
710 echo sub/file2:world
711 } >non/expect.full &&
712 echo file2:world >non/expect.sub &&
714 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
715 export GIT_CEILING_DIRECTORIES &&
716 cd non/git &&
717 test_must_fail git grep o &&
718 git grep --no-index o >../actual.full &&
719 test_cmp ../expect.full ../actual.full
720 cd sub &&
721 test_must_fail git grep o &&
722 git grep --no-index o >../../actual.sub &&
723 test_cmp ../../expect.sub ../../actual.sub
724 ) &&
726 echo ".*o*" >non/git/.gitignore &&
728 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
729 export GIT_CEILING_DIRECTORIES &&
730 cd non/git &&
731 test_must_fail git grep o &&
732 git grep --no-index --exclude-standard o >../actual.full &&
733 test_cmp ../expect.full ../actual.full &&
736 echo ".gitignore:.*o*"
737 cat ../expect.full
738 } >../expect.with.ignored &&
739 git grep --no-index --no-exclude o >../actual.full &&
740 test_cmp ../expect.with.ignored ../actual.full
744 test_expect_success 'inside git repository but with --no-index' '
745 rm -fr is &&
746 mkdir -p is/git/sub &&
747 echo hello >is/git/file1 &&
748 echo world >is/git/sub/file2 &&
749 echo ".*o*" >is/git/.gitignore &&
751 echo file1:hello &&
752 echo sub/file2:world
753 } >is/expect.unignored &&
755 echo ".gitignore:.*o*" &&
756 cat is/expect.unignored
757 } >is/expect.full &&
758 : >is/expect.empty &&
759 echo file2:world >is/expect.sub &&
761 cd is/git &&
762 git init &&
763 test_must_fail git grep o >../actual.full &&
764 test_cmp ../expect.empty ../actual.full &&
766 git grep --untracked o >../actual.unignored &&
767 test_cmp ../expect.unignored ../actual.unignored &&
769 git grep --no-index o >../actual.full &&
770 test_cmp ../expect.full ../actual.full &&
772 git grep --no-index --exclude-standard o >../actual.unignored &&
773 test_cmp ../expect.unignored ../actual.unignored &&
775 cd sub &&
776 test_must_fail git grep o >../../actual.sub &&
777 test_cmp ../../expect.empty ../../actual.sub &&
779 git grep --no-index o >../../actual.sub &&
780 test_cmp ../../expect.sub ../../actual.sub &&
782 git grep --untracked o >../../actual.sub &&
783 test_cmp ../../expect.sub ../../actual.sub
787 test_expect_success 'setup double-dash tests' '
788 cat >double-dash <<EOF &&
791 other
793 git add double-dash
796 cat >expected <<EOF
797 double-dash:->
799 test_expect_success 'grep -- pattern' '
800 git grep -- "->" >actual &&
801 test_cmp expected actual
803 test_expect_success 'grep -- pattern -- pathspec' '
804 git grep -- "->" -- double-dash >actual &&
805 test_cmp expected actual
807 test_expect_success 'grep -e pattern -- path' '
808 git grep -e "->" -- double-dash >actual &&
809 test_cmp expected actual
812 cat >expected <<EOF
813 double-dash:--
815 test_expect_success 'grep -e -- -- path' '
816 git grep -e -- -- double-dash >actual &&
817 test_cmp expected actual
820 cat >expected <<EOF
821 hello.c:int main(int argc, const char **argv)
822 hello.c: printf("Hello world.\n");
825 test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
826 git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
827 test_cmp expected actual
830 test_expect_success LIBPCRE 'grep -P pattern' '
831 git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
832 test_cmp expected actual
835 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
836 >empty &&
837 test_must_fail git -c grep.extendedregexp=true \
838 grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
839 test_cmp empty actual
842 test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
843 git -c grep.extendedregexp=true \
844 grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
845 test_cmp expected actual
848 test_expect_success LIBPCRE 'grep -P -v pattern' '
850 echo "ab:a+b*c"
851 echo "ab:a+bc"
852 } >expected &&
853 git grep -P -v "abc" ab >actual &&
854 test_cmp expected actual
857 test_expect_success LIBPCRE 'grep -P -i pattern' '
858 cat >expected <<-EOF &&
859 hello.c: printf("Hello world.\n");
861 git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
862 test_cmp expected actual
865 test_expect_success LIBPCRE 'grep -P -w pattern' '
867 echo "hello_world:Hello world"
868 echo "hello_world:HeLLo world"
869 } >expected &&
870 git grep -P -w "He((?i)ll)o" hello_world >actual &&
871 test_cmp expected actual
874 test_expect_success 'grep -G invalidpattern properly dies ' '
875 test_must_fail git grep -G "a["
878 test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' '
879 test_must_fail git -c grep.patterntype=basic grep "a["
882 test_expect_success 'grep -E invalidpattern properly dies ' '
883 test_must_fail git grep -E "a["
886 test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' '
887 test_must_fail git -c grep.patterntype=extended grep "a["
890 test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
891 test_must_fail git grep -P "a["
894 test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
895 test_must_fail git -c grep.patterntype=perl grep "a["
898 test_expect_success 'grep -G -E -F pattern' '
899 echo "ab:a+b*c" >expected &&
900 git grep -G -E -F "a+b*c" ab >actual &&
901 test_cmp expected actual
904 test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' '
905 echo "ab:a+b*c" >expected &&
906 git \
907 -c grep.patterntype=basic \
908 -c grep.patterntype=extended \
909 -c grep.patterntype=fixed \
910 grep "a+b*c" ab >actual &&
911 test_cmp expected actual
914 test_expect_success 'grep -E -F -G pattern' '
915 echo "ab:a+bc" >expected &&
916 git grep -E -F -G "a+b*c" ab >actual &&
917 test_cmp expected actual
920 test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' '
921 echo "ab:a+bc" >expected &&
922 git \
923 -c grep.patterntype=extended \
924 -c grep.patterntype=fixed \
925 -c grep.patterntype=basic \
926 grep "a+b*c" ab >actual &&
927 test_cmp expected actual
930 test_expect_success 'grep -F -G -E pattern' '
931 echo "ab:abc" >expected &&
932 git grep -F -G -E "a+b*c" ab >actual &&
933 test_cmp expected actual
936 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' '
937 echo "ab:abc" >expected &&
938 git \
939 -c grep.patterntype=fixed \
940 -c grep.patterntype=basic \
941 -c grep.patterntype=extended \
942 grep "a+b*c" ab >actual &&
943 test_cmp expected actual
946 test_expect_success 'grep -G -F -P -E pattern' '
947 >empty &&
948 test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
949 test_cmp empty actual
952 test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
953 >empty &&
954 test_must_fail git \
955 -c grep.patterntype=fixed \
956 -c grep.patterntype=basic \
957 -c grep.patterntype=perl \
958 -c grep.patterntype=extended \
959 grep "a\x{2b}b\x{2a}c" ab >actual &&
960 test_cmp empty actual
963 test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
964 echo "ab:a+b*c" >expected &&
965 git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
966 test_cmp expected actual
969 test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
970 echo "ab:a+b*c" >expected &&
971 git \
972 -c grep.patterntype=fixed \
973 -c grep.patterntype=basic \
974 -c grep.patterntype=extended \
975 -c grep.patterntype=perl \
976 grep "a\x{2b}b\x{2a}c" ab >actual &&
977 test_cmp expected actual
980 test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
981 echo "ab:a+b*c" >expected &&
982 git \
983 -c grep.patterntype=fixed \
984 grep -P "a\x{2b}b\x{2a}c" ab >actual &&
985 test_cmp expected actual
988 test_expect_success 'grep -F pattern with grep.patternType=basic' '
989 echo "ab:a+b*c" >expected &&
990 git \
991 -c grep.patterntype=basic \
992 grep -F "*c" ab >actual &&
993 test_cmp expected actual
996 test_expect_success 'grep -G pattern with grep.patternType=fixed' '
998 echo "ab:a+b*c"
999 echo "ab:a+bc"
1000 } >expected &&
1001 git \
1002 -c grep.patterntype=fixed \
1003 grep -G "a+b" ab >actual &&
1004 test_cmp expected actual
1007 test_expect_success 'grep -E pattern with grep.patternType=fixed' '
1009 echo "ab:a+b*c"
1010 echo "ab:a+bc"
1011 echo "ab:abc"
1012 } >expected &&
1013 git \
1014 -c grep.patterntype=fixed \
1015 grep -E "a+" ab >actual &&
1016 test_cmp expected actual
1019 test_config() {
1020 git config "$1" "$2" &&
1021 test_when_finished "git config --unset $1"
1024 cat >expected <<EOF
1025 hello.c<RED>:<RESET>int main(int argc, const char **argv)
1026 hello.c<RED>-<RESET>{
1027 <RED>--<RESET>
1028 hello.c<RED>:<RESET> /* char ?? */
1029 hello.c<RED>-<RESET>}
1030 <RED>--<RESET>
1031 hello_world<RED>:<RESET>Hello_world
1032 hello_world<RED>-<RESET>HeLLo_world
1035 test_expect_success 'grep --color, separator' '
1036 test_config color.grep.context normal &&
1037 test_config color.grep.filename normal &&
1038 test_config color.grep.function normal &&
1039 test_config color.grep.linenumber normal &&
1040 test_config color.grep.match normal &&
1041 test_config color.grep.selected normal &&
1042 test_config color.grep.separator red &&
1044 git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
1045 test_decode_color >actual &&
1046 test_cmp expected actual
1049 cat >expected <<EOF
1050 hello.c:int main(int argc, const char **argv)
1051 hello.c: /* char ?? */
1053 hello_world:Hello_world
1056 test_expect_success 'grep --break' '
1057 git grep --break -e char -e lo_w hello.c hello_world >actual &&
1058 test_cmp expected actual
1061 cat >expected <<EOF
1062 hello.c:int main(int argc, const char **argv)
1063 hello.c-{
1065 hello.c: /* char ?? */
1066 hello.c-}
1068 hello_world:Hello_world
1069 hello_world-HeLLo_world
1072 test_expect_success 'grep --break with context' '
1073 git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
1074 test_cmp expected actual
1077 cat >expected <<EOF
1078 hello.c
1079 int main(int argc, const char **argv)
1080 /* char ?? */
1081 hello_world
1082 Hello_world
1085 test_expect_success 'grep --heading' '
1086 git grep --heading -e char -e lo_w hello.c hello_world >actual &&
1087 test_cmp expected actual
1090 cat >expected <<EOF
1091 <BOLD;GREEN>hello.c<RESET>
1092 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1093 6: /* <BLACK;BYELLOW>char<RESET> ?? */
1095 <BOLD;GREEN>hello_world<RESET>
1096 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
1099 test_expect_success 'mimic ack-grep --group' '
1100 test_config color.grep.context normal &&
1101 test_config color.grep.filename "bold green" &&
1102 test_config color.grep.function normal &&
1103 test_config color.grep.linenumber normal &&
1104 test_config color.grep.match "black yellow" &&
1105 test_config color.grep.selected normal &&
1106 test_config color.grep.separator normal &&
1108 git grep --break --heading -n --color \
1109 -e char -e lo_w hello.c hello_world |
1110 test_decode_color >actual &&
1111 test_cmp expected actual
1114 cat >expected <<EOF
1115 space: line with leading space1
1116 space: line with leading space2
1117 space: line with leading space3
1120 test_expect_success LIBPCRE 'grep -E "^ "' '
1121 git grep -E "^ " space >actual &&
1122 test_cmp expected actual
1125 test_expect_success LIBPCRE 'grep -P "^ "' '
1126 git grep -P "^ " space >actual &&
1127 test_cmp expected actual
1130 test_done