]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4013-diff-various.sh
Merge branch 'mt/checkout-entry-dead-code-removal'
[thirdparty/git.git] / t / t4013-diff-various.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='Various diff formatting options'
7
8 . ./test-lib.sh
9
10 test_expect_success setup '
11
12 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
13 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
14 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
15
16 mkdir dir &&
17 mkdir dir2 &&
18 for i in 1 2 3; do echo $i; done >file0 &&
19 for i in A B; do echo $i; done >dir/sub &&
20 cat file0 >file2 &&
21 git add file0 file2 dir/sub &&
22 git commit -m Initial &&
23
24 git branch initial &&
25 git branch side &&
26
27 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
28 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
29 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
30
31 for i in 4 5 6; do echo $i; done >>file0 &&
32 for i in C D; do echo $i; done >>dir/sub &&
33 rm -f file2 &&
34 git update-index --remove file0 file2 dir/sub &&
35 git commit -m "Second${LF}${LF}This is the second commit." &&
36
37 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
38 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
39 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
40
41 for i in A B C; do echo $i; done >file1 &&
42 git add file1 &&
43 for i in E F; do echo $i; done >>dir/sub &&
44 git update-index dir/sub &&
45 git commit -m Third &&
46
47 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
48 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
49 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
50
51 git checkout side &&
52 for i in A B C; do echo $i; done >>file0 &&
53 for i in 1 2; do echo $i; done >>dir/sub &&
54 cat dir/sub >file3 &&
55 git add file3 &&
56 git update-index file0 dir/sub &&
57 git commit -m Side &&
58
59 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
60 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
61 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
62
63 git checkout master &&
64 git pull -s ours . side &&
65
66 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
67 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
68 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
69
70 for i in A B C; do echo $i; done >>file0 &&
71 for i in 1 2; do echo $i; done >>dir/sub &&
72 git update-index file0 dir/sub &&
73
74 mkdir dir3 &&
75 cp dir/sub dir3/sub &&
76 test-tool chmtime +1 dir3/sub &&
77
78 git config log.showroot false &&
79 git commit --amend &&
80
81 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
82 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
83 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
84 git checkout -b rearrange initial &&
85 for i in B A; do echo $i; done >dir/sub &&
86 git add dir/sub &&
87 git commit -m "Rearranged lines in dir/sub" &&
88 git checkout master &&
89
90 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
91 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
92 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
93 git checkout -b mode initial &&
94 git update-index --chmod=+x file0 &&
95 git commit -m "update mode" &&
96 git checkout -f master &&
97
98 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
99 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
100 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
101 git checkout -b note initial &&
102 git update-index --chmod=+x file2 &&
103 git commit -m "update mode (file2)" &&
104 git notes add -m "note" &&
105 git checkout -f master &&
106
107 # Same merge as master, but with parents reversed. Hide it in a
108 # pseudo-ref to avoid impacting tests with --all.
109 commit=$(echo reverse |
110 git commit-tree -p master^2 -p master^1 master^{tree}) &&
111 git update-ref REVERSE $commit &&
112
113 git config diff.renames false &&
114
115 git show-branch
116 '
117
118 : <<\EOF
119 ! [initial] Initial
120 * [master] Merge branch 'side'
121 ! [rearrange] Rearranged lines in dir/sub
122 ! [side] Side
123 ----
124 + [rearrange] Rearranged lines in dir/sub
125 - [master] Merge branch 'side'
126 * + [side] Side
127 * [master^] Third
128 * [master~2] Second
129 +*++ [initial] Initial
130 EOF
131
132 process_diffs () {
133 _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" &&
134 _x07="$_x05[0-9a-f][0-9a-f]" &&
135 sed -e "s/$OID_REGEX/$ZERO_OID/g" \
136 -e "s/From $_x40 /From $ZERO_OID /" \
137 -e "s/from $_x40)/from $ZERO_OID)/" \
138 -e "s/commit $_x40\$/commit $ZERO_OID/" \
139 -e "s/commit $_x40 (/commit $ZERO_OID (/" \
140 -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \
141 -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \
142 -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \
143 -e "s/^$_x40 /$ZERO_OID /" \
144 -e "s/^$_x40$/$ZERO_OID/" \
145 -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \
146 -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \
147 -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \
148 -e "s/$_x07 $_x07 /fffffff fffffff /g" \
149 -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \
150 -e "s/$_x07\.\.\./fffffff.../g" \
151 -e "s/ $_x04\.\.\./ ffff.../g" \
152 -e "s/ $_x04/ ffff/g" \
153 "$1"
154 }
155
156 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
157 while read magic cmd
158 do
159 case "$magic" in
160 '' | '#'*)
161 continue ;;
162 :*)
163 magic=${magic#:}
164 label="$magic-$cmd"
165 case "$magic" in
166 noellipses) ;;
167 *)
168 BUG "unknown magic $magic" ;;
169 esac ;;
170 *)
171 cmd="$magic $cmd" magic=
172 label="$cmd" ;;
173 esac
174 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
175 pfx=$(printf "%04d" $test_count)
176 expect="$TEST_DIRECTORY/t4013/diff.$test"
177 actual="$pfx-diff.$test"
178
179 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
180 {
181 echo "$ git $cmd"
182 case "$magic" in
183 "")
184 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
185 noellipses)
186 git $cmd ;;
187 esac |
188 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
189 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
190 echo "\$"
191 } >"$actual" &&
192 if test -f "$expect"
193 then
194 process_diffs "$actual" >actual &&
195 process_diffs "$expect" >expect &&
196 case $cmd in
197 *format-patch* | *-stat*)
198 test_i18ncmp expect actual;;
199 *)
200 test_cmp expect actual;;
201 esac &&
202 rm -f "$actual" actual expect
203 else
204 # this is to help developing new tests.
205 cp "$actual" "$expect"
206 false
207 fi
208 '
209 done <<\EOF
210 diff-tree initial
211 diff-tree -r initial
212 diff-tree -r --abbrev initial
213 diff-tree -r --abbrev=4 initial
214 diff-tree --root initial
215 diff-tree --root --abbrev initial
216 :noellipses diff-tree --root --abbrev initial
217 diff-tree --root -r initial
218 diff-tree --root -r --abbrev initial
219 :noellipses diff-tree --root -r --abbrev initial
220 diff-tree --root -r --abbrev=4 initial
221 :noellipses diff-tree --root -r --abbrev=4 initial
222 diff-tree -p initial
223 diff-tree --root -p initial
224 diff-tree --patch-with-stat initial
225 diff-tree --root --patch-with-stat initial
226 diff-tree --patch-with-raw initial
227 diff-tree --root --patch-with-raw initial
228
229 diff-tree --pretty initial
230 diff-tree --pretty --root initial
231 diff-tree --pretty -p initial
232 diff-tree --pretty --stat initial
233 diff-tree --pretty --summary initial
234 diff-tree --pretty --stat --summary initial
235 diff-tree --pretty --root -p initial
236 diff-tree --pretty --root --stat initial
237 # improved by Timo's patch
238 diff-tree --pretty --root --summary initial
239 # improved by Timo's patch
240 diff-tree --pretty --root --summary -r initial
241 diff-tree --pretty --root --stat --summary initial
242 diff-tree --pretty --patch-with-stat initial
243 diff-tree --pretty --root --patch-with-stat initial
244 diff-tree --pretty --patch-with-raw initial
245 diff-tree --pretty --root --patch-with-raw initial
246
247 diff-tree --pretty=oneline initial
248 diff-tree --pretty=oneline --root initial
249 diff-tree --pretty=oneline -p initial
250 diff-tree --pretty=oneline --root -p initial
251 diff-tree --pretty=oneline --patch-with-stat initial
252 # improved by Timo's patch
253 diff-tree --pretty=oneline --root --patch-with-stat initial
254 diff-tree --pretty=oneline --patch-with-raw initial
255 diff-tree --pretty=oneline --root --patch-with-raw initial
256
257 diff-tree --pretty side
258 diff-tree --pretty -p side
259 diff-tree --pretty --patch-with-stat side
260
261 diff-tree initial mode
262 diff-tree --stat initial mode
263 diff-tree --summary initial mode
264
265 diff-tree master
266 diff-tree -p master
267 diff-tree -p -m master
268 diff-tree -c master
269 diff-tree -c --abbrev master
270 :noellipses diff-tree -c --abbrev master
271 diff-tree --cc master
272 # stat only should show the diffstat with the first parent
273 diff-tree -c --stat master
274 diff-tree --cc --stat master
275 diff-tree -c --stat --summary master
276 diff-tree --cc --stat --summary master
277 # stat summary should show the diffstat and summary with the first parent
278 diff-tree -c --stat --summary side
279 diff-tree --cc --stat --summary side
280 diff-tree --cc --shortstat master
281 diff-tree --cc --summary REVERSE
282 # improved by Timo's patch
283 diff-tree --cc --patch-with-stat master
284 # improved by Timo's patch
285 diff-tree --cc --patch-with-stat --summary master
286 # this is correct
287 diff-tree --cc --patch-with-stat --summary side
288
289 log master
290 log -p master
291 log --root master
292 log --root -p master
293 log --patch-with-stat master
294 log --root --patch-with-stat master
295 log --root --patch-with-stat --summary master
296 # improved by Timo's patch
297 log --root -c --patch-with-stat --summary master
298 # improved by Timo's patch
299 log --root --cc --patch-with-stat --summary master
300 log --no-diff-merges -p --first-parent master
301 log --diff-merges=off -p --first-parent master
302 log --first-parent --diff-merges=off -p master
303 log -p --first-parent master
304 log -m -p --first-parent master
305 log -m -p master
306 log -SF master
307 log -S F master
308 log -SF -p master
309 log -SF master --max-count=0
310 log -SF master --max-count=1
311 log -SF master --max-count=2
312 log -GF master
313 log -GF -p master
314 log -GF -p --pickaxe-all master
315 log --decorate --all
316 log --decorate=full --all
317
318 rev-list --parents HEAD
319 rev-list --children HEAD
320
321 whatchanged master
322 :noellipses whatchanged master
323 whatchanged -p master
324 whatchanged --root master
325 :noellipses whatchanged --root master
326 whatchanged --root -p master
327 whatchanged --patch-with-stat master
328 whatchanged --root --patch-with-stat master
329 whatchanged --root --patch-with-stat --summary master
330 # improved by Timo's patch
331 whatchanged --root -c --patch-with-stat --summary master
332 # improved by Timo's patch
333 whatchanged --root --cc --patch-with-stat --summary master
334 whatchanged -SF master
335 :noellipses whatchanged -SF master
336 whatchanged -SF -p master
337
338 log --patch-with-stat master -- dir/
339 whatchanged --patch-with-stat master -- dir/
340 log --patch-with-stat --summary master -- dir/
341 whatchanged --patch-with-stat --summary master -- dir/
342
343 show initial
344 show --root initial
345 show side
346 show master
347 show -c master
348 show -m master
349 show --first-parent master
350 show --stat side
351 show --stat --summary side
352 show --patch-with-stat side
353 show --patch-with-raw side
354 :noellipses show --patch-with-raw side
355 show --patch-with-stat --summary side
356
357 format-patch --stdout initial..side
358 format-patch --stdout initial..master^
359 format-patch --stdout initial..master
360 format-patch --stdout --no-numbered initial..master
361 format-patch --stdout --numbered initial..master
362 format-patch --attach --stdout initial..side
363 format-patch --attach --stdout --suffix=.diff initial..side
364 format-patch --attach --stdout initial..master^
365 format-patch --attach --stdout initial..master
366 format-patch --inline --stdout initial..side
367 format-patch --inline --stdout initial..master^
368 format-patch --inline --stdout --numbered-files initial..master
369 format-patch --inline --stdout initial..master
370 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
371 config format.subjectprefix DIFFERENT_PREFIX
372 format-patch --inline --stdout initial..master^^
373 format-patch --stdout --cover-letter -n initial..master^
374
375 diff --abbrev initial..side
376 diff -U initial..side
377 diff -U1 initial..side
378 diff -r initial..side
379 diff --stat initial..side
380 diff -r --stat initial..side
381 diff initial..side
382 diff --patch-with-stat initial..side
383 diff --patch-with-raw initial..side
384 :noellipses diff --patch-with-raw initial..side
385 diff --patch-with-stat -r initial..side
386 diff --patch-with-raw -r initial..side
387 :noellipses diff --patch-with-raw -r initial..side
388 diff --name-status dir2 dir
389 diff --no-index --name-status dir2 dir
390 diff --no-index --name-status -- dir2 dir
391 diff --no-index dir dir3
392 diff master master^ side
393 # Can't use spaces...
394 diff --line-prefix=abc master master^ side
395 diff --dirstat master~1 master~2
396 diff --dirstat initial rearrange
397 diff --dirstat-by-file initial rearrange
398 diff --dirstat --cc master~1 master
399 # No-index --abbrev and --no-abbrev
400 diff --raw initial
401 :noellipses diff --raw initial
402 diff --raw --abbrev=4 initial
403 :noellipses diff --raw --abbrev=4 initial
404 diff --raw --no-abbrev initial
405 diff --no-index --raw dir2 dir
406 :noellipses diff --no-index --raw dir2 dir
407 diff --no-index --raw --abbrev=4 dir2 dir
408 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
409 diff --no-index --raw --no-abbrev dir2 dir
410
411 diff-tree --pretty --root --stat --compact-summary initial
412 diff-tree --pretty -R --root --stat --compact-summary initial
413 diff-tree --pretty note
414 diff-tree --pretty --notes note
415 diff-tree --format=%N note
416 diff-tree --stat --compact-summary initial mode
417 diff-tree -R --stat --compact-summary initial mode
418 EOF
419
420 test_expect_success 'log -S requires an argument' '
421 test_must_fail git log -S
422 '
423
424 test_expect_success 'diff --cached on unborn branch' '
425 echo ref: refs/heads/unborn >.git/HEAD &&
426 git diff --cached >result &&
427 process_diffs result >actual &&
428 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
429 test_cmp expected actual
430 '
431
432 test_expect_success 'diff --cached -- file on unborn branch' '
433 git diff --cached -- file0 >result &&
434 process_diffs result >actual &&
435 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
436 test_cmp expected actual
437 '
438 test_expect_success 'diff --line-prefix with spaces' '
439 git diff --line-prefix="| | | " --cached -- file0 >result &&
440 process_diffs result >actual &&
441 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
442 test_cmp expected actual
443 '
444
445 test_expect_success 'diff-tree --stdin with log formatting' '
446 cat >expect <<-\EOF &&
447 Side
448 Third
449 Second
450 EOF
451 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
452 test_cmp expect actual
453 '
454
455 test_done