fetch-pack: eliminate spurious error messages
[gitweb.git] / t / t7810-grep.sh
index bc9a522085c794ccfcb9648c19e6e4c0c1ed6d19..35d357d4c8bdc0ef313a2fc269a9ca81b22489f1 100755 (executable)
@@ -47,6 +47,13 @@ test_expect_success setup '
        echo vvv >t/v &&
        mkdir t/a &&
        echo vvv >t/a/v &&
+       {
+               echo "line without leading space1"
+               echo " line with leading space1"
+               echo " line with leading space2"
+               echo " line with leading space3"
+               echo "line without leading space2"
+       } >space &&
        git add . &&
        test_tick &&
        git commit -m initial
@@ -243,8 +250,108 @@ do
                git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
                test_cmp expected actual
        '
+
+       test_expect_success "grep $L with grep.patterntype=basic" '
+               echo "ab:a+bc" >expected &&
+               git -c grep.patterntype=basic grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L with grep.patterntype=extended" '
+               echo "ab:abc" >expected &&
+               git -c grep.patterntype=extended grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L with grep.patterntype=fixed" '
+               echo "ab:a+b*c" >expected &&
+               git -c grep.patterntype=fixed grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
+               echo "ab:a+b*c" >expected &&
+               git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
+               echo "ab:abc" >expected &&
+               git \
+                       -c grep.patternType=default \
+                       -c grep.extendedRegexp=true \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
+               echo "ab:abc" >expected &&
+               git \
+                       -c grep.extendedRegexp=true \
+                       -c grep.patternType=default \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
+               echo "ab:abc" >expected &&
+               git \
+                       -c grep.patternType=extended \
+                       -c grep.extendedRegexp=false \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
+               echo "ab:a+bc" >expected &&
+               git \
+                       -c grep.patternType=basic \
+                       -c grep.extendedRegexp=true \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
+               echo "ab:abc" >expected &&
+               git \
+                       -c grep.extendedRegexp=false \
+                       -c grep.patternType=extended \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
+               echo "ab:a+bc" >expected &&
+               git \
+                       -c grep.extendedRegexp=true \
+                       -c grep.patternType=basic \
+                       grep "a+b*c" ab >actual &&
+               test_cmp expected actual
+       '
 done
 
+cat >expected <<EOF
+file
+EOF
+test_expect_success 'grep -l -C' '
+       git grep -l -C1 foo >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+file:5
+EOF
+test_expect_success 'grep -l -C' '
+       git grep -c -C1 foo >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'grep -L -C' '
+       git ls-files >expected &&
+       git grep -L -C1 nonexistent_string >actual &&
+       test_cmp expected actual
+'
+
 cat >expected <<EOF
 file:foo mmap bar_mmap
 EOF
@@ -370,17 +477,6 @@ test_expect_success 'grep -q, silently report matches' '
        test_cmp empty actual
 '
 
-# Create 1024 file names that sort between "y" and "z" to make sure
-# the two files are handled by different calls to an external grep.
-# This depends on MAXARGS in builtin-grep.c being 1024 or less.
-c32="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v"
-test_expect_success 'grep -C1, hunk mark between files' '
-       for a in $c32; do for b in $c32; do : >y-$a$b; done; done &&
-       git add y-?? &&
-       git grep -C1 "^[yz]" >actual &&
-       test_cmp expected actual
-'
-
 test_expect_success 'grep -C1 hunk mark between files' '
        git grep -C1 "^[yz]" >actual &&
        test_cmp expected actual
@@ -514,6 +610,34 @@ test_expect_success 'grep -p -B5' '
        test_cmp expected actual
 '
 
