Merge branch 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po
[alt-git.git] / t / t7815-grep-binary.sh
blobac871287c03a9facc3b6530ce82b3c40ed8d9cad
1 #!/bin/sh
3 test_description='git grep in binary files'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' "
9 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
10 git add a &&
11 git commit -m.
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 &&
22 test_cmp 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' '
31 echo a:1 >expect &&
32 git grep -c ina a >actual &&
33 test_cmp expect actual
36 test_expect_success 'git grep -l ina a' '
37 echo a >expect &&
38 git grep -l ina a >actual &&
39 test_cmp expect actual
42 test_expect_success 'git grep -L bar a' '
43 echo a >expect &&
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' '
54 git grep -F ile a
57 test_expect_success 'git grep -Fi iLE a' '
58 git grep -Fi iLE a
61 # This test actually passes on platforms where regexec() supports the
62 # flag REG_STARTEND.
63 test_expect_success 'git grep ile a' '
64 git grep ile a
67 test_expect_failure 'git grep .fi a' '
68 git grep .fi a
71 test_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
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 &&
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
97 test_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
105 test_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 &&
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'
119 #!/bin/sh
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
149 test_done