3 test_description
='diff.*.textconv tests'
7 sed '1,/^index /d' |
sed '/^-- $/,$d'
10 cat >expect.binary
<<'EOF'
11 Binary files a/file and b/file differ
14 cat >expect.text
<<'EOF'
24 "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
28 test_expect_success
'setup binary file with history' '
29 printf "\\0\\n" >file &&
32 printf "\\01\\n" >>file &&
37 test_expect_success
'file is considered binary by porcelain' '
38 git diff HEAD^ HEAD >diff &&
39 find_diff <diff >actual &&
40 test_cmp expect.binary actual
43 test_expect_success
'file is considered binary by plumbing' '
44 git diff-tree -p HEAD^ HEAD >diff &&
45 find_diff <diff >actual &&
46 test_cmp expect.binary actual
49 test_expect_success
'setup textconv filters' '
50 echo file diff=foo >.gitattributes &&
51 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
52 git config diff.fail.textconv false
55 test_expect_success
'diff produces text' '
56 git diff HEAD^ HEAD >diff &&
57 find_diff <diff >actual &&
58 test_cmp expect.text actual
61 test_expect_success
'show commit produces text' '
62 git show HEAD >diff &&
63 find_diff <diff >actual &&
64 test_cmp expect.text actual
67 test_expect_success
'diff-tree produces binary' '
68 git diff-tree -p HEAD^ HEAD >diff &&
69 find_diff <diff >actual &&
70 test_cmp expect.binary actual
73 test_expect_success
'log produces text' '
75 find_diff <log >actual &&
76 test_cmp expect.text actual
79 test_expect_success
'format-patch produces binary' '
80 git format-patch --no-binary --stdout HEAD^ >patch &&
81 find_diff <patch >actual &&
82 test_cmp expect.binary actual
85 test_expect_success
'status -v produces text' '
86 git reset --soft HEAD^ &&
87 git status -v >diff &&
88 find_diff <diff >actual &&
89 test_cmp expect.text actual &&
90 git reset --soft HEAD@{1}
93 test_expect_success
'show blob produces binary' '
94 git show HEAD:file >actual &&
95 printf "\\0\\n\\01\\n" >expect &&
96 test_cmp expect actual
99 test_expect_success
'show --textconv blob produces text' '
100 git show --textconv HEAD:file >actual &&
101 printf "0\\n1\\n" >expect &&
102 test_cmp expect actual
105 test_expect_success
'show --no-textconv blob produces binary' '
106 git show --no-textconv HEAD:file >actual &&
107 printf "\\0\\n\\01\\n" >expect &&
108 test_cmp expect actual
111 test_expect_success
'grep-diff (-G) operates on textconv data (add)' '
113 git log --root --format=%s -G0 >actual &&
114 test_cmp expect actual
117 test_expect_success
'grep-diff (-G) operates on textconv data (modification)' '
119 git log --root --format=%s -G1 >actual &&
120 test_cmp expect actual
123 test_expect_success
'pickaxe (-S) operates on textconv data (add)' '
125 git log --root --format=%s -S0 >actual &&
126 test_cmp expect actual
129 test_expect_success
'pickaxe (-S) operates on textconv data (modification)' '
131 git log --root --format=%s -S1 >actual &&
132 test_cmp expect actual
135 cat >expect.stat
<<'EOF'
136 file | Bin 2 -> 4 bytes
137 1 file changed, 0 insertions(+), 0 deletions(-)
139 test_expect_success
'diffstat does not run textconv' '
140 echo file diff=fail >.gitattributes &&
141 git diff --stat HEAD^ HEAD >actual &&
142 test_i18ncmp expect.stat actual &&
144 head -n1 <expect.stat >expect.line1 &&
145 head -n1 <actual >actual.line1 &&
146 test_cmp expect.line1 actual.line1
148 # restore working setup
149 echo file diff=foo
>.gitattributes
151 cat >expect.typechange
<<'EOF'
157 diff --git a/file b/file
159 index 0000000..67be421
164 \ No newline at end of file
167 test_expect_success
'textconv does not act on symlinks' '
169 test_ln_s_add frotz file &&
170 git commit -m typechange &&
172 find_diff <diff >actual &&
173 test_cmp expect.typechange actual