3 test_description
='git grep in binary files'
11 pattern_human
=$
(echo "$pattern" |
sed 's/Q/<NUL>/g')
13 if test "$matches" = 1
15 test_expect_success
"git grep -f f $flags '$pattern_human' a" "
16 printf '$pattern' | q_to_nul >f &&
17 git grep -f f $flags a
19 elif test "$matches" = 0
21 test_expect_success
"git grep -f f $flags '$pattern_human' a" "
22 printf '$pattern' | q_to_nul >f &&
23 test_must_fail git grep -f f $flags a
26 test_expect_success
"PANIC: Test framework error. Unknown matches value $matches" 'false'
30 test_expect_success
'setup' "
31 echo 'binaryQfile' | q_to_nul >a &&
36 test_expect_success
'git grep ina a' '
37 echo Binary file a matches >expect &&
38 git grep ina a >actual &&
39 test_cmp expect actual
42 test_expect_success
'git grep -ah ina a' '
43 git grep -ah ina a >actual &&
47 test_expect_success
'git grep -I ina a' '
49 test_must_fail git grep -I ina a >actual &&
50 test_cmp expect actual
53 test_expect_success
'git grep -c ina a' '
55 git grep -c ina a >actual &&
56 test_cmp expect actual
59 test_expect_success
'git grep -l ina a' '
61 git grep -l ina a >actual &&
62 test_cmp expect actual
65 test_expect_success
'git grep -L bar a' '
67 git grep -L bar a >actual &&
68 test_cmp expect actual
71 test_expect_success
'git grep -q ina a' '
73 git grep -q ina a >actual &&
74 test_cmp expect actual
77 test_expect_success
'git grep -F ile a' '
81 test_expect_success
'git grep -Fi iLE a' '
85 # This test actually passes on platforms where regexec() supports the
87 test_expect_success
'git grep ile a' '
91 test_expect_failure
'git grep .fi a' '
95 nul_match
1 '-F' 'yQf'
96 nul_match
0 '-F' 'yQx'
97 nul_match
1 '-Fi' 'YQf'
98 nul_match
0 '-Fi' 'YQx'
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 >actual.raw &&
145 nul_to_q <actual.raw >actual &&
146 test_cmp expect actual
149 cat >nul_to_q_textconv
<<'EOF'
151 "$PERL_PATH" -pe 'y/\000/Q/' < "$1"
153 chmod +x nul_to_q_textconv
155 test_expect_success
'setup textconv filters' '
156 echo a diff=foo >.gitattributes &&
157 git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
160 test_expect_success
'grep does not honor textconv' '
161 test_must_fail git grep Qfile
164 test_expect_success
'grep --textconv honors textconv' '
165 echo "a:binaryQfile" >expect &&
166 git grep --textconv Qfile >actual &&
167 test_cmp expect actual
170 test_expect_success
'grep --no-textconv does not honor textconv' '
171 test_must_fail git grep --no-textconv Qfile
174 test_expect_success
'grep --textconv blob honors textconv' '
175 echo "HEAD:a:binaryQfile" >expect &&
176 git grep --textconv Qfile HEAD:a >actual &&
177 test_cmp expect actual