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