]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4013-diff-various.sh
Merge branch 'js/default-branch-name'
[thirdparty/git.git] / t / t4013-diff-various.sh
CommitLineData
3c2f75b5
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Various diff formatting options'
7
8. ./test-lib.sh
9
10test_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 &&
3cb56738 17 mkdir dir2 &&
3c2f75b5
JH
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 &&
a40d384c 35 git commit -m "Second${LF}${LF}This is the second commit." &&
3c2f75b5
JH
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
d61027b2
MS
74 mkdir dir3 &&
75 cp dir/sub dir3/sub &&
0e496492 76 test-tool chmtime +1 dir3/sub &&
d61027b2 77
e0d10e1c 78 git config log.showroot false &&
8ff99e74 79 git commit --amend &&
204f01a2
JH
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
58aaced4
SB
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
5778b22b
TB
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
04b19fca
JK
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
5404c116
MM
113 git config diff.renames false &&
114
3c2f75b5
JH
115 git show-branch
116'
117
118: <<\EOF
119! [initial] Initial
489947ce 120 * [master] Merge branch 'side' into master
204f01a2
JH
121 ! [rearrange] Rearranged lines in dir/sub
122 ! [side] Side
123----
124 + [rearrange] Rearranged lines in dir/sub
489947ce 125 - [master] Merge branch 'side' into master
204f01a2
JH
126 * + [side] Side
127 * [master^] Third
128 * [master~2] Second
129+*++ [initial] Initial
3c2f75b5
JH
130EOF
131
72f936b1 132process_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
4ff03347 156V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
b4c02c30 157while read magic cmd
3c2f75b5 158do
b4c02c30
AR
159 case "$magic" in
160 '' | '#'*)
161 continue ;;
162 :*)
163 magic=${magic#:}
164 label="$magic-$cmd"
165 case "$magic" in
166 noellipses) ;;
167 *)
165293af 168 BUG "unknown magic $magic" ;;
b4c02c30
AR
169 esac ;;
170 *)
171 cmd="$magic $cmd" magic=
172 label="$cmd" ;;
3c2f75b5 173 esac
b4c02c30 174 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
4ff03347 175 pfx=$(printf "%04d" $test_count)
bfdbee98 176 expect="$TEST_DIRECTORY/t4013/diff.$test"
3c2f75b5
JH
177 actual="$pfx-diff.$test"
178
de231e57 179 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
3c2f75b5 180 {
b4c02c30
AR
181 echo "$ git $cmd"
182 case "$magic" in
183 "")
184 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
185 noellipses)
186 git $cmd ;;
187 esac |
6c7f4ceb 188 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
33ee4cfb 189 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
3c2f75b5
JH
190 echo "\$"
191 } >"$actual" &&
192 if test -f "$expect"
193 then
72f936b1 194 process_diffs "$actual" >actual &&
195 process_diffs "$expect" >expect &&
6dd88832
JN
196 case $cmd in
197 *format-patch* | *-stat*)
72f936b1 198 test_i18ncmp expect actual;;
6dd88832 199 *)
72f936b1 200 test_cmp expect actual;;
6dd88832 201 esac &&
72f936b1 202 rm -f "$actual" actual expect
3c2f75b5
JH
203 else
204 # this is to help developing new tests.
205 cp "$actual" "$expect"
206 false
207 fi
208 '
209done <<\EOF
210diff-tree initial
211diff-tree -r initial
212diff-tree -r --abbrev initial
213diff-tree -r --abbrev=4 initial
214diff-tree --root initial
215diff-tree --root --abbrev initial
c2f1d398 216:noellipses diff-tree --root --abbrev initial
3c2f75b5
JH
217diff-tree --root -r initial
218diff-tree --root -r --abbrev initial
c2f1d398 219:noellipses diff-tree --root -r --abbrev initial
3c2f75b5 220diff-tree --root -r --abbrev=4 initial
c2f1d398 221:noellipses diff-tree --root -r --abbrev=4 initial
3c2f75b5
JH
222diff-tree -p initial
223diff-tree --root -p initial
224diff-tree --patch-with-stat initial
225diff-tree --root --patch-with-stat initial
226diff-tree --patch-with-raw initial
227diff-tree --root --patch-with-raw initial
228
229diff-tree --pretty initial
230diff-tree --pretty --root initial
231diff-tree --pretty -p initial
232diff-tree --pretty --stat initial
233diff-tree --pretty --summary initial
234diff-tree --pretty --stat --summary initial
235diff-tree --pretty --root -p initial
236diff-tree --pretty --root --stat initial
026625e7
JH
237# improved by Timo's patch
238diff-tree --pretty --root --summary initial
239# improved by Timo's patch
240diff-tree --pretty --root --summary -r initial
3c2f75b5
JH
241diff-tree --pretty --root --stat --summary initial
242diff-tree --pretty --patch-with-stat initial
243diff-tree --pretty --root --patch-with-stat initial
244diff-tree --pretty --patch-with-raw initial
245diff-tree --pretty --root --patch-with-raw initial
246
247diff-tree --pretty=oneline initial
248diff-tree --pretty=oneline --root initial
249diff-tree --pretty=oneline -p initial
250diff-tree --pretty=oneline --root -p initial
251diff-tree --pretty=oneline --patch-with-stat initial
026625e7 252# improved by Timo's patch
3c2f75b5
JH
253diff-tree --pretty=oneline --root --patch-with-stat initial
254diff-tree --pretty=oneline --patch-with-raw initial
255diff-tree --pretty=oneline --root --patch-with-raw initial
256
257diff-tree --pretty side
258diff-tree --pretty -p side
259diff-tree --pretty --patch-with-stat side
260
58aaced4
SB
261diff-tree initial mode
262diff-tree --stat initial mode
263diff-tree --summary initial mode
264
3c2f75b5
JH
265diff-tree master
266diff-tree -p master
267diff-tree -p -m master
268diff-tree -c master
269diff-tree -c --abbrev master
c2f1d398 270:noellipses diff-tree -c --abbrev master
3c2f75b5 271diff-tree --cc master
47979d5d
JH
272# stat only should show the diffstat with the first parent
273diff-tree -c --stat master
274diff-tree --cc --stat master
275diff-tree -c --stat --summary master
276diff-tree --cc --stat --summary master
277# stat summary should show the diffstat and summary with the first parent
278diff-tree -c --stat --summary side
279diff-tree --cc --stat --summary side
8290faa0 280diff-tree --cc --shortstat master
04b19fca 281diff-tree --cc --summary REVERSE
026625e7
JH
282# improved by Timo's patch
283diff-tree --cc --patch-with-stat master
284# improved by Timo's patch
47979d5d
JH
285diff-tree --cc --patch-with-stat --summary master
286# this is correct
287diff-tree --cc --patch-with-stat --summary side
3c2f75b5
JH
288
289log master
290log -p master
291log --root master
292log --root -p master
293log --patch-with-stat master
294log --root --patch-with-stat master
47979d5d 295log --root --patch-with-stat --summary master
026625e7 296# improved by Timo's patch
47979d5d 297log --root -c --patch-with-stat --summary master
026625e7 298# improved by Timo's patch
47979d5d 299log --root --cc --patch-with-stat --summary master
126f431a
JH
300log -p --first-parent master
301log -m -p --first-parent master
302log -m -p master
3c2f75b5 303log -SF master
dea007fb 304log -S F master
47979d5d 305log -SF -p master
251df09b
MM
306log -SF master --max-count=0
307log -SF master --max-count=1
308log -SF master --max-count=2
bf1dfc31
JH
309log -GF master
310log -GF -p master
311log -GF -p --pickaxe-all master
28fd76bd 312log --decorate --all
33e7018c 313log --decorate=full --all
3c2f75b5 314
fcbc6efc
TR
315rev-list --parents HEAD
316rev-list --children HEAD
3c2f75b5
JH
317
318whatchanged master
c2f1d398 319:noellipses whatchanged master
3c2f75b5
JH
320whatchanged -p master
321whatchanged --root master
c2f1d398 322:noellipses whatchanged --root master
3c2f75b5
JH
323whatchanged --root -p master
324whatchanged --patch-with-stat master
325whatchanged --root --patch-with-stat master
326whatchanged --root --patch-with-stat --summary master
026625e7 327# improved by Timo's patch
47979d5d 328whatchanged --root -c --patch-with-stat --summary master
026625e7 329# improved by Timo's patch
47979d5d 330whatchanged --root --cc --patch-with-stat --summary master
3c2f75b5 331whatchanged -SF master
c2f1d398 332:noellipses whatchanged -SF master
47979d5d 333whatchanged -SF -p master
3c2f75b5
JH
334
335log --patch-with-stat master -- dir/
336whatchanged --patch-with-stat master -- dir/
47979d5d
JH
337log --patch-with-stat --summary master -- dir/
338whatchanged --patch-with-stat --summary master -- dir/
3c2f75b5
JH
339
340show initial
341show --root initial
342show side
343show master
b4490059 344show -c master
2bf65873
JH
345show -m master
346show --first-parent master
3c2f75b5
JH
347show --stat side
348show --stat --summary side
349show --patch-with-stat side
350show --patch-with-raw side
c2f1d398 351:noellipses show --patch-with-raw side
3c2f75b5
JH
352show --patch-with-stat --summary side
353
d410e43b
JH
354format-patch --stdout initial..side
355format-patch --stdout initial..master^
356format-patch --stdout initial..master
a567fdcb
BG
357format-patch --stdout --no-numbered initial..master
358format-patch --stdout --numbered initial..master
d410e43b 359format-patch --attach --stdout initial..side
108dab28 360format-patch --attach --stdout --suffix=.diff initial..side
d410e43b
JH
361format-patch --attach --stdout initial..master^
362format-patch --attach --stdout initial..master
c112f689
JS
363format-patch --inline --stdout initial..side
364format-patch --inline --stdout initial..master^
747e2505 365format-patch --inline --stdout --numbered-files initial..master
a567fdcb 366format-patch --inline --stdout initial..master
171ddd91 367format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
dbd21447
AR
368config format.subjectprefix DIFFERENT_PREFIX
369format-patch --inline --stdout initial..master^^
a5a27c79 370format-patch --stdout --cover-letter -n initial..master^
d410e43b 371
b319b02e 372diff --abbrev initial..side
8ef05193
NTND
373diff -U initial..side
374diff -U1 initial..side
b319b02e
JH
375diff -r initial..side
376diff --stat initial..side
377diff -r --stat initial..side
378diff initial..side
379diff --patch-with-stat initial..side
380diff --patch-with-raw initial..side
c2f1d398 381:noellipses diff --patch-with-raw initial..side
b319b02e
JH
382diff --patch-with-stat -r initial..side
383diff --patch-with-raw -r initial..side
c2f1d398 384:noellipses diff --patch-with-raw -r initial..side
3cb56738 385diff --name-status dir2 dir
0569e9b8 386diff --no-index --name-status dir2 dir
e423ffd8 387diff --no-index --name-status -- dir2 dir
d61027b2 388diff --no-index dir dir3
b75271d9 389diff master master^ side
660e113c
JK
390# Can't use spaces...
391diff --line-prefix=abc master master^ side
f37bfb7a 392diff --dirstat master~1 master~2
204f01a2 393diff --dirstat initial rearrange
0133dab7 394diff --dirstat-by-file initial rearrange
dac03b55 395diff --dirstat --cc master~1 master
43d1948b
JB
396# No-index --abbrev and --no-abbrev
397diff --raw initial
c2f1d398 398:noellipses diff --raw initial
43d1948b 399diff --raw --abbrev=4 initial
c2f1d398 400:noellipses diff --raw --abbrev=4 initial
43d1948b
JB
401diff --raw --no-abbrev initial
402diff --no-index --raw dir2 dir
c2f1d398 403:noellipses diff --no-index --raw dir2 dir
43d1948b 404diff --no-index --raw --abbrev=4 dir2 dir
c2f1d398 405:noellipses diff --no-index --raw --abbrev=4 dir2 dir
43d1948b 406diff --no-index --raw --no-abbrev dir2 dir
ddf88fa6
NTND
407
408diff-tree --pretty --root --stat --compact-summary initial
409diff-tree --pretty -R --root --stat --compact-summary initial
5778b22b
TB
410diff-tree --pretty note
411diff-tree --pretty --notes note
412diff-tree --format=%N note
ddf88fa6
NTND
413diff-tree --stat --compact-summary initial mode
414diff-tree -R --stat --compact-summary initial mode
3c2f75b5
JH
415EOF
416
dea007fb
MM
417test_expect_success 'log -S requires an argument' '
418 test_must_fail git log -S
419'
420
a2b7a3b3
NTND
421test_expect_success 'diff --cached on unborn branch' '
422 echo ref: refs/heads/unborn >.git/HEAD &&
423 git diff --cached >result &&
72f936b1 424 process_diffs result >actual &&
425 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
426 test_cmp expected actual
a2b7a3b3
NTND
427'
428
429test_expect_success 'diff --cached -- file on unborn branch' '
430 git diff --cached -- file0 >result &&
72f936b1 431 process_diffs result >actual &&
432 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
433 test_cmp expected actual
a2b7a3b3 434'
660e113c
JK
435test_expect_success 'diff --line-prefix with spaces' '
436 git diff --line-prefix="| | | " --cached -- file0 >result &&
72f936b1 437 process_diffs result >actual &&
438 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
439 test_cmp expected actual
660e113c 440'
a2b7a3b3 441
d299e9e5
JK
442test_expect_success 'diff-tree --stdin with log formatting' '
443 cat >expect <<-\EOF &&
444 Side
445 Third
446 Second
447 EOF
448 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
449 test_cmp expect actual
450'
451
3c2f75b5 452test_done