From: Junio C Hamano Date: Tue, 31 Jan 2017 21:32:09 +0000 (-0800) Subject: Merge branch 'jk/grep-e-could-be-extended-beyond-posix' into maint X-Git-Tag: v2.11.1~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/14beee0d0de56d56a8a61e442754644e16c5ed1a?hp=-c Merge branch 'jk/grep-e-could-be-extended-beyond-posix' into maint Tighten a test to avoid mistaking an extended ERE regexp engine as a PRE regexp engine. * jk/grep-e-could-be-extended-beyond-posix: t7810: avoid assumption about invalid regex syntax --- 14beee0d0de56d56a8a61e442754644e16c5ed1a diff --combined t/t7810-grep.sh index de2405ccba,d69f76bf90..19f0108f8a --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@@ -9,9 -9,7 +9,9 @@@ test_description='git grep various . ./test-lib.sh cat >hello.c < #include + int main(int argc, const char **argv) { printf("Hello world.\n"); @@@ -39,6 -37,10 +39,10 @@@ test_expect_success setup echo "a+bc" echo "abc" } >ab && + { + echo d && + echo 0 + } >d0 && echo vvv >v && echo ww w >w && echo x x xx x >x && @@@ -177,7 -179,7 +181,7 @@@ d test_expect_success "grep -c $L (no /dev/null)" ' ! git grep -c test $H | grep /dev/null - ' + ' test_expect_success "grep --max-depth -1 $L" ' { @@@ -355,7 -357,7 +359,7 @@@ test_expect_success 'grep -l -C' cat >expected <actual && test_cmp expected actual ' @@@ -581,7 -583,7 +585,7 @@@ test_expect_success 'log grep (9)' ' test_expect_success 'log grep (9)' ' - git log -g --grep-reflog="commit: third" --author="non-existant" --pretty=tformat:%s >actual && + git log -g --grep-reflog="commit: third" --author="non-existent" --pretty=tformat:%s >actual && : >expect && test_cmp expect actual ' @@@ -717,7 -719,6 +721,7 @@@ test_expect_success 'grep -p' cat >expected < +hello.c- hello.c=int main(int argc, const char **argv) hello.c-{ hello.c- printf("Hello world.\n"); @@@ -743,16 -744,6 +747,16 @@@ test_expect_success 'grep -W' test_cmp expected actual ' +cat >expected < +hello.c:#include +EOF + +test_expect_success 'grep -W shows no trailing empty lines' ' + git grep -W stdio >actual && + test_cmp expected actual +' + cat >expected <empty && - test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual && - test_cmp empty actual + echo "d0:d" >expected && + git grep -G -F -P -E "[\d]" d0 >actual && + test_cmp expected actual ' test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' ' - >empty && - test_must_fail git \ + echo "d0:d" >expected && + git \ -c grep.patterntype=fixed \ -c grep.patterntype=basic \ -c grep.patterntype=perl \ -c grep.patterntype=extended \ - grep "a\x{2b}b\x{2a}c" ab >actual && - test_cmp empty actual + grep "[\d]" d0 >actual && + test_cmp expected actual ' test_expect_success LIBPCRE 'grep -G -F -E -P pattern' ' - echo "ab:a+b*c" >expected && - git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual && + echo "d0:0" >expected && + git grep -G -F -E -P "[\d]" d0 >actual && test_cmp expected actual ' test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' ' - echo "ab:a+b*c" >expected && + echo "d0:0" >expected && git \ -c grep.patterntype=fixed \ -c grep.patterntype=basic \ -c grep.patterntype=extended \ -c grep.patterntype=perl \ - grep "a\x{2b}b\x{2a}c" ab >actual && + grep "[\d]" d0 >actual && test_cmp expected actual ' @@@ -1245,8 -1236,8 +1249,8 @@@ test_expect_success 'grep --heading' cat >expected <hello.c -2:int main(int argc, const char **argv) -6: /* char ?? */ +4:int main(int argc, const char **argv) +8: /* char ?? */ hello_world 3:Hello_world @@@ -1353,7 -1344,7 +1357,7 @@@ test_expect_success 'grep --color -e A ' cat >expected < +hello.c- hello.c=int main(int argc, const char **argv) hello.c-{ hello.c: printf("Hello world.\n"); @@@ -1377,62 -1368,4 +1381,62 @@@ test_expect_success 'grep --color -e A test_cmp expected actual ' +test_expect_success 'grep can find things only in the work tree' ' + : >work-tree-only && + git add work-tree-only && + test_when_finished "git rm -f work-tree-only" && + echo "find in work tree" >work-tree-only && + git grep --quiet "find in work tree" && + test_must_fail git grep --quiet --cached "find in work tree" && + test_must_fail git grep --quiet "find in work tree" HEAD +' + +test_expect_success 'grep can find things only in the work tree (i-t-a)' ' + echo "intend to add this" >intend-to-add && + git add -N intend-to-add && + test_when_finished "git rm -f intend-to-add" && + git grep --quiet "intend to add this" && + test_must_fail git grep --quiet --cached "intend to add this" && + test_must_fail git grep --quiet "intend to add this" HEAD +' + +test_expect_success 'grep does not search work tree with assume unchanged' ' + echo "intend to add this" >intend-to-add && + git add -N intend-to-add && + git update-index --assume-unchanged intend-to-add && + test_when_finished "git rm -f intend-to-add" && + test_must_fail git grep --quiet "intend to add this" && + test_must_fail git grep --quiet --cached "intend to add this" && + test_must_fail git grep --quiet "intend to add this" HEAD +' + +test_expect_success 'grep can find things only in the index' ' + echo "only in the index" >cache-this && + git add cache-this && + rm cache-this && + test_when_finished "git rm --cached cache-this" && + test_must_fail git grep --quiet "only in the index" && + git grep --quiet --cached "only in the index" && + test_must_fail git grep --quiet "only in the index" HEAD +' + +test_expect_success 'grep does not report i-t-a with -L --cached' ' + echo "intend to add this" >intend-to-add && + git add -N intend-to-add && + test_when_finished "git rm -f intend-to-add" && + git ls-files | grep -v "^intend-to-add\$" >expected && + git grep -L --cached "nonexistent_string" >actual && + test_cmp expected actual +' + +test_expect_success 'grep does not report i-t-a and assume unchanged with -L' ' + echo "intend to add this" >intend-to-add-assume-unchanged && + git add -N intend-to-add-assume-unchanged && + test_when_finished "git rm -f intend-to-add-assume-unchanged" && + git update-index --assume-unchanged intend-to-add-assume-unchanged && + git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected && + git grep -L "nonexistent_string" >actual && + test_cmp expected actual +' + test_done