3 test_description='git grep in binary files'
 
   7 test_expect_success 'setup' "
 
   8         echo 'binaryQfile' | q_to_nul >a &&
 
  13 test_expect_success 'git grep ina a' '
 
  14         echo Binary file a matches >expect &&
 
  15         git grep ina a >actual &&
 
  16         test_cmp expect actual
 
  19 test_expect_success 'git grep -ah ina a' '
 
  20         git grep -ah ina a >actual &&
 
  24 test_expect_success 'git grep -I ina a' '
 
  26         test_must_fail git grep -I ina a >actual &&
 
  27         test_cmp expect actual
 
  30 test_expect_success 'git grep -c ina a' '
 
  32         git grep -c ina a >actual &&
 
  33         test_cmp expect actual
 
  36 test_expect_success 'git grep -l ina a' '
 
  38         git grep -l ina a >actual &&
 
  39         test_cmp expect actual
 
  42 test_expect_success 'git grep -L bar a' '
 
  44         git grep -L bar a >actual &&
 
  45         test_cmp expect actual
 
  48 test_expect_success 'git grep -q ina a' '
 
  50         git grep -q ina a >actual &&
 
  51         test_cmp expect actual
 
  54 test_expect_success 'git grep -F ile a' '
 
  58 test_expect_success 'git grep -Fi iLE a' '
 
  62 # This test actually passes on platforms where regexec() supports the
 
  64 test_expect_success 'git grep ile a' '
 
  68 test_expect_failure 'git grep .fi a' '
 
  72 test_expect_success 'git grep -F y<NUL>f a' "
 
  73         printf 'yQf' | q_to_nul >f &&
 
  77 test_expect_success 'git grep -F y<NUL>x a' "
 
  78         printf 'yQx' | q_to_nul >f &&
 
  79         test_must_fail git grep -f f -F a
 
  82 test_expect_success 'git grep -Fi Y<NUL>f a' "
 
  83         printf 'YQf' | q_to_nul >f &&
 
  87 test_expect_success 'git grep -Fi Y<NUL>x a' "
 
  88         printf 'YQx' | q_to_nul >f &&
 
  89         test_must_fail git grep -f f -Fi a
 
  92 test_expect_success 'git grep y<NUL>f a' "
 
  93         printf 'yQf' | q_to_nul >f &&
 
  97 test_expect_success 'git grep y<NUL>x a' "
 
  98         printf 'yQx' | q_to_nul >f &&
 
  99         test_must_fail git grep -f f a
 
 102 test_expect_success 'grep respects binary diff attribute' '
 
 105         echo t:text >expect &&
 
 106         git grep text t >actual &&
 
 107         test_cmp expect actual &&
 
 108         echo "t -diff" >.gitattributes &&
 
 109         echo "Binary file t matches" >expect &&
 
 110         git grep text t >actual &&
 
 111         test_cmp expect actual
 
 114 test_expect_success 'grep --cached respects binary diff attribute' '
 
 115         git grep --cached text t >actual &&
 
 116         test_cmp expect actual
 
 119 test_expect_success 'grep --cached respects binary diff attribute (2)' '
 
 120         git add .gitattributes &&
 
 122         git grep --cached text t >actual &&
 
 123         test_when_finished "git rm --cached .gitattributes" &&
 
 124         test_when_finished "git checkout .gitattributes" &&
 
 125         test_cmp expect actual
 
 128 test_expect_success 'grep revision respects binary diff attribute' '
 
 130         echo "Binary file HEAD:t matches" >expect &&
 
 131         git grep text HEAD -- t >actual &&
 
 132         test_when_finished "git reset HEAD^" &&
 
 133         test_cmp expect actual
 
 136 test_expect_success 'grep respects not-binary diff attribute' '
 
 137         echo binQary | q_to_nul >b &&
 
 139         echo "Binary file b matches" >expect &&
 
 140         git grep bin b >actual &&
 
 141         test_cmp expect actual &&
 
 142         echo "b diff" >.gitattributes &&
 
 143         echo "b:binQary" >expect &&
 
 144         git grep bin b | nul_to_q >actual &&
 
 145         test_cmp expect actual
 
 148 cat >nul_to_q_textconv <<'EOF'
 
 150 "$PERL_PATH" -pe 'y/\000/Q/' < "$1"
 
 152 chmod +x nul_to_q_textconv
 
 154 test_expect_success 'setup textconv filters' '
 
 155         echo a diff=foo >.gitattributes &&
 
 156         git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
 
 159 test_expect_success 'grep does not honor textconv' '
 
 160         test_must_fail git grep Qfile
 
 163 test_expect_success 'grep --textconv honors textconv' '
 
 164         echo "a:binaryQfile" >expect &&
 
 165         git grep --textconv Qfile >actual &&
 
 166         test_cmp expect actual
 
 169 test_expect_success 'grep --no-textconv does not honor textconv' '
 
 170         test_must_fail git grep --no-textconv Qfile
 
 173 test_expect_success 'grep --textconv blob honors textconv' '
 
 174         echo "HEAD:a:binaryQfile" >expect &&
 
 175         git grep --textconv Qfile HEAD:a >actual &&
 
 176         test_cmp expect actual