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