Merge branch 'mg/timestamp-t-fix' into maint
[gitweb.git] / t / t7810-grep.sh
index 19f0108f8a2c67c518a92d996be7a335dbb69af2..2a6679c2f596fb13a34786a4aa4b954e61c61113 100755 (executable)
@@ -275,12 +275,16 @@ do
                test_cmp expected actual
        '
 
-       test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
+       test_expect_success PCRE "grep $L with grep.patterntype=perl" '
                echo "${HC}ab:a+b*c" >expected &&
                git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual &&
                test_cmp expected actual
        '
 
+       test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
+               test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
+       '
+
        test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
                echo "${HC}ab:abc" >expected &&
                git \
@@ -370,6 +374,11 @@ test_expect_success 'grep -L -C' '
        test_cmp expected actual
 '
 
+test_expect_success 'grep --files-without-match --quiet' '
+       git grep --files-without-match --quiet nonexistent_string >actual &&
+       test_cmp /dev/null actual
+'
+
 cat >expected <<EOF
 file:foo mmap bar_mmap
 EOF
@@ -771,6 +780,40 @@ test_expect_success 'grep -W with userdiff' '
        test_cmp expected actual
 '
 
+for threads in $(test_seq 0 10)
+do
+       test_expect_success "grep --threads=$threads & -c grep.threads=$threads" "
+               git grep --threads=$threads . >actual.$threads &&
+               if test $threads -ge 1
+               then
+                       test_cmp actual.\$(($threads - 1)) actual.$threads
+               fi &&
+               git -c grep.threads=$threads grep . >actual.$threads &&
+               if test $threads -ge 1
+               then
+                       test_cmp actual.\$(($threads - 1)) actual.$threads
+               fi
+       "
+done
+
+test_expect_success !PTHREADS,C_LOCALE_OUTPUT 'grep --threads=N or pack.threads=N warns when no pthreads' '
+       git grep --threads=2 Hello hello_world 2>err &&
+       grep ^warning: err >warnings &&
+       test_line_count = 1 warnings &&
+       grep -F "no threads support, ignoring --threads" err &&
+       git -c grep.threads=2 grep Hello hello_world 2>err &&
+       grep ^warning: err >warnings &&
+       test_line_count = 1 warnings &&
+       grep -F "no threads support, ignoring grep.threads" err &&
+       git -c grep.threads=2 grep --threads=4 Hello hello_world 2>err &&
+       grep ^warning: err >warnings &&
+       test_line_count = 2 warnings &&
+       grep -F "no threads support, ignoring --threads" err &&
+       grep -F "no threads support, ignoring grep.threads" err &&
+       git -c grep.threads=0 grep --threads=0 Hello hello_world 2>err &&
+       test_line_count = 0 err
+'
+
 test_expect_success 'grep from a subdirectory to search wider area (1)' '
        mkdir -p s &&
        (
@@ -982,21 +1025,95 @@ test_expect_success 'grep -e -- -- path' '
        test_cmp expected actual
 '
 
+test_expect_success 'dashdash disambiguates rev as rev' '
+       test_when_finished "rm -f master" &&
+       echo content >master &&
+       echo master:hello.c >expect &&
+       git grep -l o master -- hello.c >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'dashdash disambiguates pathspec as pathspec' '
+       test_when_finished "git rm -f master" &&
+       echo content >master &&
+       git add master &&
+       echo master:content >expect &&
+       git grep o -- master >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'report bogus arg without dashdash' '
+       test_must_fail git grep o does-not-exist
+'
+
+test_expect_success 'report bogus rev with dashdash' '
+       test_must_fail git grep o hello.c --
+'
+
+test_expect_success 'allow non-existent path with dashdash' '
+       # We need a real match so grep exits with success.
+       tree=$(git ls-tree HEAD |
+              sed s/hello.c/not-in-working-tree/ |
+              git mktree) &&
+       git grep o "$tree" -- not-in-working-tree
+'
+
+test_expect_success 'grep --no-index pattern -- path' '
+       rm -fr non &&
+       mkdir -p non/git &&
+       (
+               GIT_CEILING_DIRECTORIES="$(pwd)/non" &&
+               export GIT_CEILING_DIRECTORIES &&
+               cd non/git &&
+               echo hello >hello &&
+               echo goodbye >goodbye &&
+               echo hello:hello >expect &&
+               git grep --no-index o -- hello >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'grep --no-index complains of revs' '
+       test_must_fail git grep --no-index o master -- 2>err &&
+       test_i18ngrep "cannot be used with revs" err
+'
+
+test_expect_success 'grep --no-index prefers paths to revs' '
+       test_when_finished "rm -f master" &&
+       echo content >master &&
+       echo master:content >expect &&
+       git grep --no-index o master >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'grep --no-index does not "diagnose" revs' '
+       test_must_fail git grep --no-index o :1:hello.c 2>err &&
+       test_i18ngrep ! -i "did you mean" err
+'
+
 cat >expected <<EOF
 hello.c:int main(int argc, const char **argv)
 hello.c:       printf("Hello world.\n");
 EOF
 
-test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
+test_expect_success PCRE 'grep --perl-regexp pattern' '
        git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P pattern' '
+test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
+       test_must_fail git grep --perl-regexp "foo.*bar"
+'
+
+test_expect_success PCRE 'grep -P pattern' '
        git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
        test_cmp expected actual
 '
 
+test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
+       test_must_fail git grep -P "foo.*bar"
+'
+
 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
        >empty &&
        test_must_fail git -c grep.extendedregexp=true \
@@ -1004,13 +1121,13 @@ test_expect_success 'grep pattern with grep.extendedRegexp=true' '
        test_cmp empty actual
 '
 
-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
+test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' '
        git -c grep.extendedregexp=true \
                grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P -v pattern' '
+test_expect_success PCRE 'grep -P -v pattern' '
        {
                echo "ab:a+b*c"
                echo "ab:a+bc"
@@ -1019,7 +1136,7 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P -i pattern' '
+test_expect_success PCRE 'grep -P -i pattern' '
        cat >expected <<-EOF &&
        hello.c:        printf("Hello world.\n");
        EOF
@@ -1027,7 +1144,7 @@ test_expect_success LIBPCRE 'grep -P -i pattern' '
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P -w pattern' '
+test_expect_success PCRE 'grep -P -w pattern' '
        {
                echo "hello_world:Hello world"
                echo "hello_world:HeLLo world"
@@ -1036,6 +1153,13 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
        test_cmp expected actual
 '
 
+test_expect_success PCRE 'grep -P backreferences work (the PCRE NO_AUTO_CAPTURE flag is not set)' '
+       git grep -P -h "(?P<one>.)(?P=one)" hello_world >actual &&
+       test_cmp hello_world actual &&
+       git grep -P -h "(.)\1" hello_world >actual &&
+       test_cmp hello_world actual
+'
+
 test_expect_success 'grep -G invalidpattern properly dies ' '
        test_must_fail git grep -G "a["
 '
@@ -1052,11 +1176,11 @@ test_expect_success 'grep invalidpattern properly dies with grep.patternType=ext
        test_must_fail git -c grep.patterntype=extended grep "a["
 '
 
-test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
+test_expect_success PCRE '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_expect_success PCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
        test_must_fail git -c grep.patterntype=perl grep "a["
 '
 
@@ -1125,13 +1249,13 @@ test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =e
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
+test_expect_success PCRE 'grep -G -F -E -P pattern' '
        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' '
+test_expect_success PCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
        echo "d0:0" >expected &&
        git \
                -c grep.patterntype=fixed \
@@ -1142,7 +1266,7 @@ test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
+test_expect_success PCRE 'grep -P pattern with grep.patternType=fixed' '
        echo "ab:a+b*c" >expected &&
        git \
                -c grep.patterntype=fixed \
@@ -1277,12 +1401,12 @@ space: line with leading space2
 space: line with leading space3
 EOF
 
-test_expect_success LIBPCRE 'grep -E "^ "' '
+test_expect_success PCRE 'grep -E "^ "' '
        git grep -E "^ " space >actual &&
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -P "^ "' '
+test_expect_success PCRE 'grep -P "^ "' '
        git grep -P "^ " space >actual &&
        test_cmp expected actual
 '