+cat >expected <<EOF
+hello.c=int main(int argc, const char **argv)
+hello.c-{
+hello.c-       printf("Hello world.\n");
+hello.c:       return 0;
+hello.c-       /* char ?? */
+hello.c-}
+EOF
+
+test_expect_success 'grep -W' '
+       git grep -W return >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c=       printf("Hello world.\n");
+hello.c:       return 0;
+hello.c-       /* char ?? */
+EOF
+
+test_expect_success 'grep -W with userdiff' '
+       test_when_finished "rm -f .gitattributes" &&
+       git config diff.custom.xfuncname "(printf.*|})$" &&
+       echo "hello.c diff=custom" >.gitattributes &&
+       git grep -W return >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'grep from a subdirectory to search wider area (1)' '
        mkdir -p s &&
        (
@@ -545,7 +669,6 @@ test_expect_success 'outside of git repository' '
        mkdir -p non/git/sub &&
        echo hello >non/git/file1 &&
        echo world >non/git/sub/file2 &&
-       echo ".*o*" >non/git/.gitignore &&
        {
                echo file1:hello &&
                echo sub/file2:world
@@ -562,6 +685,23 @@ test_expect_success 'outside of git repository' '
                test_must_fail git grep o &&
                git grep --no-index o >../../actual.sub &&
                test_cmp ../../expect.sub ../../actual.sub
+       ) &&
+
+       echo ".*o*" >non/git/.gitignore &&
+       (
+               GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
+               export GIT_CEILING_DIRECTORIES &&
+               cd non/git &&
+               test_must_fail git grep o &&
+               git grep --no-index --exclude-standard o >../actual.full &&
+               test_cmp ../expect.full ../actual.full &&
+
+               {
+                       echo ".gitignore:.*o*"
+                       cat ../expect.full
+               } >../expect.with.ignored &&
+               git grep --no-index --no-exclude o >../actual.full &&
+               test_cmp ../expect.with.ignored ../actual.full
        )
 '
 
@@ -574,6 +714,10 @@ test_expect_success 'inside git repository but with --no-index' '
        {
                echo file1:hello &&
                echo sub/file2:world
+       } >is/expect.unignored &&
+       {
+               echo ".gitignore:.*o*" &&
+               cat is/expect.unignored
        } >is/expect.full &&
        : >is/expect.empty &&
        echo file2:world >is/expect.sub &&
@@ -582,12 +726,24 @@ test_expect_success 'inside git repository but with --no-index' '
                git init &&
                test_must_fail git grep o >../actual.full &&
                test_cmp ../expect.empty ../actual.full &&
+
+               git grep --untracked o >../actual.unignored &&
+               test_cmp ../expect.unignored ../actual.unignored &&
+
                git grep --no-index o >../actual.full &&
                test_cmp ../expect.full ../actual.full &&
+
+               git grep --no-index --exclude-standard o >../actual.unignored &&
+               test_cmp ../expect.unignored ../actual.unignored &&
+
                cd sub &&
                test_must_fail git grep o >../../actual.sub &&
                test_cmp ../../expect.empty ../../actual.sub &&
+
                git grep --no-index o >../../actual.sub &&
+               test_cmp ../../expect.sub ../../actual.sub &&
+
+               git grep --untracked o >../../actual.sub &&
                test_cmp ../../expect.sub ../../actual.sub
        )
 '
@@ -683,42 +839,256 @@ test_expect_success 'grep -G invalidpattern properly dies ' '
        test_must_fail git grep -G "a["
 '
 
+test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' '
+       test_must_fail git -c grep.patterntype=basic grep "a["
+'
+
 test_expect_success 'grep -E invalidpattern properly dies ' '
        test_must_fail git grep -E "a["
 '
 
+test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' '
+       test_must_fail git -c grep.patterntype=extended grep "a["
+'
+
 test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
        test_must_fail git grep -P "a["
 '
 
+test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
+       test_must_fail git -c grep.patterntype=perl grep "a["
+'
+
 test_expect_success 'grep -G -E -F pattern' '
        echo "ab:a+b*c" >expected &&
        git grep -G -E -F "a+b*c" ab >actual &&
        test_cmp expected actual
 '
 
+test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' '
+       echo "ab:a+b*c" >expected &&
+       git \
+               -c grep.patterntype=basic \
+               -c grep.patterntype=extended \
+               -c grep.patterntype=fixed \
+               grep "a+b*c" ab >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'grep -E -F -G pattern' '
        echo "ab:a+bc" >expected &&
        git grep -E -F -G "a+b*c" ab >actual &&
        test_cmp expected actual
 '
 
