]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4020-diff-external.sh
path.c: don't call the match function without value in trie_find()
[thirdparty/git.git] / t / t4020-diff-external.sh
CommitLineData
f1af60bd
JH
1#!/bin/sh
2
3test_description='external diff interface test'
4
5. ./test-lib.sh
6
f1af60bd
JH
7test_expect_success setup '
8
9 test_tick &&
10 echo initial >file &&
11 git add file &&
12 git commit -m initial &&
13
14 test_tick &&
15 echo second >file &&
f2fffc17 16 before=$(git hash-object file) &&
17 before=$(git rev-parse --short $before) &&
f1af60bd
JH
18 git add file &&
19 git commit -m second &&
20
21 test_tick &&
22 echo third >file
23'
24
25test_expect_success 'GIT_EXTERNAL_DIFF environment' '
26
27 GIT_EXTERNAL_DIFF=echo git diff | {
28 read path oldfile oldhex oldmode newfile newhex newmode &&
29 test "z$path" = zfile &&
30 test "z$oldmode" = z100644 &&
8125a58b 31 test "z$newhex" = "z$ZERO_OID" &&
f1af60bd
JH
32 test "z$newmode" = z100644 &&
33 oh=$(git rev-parse --verify HEAD:file) &&
34 test "z$oh" = "z$oldhex"
35 }
36
37'
38
39test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
40
41 GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
42 grep "^diff --git a/file b/file"
43
44'
45
61af494c
JH
46test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
47
48 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
49 grep "^diff --git a/file b/file"
50
51'
52
bd8c1a9b
JH
53test_expect_success SYMLINKS 'typechange diff' '
54 rm -f file &&
55 ln -s elif file &&
56 GIT_EXTERNAL_DIFF=echo git diff | {
57 read path oldfile oldhex oldmode newfile newhex newmode &&
58 test "z$path" = zfile &&
59 test "z$oldmode" = z100644 &&
8125a58b 60 test "z$newhex" = "z$ZERO_OID" &&
bd8c1a9b
JH
61 test "z$newmode" = z120000 &&
62 oh=$(git rev-parse --verify HEAD:file) &&
63 test "z$oh" = "z$oldhex"
64 } &&
65 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
66 git diff >expect &&
67 test_cmp expect actual
68'
69
c12f82ae
JK
70test_expect_success 'diff.external' '
71 git reset --hard &&
72 echo third >file &&
73 test_config diff.external echo &&
74 git diff | {
75 read path oldfile oldhex oldmode newfile newhex newmode &&
76 test "z$path" = zfile &&
77 test "z$oldmode" = z100644 &&
8125a58b 78 test "z$newhex" = "z$ZERO_OID" &&
c12f82ae
JK
79 test "z$newmode" = z100644 &&
80 oh=$(git rev-parse --verify HEAD:file) &&
81 test "z$oh" = "z$oldhex"
82 }
83'
84
85test_expect_success 'diff.external should apply only to diff' '
86 test_config diff.external echo &&
87 git log -p -1 HEAD |
88 grep "^diff --git a/file b/file"
89'
90
91test_expect_success 'diff.external and --no-ext-diff' '
92 test_config diff.external echo &&
93 git diff --no-ext-diff |
94 grep "^diff --git a/file b/file"
95'
96
f1af60bd 97test_expect_success 'diff attribute' '
bd8c1a9b
JH
98 git reset --hard &&
99 echo third >file &&
f1af60bd
JH
100
101 git config diff.parrot.command echo &&
102
103 echo >.gitattributes "file diff=parrot" &&
104
105 git diff | {
106 read path oldfile oldhex oldmode newfile newhex newmode &&
107 test "z$path" = zfile &&
108 test "z$oldmode" = z100644 &&
8125a58b 109 test "z$newhex" = "z$ZERO_OID" &&
f1af60bd
JH
110 test "z$newmode" = z100644 &&
111 oh=$(git rev-parse --verify HEAD:file) &&
112 test "z$oh" = "z$oldhex"
113 }
114
115'
116
117test_expect_success 'diff attribute should apply only to diff' '
118
119 git log -p -1 HEAD |
120 grep "^diff --git a/file b/file"
121
122'
123
61af494c
JH
124test_expect_success 'diff attribute and --no-ext-diff' '
125
126 git diff --no-ext-diff |
127 grep "^diff --git a/file b/file"
128
129'
130
f1af60bd
JH
131test_expect_success 'diff attribute' '
132
133 git config --unset diff.parrot.command &&
134 git config diff.color.command echo &&
135
136 echo >.gitattributes "file diff=color" &&
137
138 git diff | {
139 read path oldfile oldhex oldmode newfile newhex newmode &&
140 test "z$path" = zfile &&
141 test "z$oldmode" = z100644 &&
8125a58b 142 test "z$newhex" = "z$ZERO_OID" &&
f1af60bd
JH
143 test "z$newmode" = z100644 &&
144 oh=$(git rev-parse --verify HEAD:file) &&
145 test "z$oh" = "z$oldhex"
146 }
147
148'
149
150test_expect_success 'diff attribute should apply only to diff' '
151
152 git log -p -1 HEAD |
153 grep "^diff --git a/file b/file"
154
155'
156
61af494c
JH
157test_expect_success 'diff attribute and --no-ext-diff' '
158
159 git diff --no-ext-diff |
160 grep "^diff --git a/file b/file"
161
162'
163
c12f82ae
JK
164test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
165 >.gitattributes &&
166 test_config diff.external "echo ext-global" &&
167 GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
168'
169
170test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
171 test_config diff.foo.command "echo ext-attribute" &&
172 test_config diff.external "echo ext-global" &&
173 echo "file diff=foo" >.gitattributes &&
174 GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
175'
176
2c3fa66f
JH
177test_expect_success 'no diff with -diff' '
178 echo >.gitattributes "file -diff" &&
179 git diff | grep Binary
180'
181
94221d22 182echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
2c3fa66f
JH
183
184test_expect_success 'force diff with "diff"' '
f2fffc17 185 after=$(git hash-object file) &&
186 after=$(git rev-parse --short $after) &&
2c3fa66f 187 echo >.gitattributes "file diff" &&
53a5b443 188 git diff >actual &&
f2fffc17 189 sed -e "s/^index .*/index $before..$after 100644/" \
190 "$TEST_DIRECTORY"/t4020/diff.NUL >expected-diff &&
191 test_cmp expected-diff actual
2c3fa66f
JH
192'
193
a8344abe
NR
194test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
195 echo anotherfile > file2 &&
196 git add file2 &&
197 git commit -m "added 2nd file" &&
198 echo modified >file2 &&
199 GIT_EXTERNAL_DIFF=echo git diff
200'
201
ee7fb0b1
ZK
202test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' '
203 write_script external-diff.sh <<-\EOF &&
204 echo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt
205 EOF
206 >counter.txt &&
207 cat >expect <<-\EOF &&
208 1 of 2
209 2 of 2
210 EOF
211 GIT_EXTERNAL_DIFF=./external-diff.sh git diff &&
212 test_cmp expect counter.txt
213'
214
003b33a8
DA
215test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
216 touch file.ext &&
217 git add file.ext &&
218 echo with extension > file.ext &&
219 GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
220 git update-index --force-remove file.ext &&
221 rm file.ext
222'
223
4e218f54
JS
224echo "#!$SHELL_PATH" >fake-diff.sh
225cat >> fake-diff.sh <<\EOF
226cat $2 >> crlfed.txt
227EOF
228chmod a+x fake-diff.sh
229
230keep_only_cr () {
231 tr -dc '\015'
232}
233
234test_expect_success 'external diff with autocrlf = true' '
aba47272 235 test_config core.autocrlf true &&
4e218f54
JS
236 GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
237 test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
238'
239
150115ad 240test_expect_success 'diff --cached' '
aba47272 241 test_config core.autocrlf true &&
150115ad
JH
242 git add file &&
243 git update-index --assume-unchanged file &&
244 echo second >file &&
245 git diff --cached >actual &&
f2fffc17 246 test_cmp expected-diff actual
150115ad
JH
247'
248
aba47272
TR
249test_expect_success 'clean up crlf leftovers' '
250 git update-index --no-assume-unchanged file &&
251 rm -f file* &&
252 git reset --hard
253'
254
255test_expect_success 'submodule diff' '
256 git init sub &&
257 ( cd sub && test_commit sub1 ) &&
258 git add sub &&
259 test_tick &&
260 git commit -m "add submodule" &&
261 ( cd sub && test_commit sub2 ) &&
262 write_script gather_pre_post.sh <<-\EOF &&
263 echo "$1 $4" # path, mode
264 cat "$2" # old file
265 cat "$5" # new file
266 EOF
267 GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&
268 cat >expected <<-EOF &&
269 sub 160000
270 Subproject commit $(git rev-parse HEAD:sub)
271 Subproject commit $(cd sub && git rev-parse HEAD)
272 EOF
273 test_cmp expected actual
274'
275
f1af60bd 276test_done