]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7815-grep-binary.sh
Merge branch 'jc/advice-sans-trailing-whitespace'
[thirdparty/git.git] / t / t7815-grep-binary.sh
CommitLineData
aca20dd5
RS
1#!/bin/sh
2
3test_description='git grep in binary files'
4
9081a421 5TEST_PASSES_SANITIZE_LEAK=true
aca20dd5
RS
6. ./test-lib.sh
7
8test_expect_success 'setup' "
12fc32fa 9 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
aca20dd5
RS
10 git add a &&
11 git commit -m.
12"
13
14test_expect_success 'git grep ina a' '
15 echo Binary file a matches >expect &&
16 git grep ina a >actual &&
17 test_cmp expect actual
18'
19
20test_expect_success 'git grep -ah ina a' '
21 git grep -ah ina a >actual &&
22 test_cmp a actual
23'
24
25test_expect_success 'git grep -I ina a' '
aca20dd5 26 test_must_fail git grep -I ina a >actual &&
1c5e94f4 27 test_must_be_empty actual
aca20dd5
RS
28'
29
c30c10cf
RS
30test_expect_success 'git grep -c ina a' '
31 echo a:1 >expect &&
32 git grep -c ina a >actual &&
33 test_cmp expect actual
34'
35
321ffcc0
RS
36test_expect_success 'git grep -l ina a' '
37 echo a >expect &&
38 git grep -l ina a >actual &&
39 test_cmp expect actual
40'
41
aca20dd5
RS
42test_expect_success 'git grep -L bar a' '
43 echo a >expect &&
44 git grep -L bar a >actual &&
45 test_cmp expect actual
46'
47
48test_expect_success 'git grep -q ina a' '
aca20dd5 49 git grep -q ina a >actual &&
1c5e94f4 50 test_must_be_empty actual
aca20dd5
RS
51'
52
1baddf4b
RS
53test_expect_success 'git grep -F ile a' '
54 git grep -F ile a
55'
56
52d799a7
RS
57test_expect_success 'git grep -Fi iLE a' '
58 git grep -Fi iLE a
59'
60
f96e5673
RS
61# This test actually passes on platforms where regexec() supports the
62# flag REG_STARTEND.
7e36de58 63test_expect_success 'git grep ile a' '
f96e5673
RS
64 git grep ile a
65'
66
67test_expect_failure 'git grep .fi a' '
68 git grep .fi a
69'
70
41b59bfc
JK
71test_expect_success 'grep respects binary diff attribute' '
72 echo text >t &&
73 git add t &&
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
81'
82
55c61688
NTND
83test_expect_success 'grep --cached respects binary diff attribute' '
84 git grep --cached text t >actual &&
85 test_cmp expect actual
86'
87
88test_expect_success 'grep --cached respects binary diff attribute (2)' '
89 git add .gitattributes &&
90 rm .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
95'
96
97test_expect_success 'grep revision respects binary diff attribute' '
98 git commit -m new &&
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
103'
104
41b59bfc
JK
105test_expect_success 'grep respects not-binary diff attribute' '
106 echo binQary | q_to_nul >b &&
107 git add 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 &&
a0578e03
LS
113 git grep bin b >actual.raw &&
114 nul_to_q <actual.raw >actual &&
41b59bfc
JK
115 test_cmp expect actual
116'
117
97f6a9c9
MG
118cat >nul_to_q_textconv <<'EOF'
119#!/bin/sh
120"$PERL_PATH" -pe 'y/\000/Q/' < "$1"
121EOF
122chmod +x nul_to_q_textconv
123
124test_expect_success 'setup textconv filters' '
125 echo a diff=foo >.gitattributes &&
126 git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
127'
128
129test_expect_success 'grep does not honor textconv' '
130 test_must_fail git grep Qfile
131'
132
335ec3bf 133test_expect_success 'grep --textconv honors textconv' '
12fc32fa 134 echo "a:binaryQfileQm[*]cQ*æQð" >expect &&
97f6a9c9
MG
135 git grep --textconv Qfile >actual &&
136 test_cmp expect actual
137'
138
139test_expect_success 'grep --no-textconv does not honor textconv' '
140 test_must_fail git grep --no-textconv Qfile
141'
142
afa15f3c 143test_expect_success 'grep --textconv blob honors textconv' '
12fc32fa 144 echo "HEAD:a:binaryQfileQm[*]cQ*æQð" >expect &&
97f6a9c9
MG
145 git grep --textconv Qfile HEAD:a >actual &&
146 test_cmp expect actual
147'
148
aca20dd5 149test_done