]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4030-diff-textconv.sh
The third batch
[thirdparty/git.git] / t / t4030-diff-textconv.sh
CommitLineData
df5e91fc
JK
1#!/bin/sh
2
3test_description='diff.*.textconv tests'
4. ./test-lib.sh
5
6find_diff() {
7 sed '1,/^index /d' | sed '/^-- $/,$d'
8}
9
10cat >expect.binary <<'EOF'
11Binary files a/file and b/file differ
12EOF
13
14cat >expect.text <<'EOF'
15--- a/file
16+++ b/file
17@@ -1 +1,2 @@
18 0
19+1
20EOF
21
22cat >hexdump <<'EOF'
23#!/bin/sh
7096b648 24"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
df5e91fc
JK
25EOF
26chmod +x hexdump
27
28test_expect_success 'setup binary file with history' '
47c88d16
ÆAB
29 test_commit --printf one file "\\0\\n" &&
30 test_commit --printf --append two file "\\01\\n"
df5e91fc
JK
31'
32
33test_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
37'
38
39test_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
43'
44
45test_expect_success 'setup textconv filters' '
46 echo file diff=foo >.gitattributes &&
63962583 47 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
df5e91fc
JK
48 git config diff.fail.textconv false
49'
50
04427ac8 51test_expect_success 'diff produces text' '
df5e91fc
JK
52 git diff HEAD^ HEAD >diff &&
53 find_diff <diff >actual &&
54 test_cmp expect.text actual
55'
56
4bd52d09
MG
57test_expect_success 'show commit produces text' '
58 git show HEAD >diff &&
59 find_diff <diff >actual &&
60 test_cmp expect.text actual
61'
62
df5e91fc
JK
63test_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
67'
68
04427ac8 69test_expect_success 'log produces text' '
df5e91fc
JK
70 git log -1 -p >log &&
71 find_diff <log >actual &&
72 test_cmp expect.text actual
73'
74
c7534ef4 75test_expect_success 'format-patch produces binary' '
df5e91fc
JK
76 git format-patch --no-binary --stdout HEAD^ >patch &&
77 find_diff <patch >actual &&
78 test_cmp expect.binary actual
79'
80
a79b8b66
JK
81test_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}
87'
88
4bd52d09
MG
89test_expect_success 'show blob produces binary' '
90 git show HEAD:file >actual &&
91 printf "\\0\\n\\01\\n" >expect &&
92 test_cmp expect actual
93'
94
083b9931 95test_expect_success 'show --textconv blob produces text' '
4bd52d09
MG
96 git show --textconv HEAD:file >actual &&
97 printf "0\\n1\\n" >expect &&
98 test_cmp expect actual
99'
100
083b9931
MG
101test_expect_success 'show --no-textconv blob produces binary' '
102 git show --no-textconv HEAD:file >actual &&
4bd52d09
MG
103 printf "\\0\\n\\01\\n" >expect &&
104 test_cmp expect actual
105'
106
b1c2f57d
JK
107test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
108 echo one >expect &&
109 git log --root --format=%s -G0 >actual &&
110 test_cmp expect actual
111'
112
113test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
114 echo two >expect &&
115 git log --root --format=%s -G1 >actual &&
116 test_cmp expect actual
117'
118
ef90ab66
JK
119test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
120 echo one >expect &&
121 git log --root --format=%s -S0 >actual &&
122 test_cmp expect actual
123'
124
125test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
126 echo two >expect &&
127 git log --root --format=%s -S1 >actual &&
128 test_cmp expect actual
129'
130
df5e91fc 131cat >expect.stat <<'EOF'
dc801e71 132 file | Bin 2 -> 4 bytes
7f814632 133 1 file changed, 0 insertions(+), 0 deletions(-)
df5e91fc 134EOF
04427ac8 135test_expect_success 'diffstat does not run textconv' '
df5e91fc
JK
136 echo file diff=fail >.gitattributes &&
137 git diff --stat HEAD^ HEAD >actual &&
1108cea7 138 test_cmp expect.stat actual &&
6dd88832
JN
139
140 head -n1 <expect.stat >expect.line1 &&
141 head -n1 <actual >actual.line1 &&
142 test_cmp expect.line1 actual.line1
df5e91fc
JK
143'
144# restore working setup
145echo file diff=foo >.gitattributes
146
a6c57990 147symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
148cat >expect.typechange <<EOF
df5e91fc
JK
149--- a/file
150+++ /dev/null
151@@ -1,2 +0,0 @@
152-0
153-1
154diff --git a/file b/file
155new file mode 120000
a6c57990 156index 0000000..$symlink
df5e91fc
JK
157--- /dev/null
158+++ b/file
159@@ -0,0 +1 @@
160+frotz
161\ No newline at end of file
162EOF
889c6f0e 163
2675773a 164test_expect_success 'textconv does not act on symlinks' '
889c6f0e
JS
165 rm -f file &&
166 test_ln_s_add frotz file &&
df5e91fc
JK
167 git commit -m typechange &&
168 git show >diff &&
169 find_diff <diff >actual &&
170 test_cmp expect.typechange actual
171'
172
173test_done