3 test_description
='git grep in binary files'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' "
9 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
14 test_expect_success
'git grep ina a' '
15 echo Binary file a matches >expect &&
16 git grep ina a >actual &&
17 test_cmp expect actual
20 test_expect_success
'git grep -ah ina a' '
21 git grep -ah ina a >actual &&
25 test_expect_success
'git grep -I ina a' '
26 test_must_fail git grep -I ina a >actual &&
27 test_must_be_empty 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' '
49 git grep -q ina a >actual &&
50 test_must_be_empty actual
53 test_expect_success
'git grep -F ile a' '
57 test_expect_success
'git grep -Fi iLE a' '
61 # This test actually passes on platforms where regexec() supports the
63 test_expect_success
'git grep ile a' '
67 test_expect_failure
'git grep .fi a' '
71 test_expect_success
'grep respects binary diff attribute' '
74 echo t:text >expect &&
75 git grep text t >actual &&
76 test_cmp expect actual &&
77 echo "t -diff" >.gitattributes &&
78 echo "Binary file t matches" >expect &&
79 git grep text t >actual &&
80 test_cmp expect actual
83 test_expect_success
'grep --cached respects binary diff attribute' '
84 git grep --cached text t >actual &&
85 test_cmp expect actual
88 test_expect_success
'grep --cached respects binary diff attribute (2)' '
89 git add .gitattributes &&
91 git grep --cached text t >actual &&
92 test_when_finished "git rm --cached .gitattributes" &&
93 test_when_finished "git checkout .gitattributes" &&
94 test_cmp expect actual
97 test_expect_success
'grep revision respects binary diff attribute' '
99 echo "Binary file HEAD:t matches" >expect &&
100 git grep text HEAD -- t >actual &&
101 test_when_finished "git reset HEAD^" &&
102 test_cmp expect actual
105 test_expect_success
'grep respects not-binary diff attribute' '
106 echo binQary | q_to_nul >b &&
108 echo "Binary file b matches" >expect &&
109 git grep bin b >actual &&
110 test_cmp expect actual &&
111 echo "b diff" >.gitattributes &&
112 echo "b:binQary" >expect &&
113 git grep bin b >actual.raw &&
114 nul_to_q <actual.raw >actual &&
115 test_cmp expect actual
118 cat >nul_to_q_textconv
<<'EOF'
120 "$PERL_PATH" -pe 'y/\000/Q/' < "$1"
122 chmod +x nul_to_q_textconv
124 test_expect_success
'setup textconv filters' '
125 echo a diff=foo >.gitattributes &&
126 git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
129 test_expect_success
'grep does not honor textconv' '
130 test_must_fail git grep Qfile
133 test_expect_success
'grep --textconv honors textconv' '
134 echo "a:binaryQfileQm[*]cQ*æQð" >expect &&
135 git grep --textconv Qfile >actual &&
136 test_cmp expect actual
139 test_expect_success
'grep --no-textconv does not honor textconv' '
140 test_must_fail git grep --no-textconv Qfile
143 test_expect_success
'grep --textconv blob honors textconv' '
144 echo "HEAD:a:binaryQfileQm[*]cQ*æQð" >expect &&
145 git grep --textconv Qfile HEAD:a >actual &&
146 test_cmp expect actual