Raw
1 #!/bin/sh
2
3 test_description='diff.*.textconv tests'
4
5 . ./test-lib.sh
6
7 find_diff() {
8 sed '1,/^index /d' | sed '/^-- $/,$d'
9 }
10
11 cat >expect.binary <<'EOF'
12 Binary files a/file and b/file differ
13 EOF
14
15 cat >expect.text <<'EOF'
16 --- a/file
17 +++ b/file
18 @@ -1 +1,2 @@
19 0
20 +1
21 EOF
22
23 test_expect_success 'setup binary file with history' '
24 write_script hexdump <<-\EOF &&
25 tr "\000\001" "01" <"$1"
26 EOF
27 test_commit --printf one file "\\0\\n" &&
28 test_commit --printf --append two file "\\01\\n"
29 '
30
31 test_expect_success 'file is considered binary by porcelain' '
32 git diff HEAD^ HEAD >diff &&
33 find_diff <diff >actual &&
34 test_cmp expect.binary actual
35 '
36
37 test_expect_success 'file is considered binary by plumbing' '
38 git diff-tree -p HEAD^ HEAD >diff &&
39 find_diff <diff >actual &&
40 test_cmp expect.binary actual
41 '
42
43 test_expect_success 'setup textconv filters' '
44 echo file diff=foo >.gitattributes &&
45 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
46 git config diff.fail.textconv false
47 '
48
49 test_expect_success 'diff produces text' '
50 git diff HEAD^ HEAD >diff &&
51 find_diff <diff >actual &&
52 test_cmp expect.text actual
53 '
54
55 test_expect_success 'show commit produces text' '
56 git show HEAD >diff &&
57 find_diff <diff >actual &&
58 test_cmp expect.text actual
59 '
60
61 test_expect_success 'diff-tree produces binary' '
62 git diff-tree -p HEAD^ HEAD >diff &&
63 find_diff <diff >actual &&
64 test_cmp expect.binary actual
65 '
66
67 test_expect_success 'log produces text' '
68 git log -1 -p >log &&
69 find_diff <log >actual &&
70 test_cmp expect.text actual
71 '
72
73 test_expect_success 'format-patch produces binary' '
74 git format-patch --no-binary --stdout HEAD^ >patch &&
75 find_diff <patch >actual &&
76 test_cmp expect.binary actual
77 '
78
79 test_expect_success 'status -v produces text' '
80 git reset --soft HEAD^ &&
81 git status -v >diff &&
82 find_diff <diff >actual &&
83 test_cmp expect.text actual &&
84 git reset --soft HEAD@{1}
85 '
86
87 test_expect_success 'show blob produces binary' '
88 git show HEAD:file >actual &&
89 printf "\\0\\n\\01\\n" >expect &&
90 test_cmp expect actual
91 '
92
93 test_expect_success 'show --textconv blob produces text' '
94 git show --textconv HEAD:file >actual &&
95 printf "0\\n1\\n" >expect &&
96 test_cmp expect actual
97 '
98
99 test_expect_success 'show --no-textconv blob produces binary' '
100 git show --no-textconv HEAD:file >actual &&
101 printf "\\0\\n\\01\\n" >expect &&
102 test_cmp expect actual
103 '
104
105 test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
106 echo one >expect &&
107 git log --root --format=%s -G0 >actual &&
108 test_cmp expect actual
109 '
110
111 test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
112 echo two >expect &&
113 git log --root --format=%s -G1 >actual &&
114 test_cmp expect actual
115 '
116
117 test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
118 echo one >expect &&
119 git log --root --format=%s -S0 >actual &&
120 test_cmp expect actual
121 '
122
123 test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
124 echo two >expect &&
125 git log --root --format=%s -S1 >actual &&
126 test_cmp expect actual
127 '
128
129 cat >expect.stat <<'EOF'
130 file | Bin 2 -> 4 bytes
131 1 file changed, 0 insertions(+), 0 deletions(-)
132 EOF
133 test_expect_success 'diffstat does not run textconv' '
134 echo file diff=fail >.gitattributes &&
135 git diff --stat HEAD^ HEAD >actual &&
136 test_cmp expect.stat actual &&
137
138 head -n1 <expect.stat >expect.line1 &&
139 head -n1 <actual >actual.line1 &&
140 test_cmp expect.line1 actual.line1
141 '
142 # restore working setup
143 echo file diff=foo >.gitattributes
144
145 symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
146 cat >expect.typechange <<EOF
147 --- a/file
148 +++ /dev/null
149 @@ -1,2 +0,0 @@
150 -0
151 -1
152 diff --git a/file b/file
153 new file mode 120000
154 index 0000000..$symlink
155 --- /dev/null
156 +++ b/file
157 @@ -0,0 +1 @@
158 +frotz
159 \ No newline at end of file
160 EOF
161
162 test_expect_success 'textconv does not act on symlinks' '
163 rm -f file &&
164 test_ln_s_add frotz file &&
165 git commit -m typechange &&
166 git show >diff &&
167 find_diff <diff >actual &&
168 test_cmp expect.typechange actual
169 '
170
171 test_done