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 test_commit --printf one file "\\0\\n" &&
30 test_commit --printf --append two file "\\01\\n"
33 test_expect_success
'file is considered binary by porcelain' '
34 git diff HEAD^ HEAD >diff &&
35 find_diff <diff >actual &&
36 test_cmp expect.binary actual
39 test_expect_success
'file is considered binary by plumbing' '
40 git diff-tree -p HEAD^ HEAD >diff &&
41 find_diff <diff >actual &&
42 test_cmp expect.binary actual
45 test_expect_success
'setup textconv filters' '
46 echo file diff=foo >.gitattributes &&
47 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
48 git config diff.fail.textconv false
51 test_expect_success
'diff produces text' '
52 git diff HEAD^ HEAD >diff &&
53 find_diff <diff >actual &&
54 test_cmp expect.text actual
57 test_expect_success
'show commit produces text' '
58 git show HEAD >diff &&
59 find_diff <diff >actual &&
60 test_cmp expect.text actual
63 test_expect_success
'diff-tree produces binary' '
64 git diff-tree -p HEAD^ HEAD >diff &&
65 find_diff <diff >actual &&
66 test_cmp expect.binary actual
69 test_expect_success
'log produces text' '
71 find_diff <log >actual &&
72 test_cmp expect.text actual
75 test_expect_success
'format-patch produces binary' '
76 git format-patch --no-binary --stdout HEAD^ >patch &&
77 find_diff <patch >actual &&
78 test_cmp expect.binary actual
81 test_expect_success
'status -v produces text' '
82 git reset --soft HEAD^ &&
83 git status -v >diff &&
84 find_diff <diff >actual &&
85 test_cmp expect.text actual &&
86 git reset --soft HEAD@{1}
89 test_expect_success
'show blob produces binary' '
90 git show HEAD:file >actual &&
91 printf "\\0\\n\\01\\n" >expect &&
92 test_cmp expect actual
95 test_expect_success
'show --textconv blob produces text' '
96 git show --textconv HEAD:file >actual &&
97 printf "0\\n1\\n" >expect &&
98 test_cmp expect actual
101 test_expect_success
'show --no-textconv blob produces binary' '
102 git show --no-textconv HEAD:file >actual &&
103 printf "\\0\\n\\01\\n" >expect &&
104 test_cmp expect actual
107 test_expect_success
'grep-diff (-G) operates on textconv data (add)' '
109 git log --root --format=%s -G0 >actual &&
110 test_cmp expect actual
113 test_expect_success
'grep-diff (-G) operates on textconv data (modification)' '
115 git log --root --format=%s -G1 >actual &&
116 test_cmp expect actual
119 test_expect_success
'pickaxe (-S) operates on textconv data (add)' '
121 git log --root --format=%s -S0 >actual &&
122 test_cmp expect actual
125 test_expect_success
'pickaxe (-S) operates on textconv data (modification)' '
127 git log --root --format=%s -S1 >actual &&
128 test_cmp expect actual
131 cat >expect.stat
<<'EOF'
132 file | Bin 2 -> 4 bytes
133 1 file changed, 0 insertions(+), 0 deletions(-)
135 test_expect_success
'diffstat does not run textconv' '
136 echo file diff=fail >.gitattributes &&
137 git diff --stat HEAD^ HEAD >actual &&
138 test_cmp expect.stat actual &&
140 head -n1 <expect.stat >expect.line1 &&
141 head -n1 <actual >actual.line1 &&
142 test_cmp expect.line1 actual.line1
144 # restore working setup
145 echo file diff=foo
>.gitattributes
147 symlink
=$
(git rev-parse
--short $
(printf frotz | git hash-object
--stdin))
148 cat >expect.typechange
<<EOF
154 diff --git a/file b/file
156 index 0000000..$symlink
161 \ No newline at end of file
164 test_expect_success
'textconv does not act on symlinks' '
166 test_ln_s_add frotz file &&
167 git commit -m typechange &&
169 find_diff <diff >actual &&
170 test_cmp expect.typechange actual