]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4030-diff-textconv.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[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' '
29 printf "\\0\\n" >file &&
30 git add file &&
31 git commit -m one &&
deb13872 32 printf "\\01\\n" >>file &&
df5e91fc
JK
33 git add file &&
34 git commit -m two
35'
36
37test_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
41'
42
43test_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
47'
48
49test_expect_success 'setup textconv filters' '
50 echo file diff=foo >.gitattributes &&
63962583 51 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
df5e91fc
JK
52 git config diff.fail.textconv false
53'
54
04427ac8 55test_expect_success 'diff produces text' '
df5e91fc
JK
56 git diff HEAD^ HEAD >diff &&
57 find_diff <diff >actual &&
58 test_cmp expect.text actual
59'
60
4bd52d09
MG
61test_expect_success 'show commit produces text' '
62 git show HEAD >diff &&
63 find_diff <diff >actual &&
64 test_cmp expect.text actual
65'
66
df5e91fc
JK
67test_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
71'
72
04427ac8 73test_expect_success 'log produces text' '
df5e91fc
JK
74 git log -1 -p >log &&
75 find_diff <log >actual &&
76 test_cmp expect.text actual
77'
78
c7534ef4 79test_expect_success 'format-patch produces binary' '
df5e91fc
JK
80 git format-patch --no-binary --stdout HEAD^ >patch &&
81 find_diff <patch >actual &&
82 test_cmp expect.binary actual
83'
84
a79b8b66
JK
85test_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}
91'
92
4bd52d09
MG
93test_expect_success 'show blob produces binary' '
94 git show HEAD:file >actual &&
95 printf "\\0\\n\\01\\n" >expect &&
96 test_cmp expect actual
97'
98
083b9931 99test_expect_success 'show --textconv blob produces text' '
4bd52d09
MG
100 git show --textconv HEAD:file >actual &&
101 printf "0\\n1\\n" >expect &&
102 test_cmp expect actual
103'
104
083b9931
MG
105test_expect_success 'show --no-textconv blob produces binary' '
106 git show --no-textconv HEAD:file >actual &&
4bd52d09
MG
107 printf "\\0\\n\\01\\n" >expect &&
108 test_cmp expect actual
109'
110
b1c2f57d
JK
111test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
112 echo one >expect &&
113 git log --root --format=%s -G0 >actual &&
114 test_cmp expect actual
115'
116
117test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
118 echo two >expect &&
119 git log --root --format=%s -G1 >actual &&
120 test_cmp expect actual
121'
122
ef90ab66
JK
123test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
124 echo one >expect &&
125 git log --root --format=%s -S0 >actual &&
126 test_cmp expect actual
127'
128
129test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
130 echo two >expect &&
131 git log --root --format=%s -S1 >actual &&
132 test_cmp expect actual
133'
134
df5e91fc 135cat >expect.stat <<'EOF'
dc801e71 136 file | Bin 2 -> 4 bytes
7f814632 137 1 file changed, 0 insertions(+), 0 deletions(-)
df5e91fc 138EOF
04427ac8 139test_expect_success 'diffstat does not run textconv' '
df5e91fc
JK
140 echo file diff=fail >.gitattributes &&
141 git diff --stat HEAD^ HEAD >actual &&
6dd88832
JN
142 test_i18ncmp expect.stat actual &&
143
144 head -n1 <expect.stat >expect.line1 &&
145 head -n1 <actual >actual.line1 &&
146 test_cmp expect.line1 actual.line1
df5e91fc
JK
147'
148# restore working setup
149echo file diff=foo >.gitattributes
150
a6c57990 151symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
152cat >expect.typechange <<EOF
df5e91fc
JK
153--- a/file
154+++ /dev/null
155@@ -1,2 +0,0 @@
156-0
157-1
158diff --git a/file b/file
159new file mode 120000
a6c57990 160index 0000000..$symlink
df5e91fc
JK
161--- /dev/null
162+++ b/file
163@@ -0,0 +1 @@
164+frotz
165\ No newline at end of file
166EOF
889c6f0e 167
2675773a 168test_expect_success 'textconv does not act on symlinks' '
889c6f0e
JS
169 rm -f file &&
170 test_ln_s_add frotz file &&
df5e91fc
JK
171 git commit -m typechange &&
172 git show >diff &&
173 find_diff <diff >actual &&
174 test_cmp expect.typechange actual
175'
176
177test_done