+test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' '
+       echo "ab:a+bc" >expected &&
+       git \
+               -c grep.patterntype=extended \
+               -c grep.patterntype=fixed \
+               -c grep.patterntype=basic \
+               grep "a+b*c" ab >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'grep -F -G -E pattern' '
        echo "ab:abc" >expected &&
        git grep -F -G -E "a+b*c" ab >actual &&
        test_cmp expected actual
 '
 
+test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' '
+       echo "ab:abc" >expected &&
+       git \
+               -c grep.patterntype=fixed \
+               -c grep.patterntype=basic \
+               -c grep.patterntype=extended \
+               grep "a+b*c" ab >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'grep -G -F -P -E pattern' '
        >empty &&
        test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
        test_cmp empty actual
 '
 
+test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
+       >empty &&
+       test_must_fail 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
+'
+
 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 &&
        test_cmp expected actual
 '
 
+test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
+       echo "ab:a+b*c" >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 &&
+       test_cmp expected actual
+'
+
+test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
+       echo "ab:a+b*c" >expected &&
+       git \
+               -c grep.patterntype=fixed \
+               grep -P "a\x{2b}b\x{2a}c" ab >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'grep -F pattern with grep.patternType=basic' '
+       echo "ab:a+b*c" >expected &&
+       git \
+               -c grep.patterntype=basic \
+               grep -F "*c" ab >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'grep -G pattern with grep.patternType=fixed' '
+       {
+               echo "ab:a+b*c"
+               echo "ab:a+bc"
+       } >expected &&
+       git \
+               -c grep.patterntype=fixed \
+               grep -G "a+b" ab >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'grep -E pattern with grep.patternType=fixed' '
+       {
+               echo "ab:a+b*c"
+               echo "ab:a+bc"
+               echo "ab:abc"
+       } >expected &&
+       git \
+               -c grep.patterntype=fixed \
+               grep -E "a+" ab >actual &&
+       test_cmp expected actual
+'
+
+test_config() {
+       git config "$1" "$2" &&
+       test_when_finished "git config --unset $1"
+}
+
+cat >expected <<EOF
+hello.c<RED>:<RESET>int main(int argc, const char **argv)
+hello.c<RED>-<RESET>{
+<RED>--<RESET>
+hello.c<RED>:<RESET>   /* char ?? */
+hello.c<RED>-<RESET>}
+<RED>--<RESET>
+hello_world<RED>:<RESET>Hello_world
+hello_world<RED>-<RESET>HeLLo_world
+EOF
+
+test_expect_success 'grep --color, separator' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         normal &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            normal &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        red &&
+
+       git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c:       /* char ?? */
+
+hello_world:Hello_world
+EOF
+
+test_expect_success 'grep --break' '
+       git grep --break -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c-{
+--
+hello.c:       /* char ?? */
+hello.c-}
+
+hello_world:Hello_world
+hello_world-HeLLo_world
+EOF
+
+test_expect_success 'grep --break with context' '
+       git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c
+int main(int argc, const char **argv)
+       /* char ?? */
+hello_world
+Hello_world
+EOF
+
+test_expect_success 'grep --heading' '
+       git grep --heading -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+<BOLD;GREEN>hello.c<RESET>
+2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
+6:     /* <BLACK;BYELLOW>char<RESET> ?? */
+
+<BOLD;GREEN>hello_world<RESET>
+3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
+EOF
+
+test_expect_success 'mimic ack-grep --group' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         "bold green" &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            "black yellow" &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        normal &&
+
+       git grep --break --heading -n --color \
+               -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+space: line with leading space1
+space: line with leading space2
+space: line with leading space3
+EOF
+
+test_expect_success LIBPCRE 'grep -E "^ "' '
+       git grep -E "^ " space >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success LIBPCRE 'grep -P "^ "' '
+       git grep -P "^ " space >actual &&
+       test_cmp expected actual
+'
+
 test_done