]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - t/t4013-diff-various.sh
mailinfo: factor out some repeated header handling
[thirdparty/git.git] / t / t4013-diff-various.sh
... / ...
CommitLineData
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 &&
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 # 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
104 git config diff.renames false &&
105
106 git show-branch
107'
108
109: <<\EOF
110! [initial] Initial
111 * [master] Merge branch 'side'
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
121EOF
122
123V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
124while read magic cmd
125do
126 case "$magic" in
127 '' | '#'*)
128 continue ;;
129 :*)
130 magic=${magic#:}
131 label="$magic-$cmd"
132 case "$magic" in
133 noellipses) ;;
134 *)
135 BUG "unknown magic $magic" ;;
136 esac ;;
137 *)
138 cmd="$magic $cmd" magic=
139 label="$cmd" ;;
140 esac
141 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
142 pfx=$(printf "%04d" $test_count)
143 expect="$TEST_DIRECTORY/t4013/diff.$test"
144 actual="$pfx-diff.$test"
145
146 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
147 {
148 echo "$ git $cmd"
149 case "$magic" in
150 "")
151 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
152 noellipses)
153 git $cmd ;;
154 esac |
155 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
156 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
157 echo "\$"
158 } >"$actual" &&
159 if test -f "$expect"
160 then
161 case $cmd in
162 *format-patch* | *-stat*)
163 test_i18ncmp "$expect" "$actual";;
164 *)
165 test_cmp "$expect" "$actual";;
166 esac &&
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
181:noellipses diff-tree --root --abbrev initial
182diff-tree --root -r initial
183diff-tree --root -r --abbrev initial
184:noellipses diff-tree --root -r --abbrev initial
185diff-tree --root -r --abbrev=4 initial
186:noellipses diff-tree --root -r --abbrev=4 initial
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
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
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
217# improved by Timo's patch
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
226diff-tree initial mode
227diff-tree --stat initial mode
228diff-tree --summary initial mode
229
230diff-tree master
231diff-tree -p master
232diff-tree -p -m master
233diff-tree -c master
234diff-tree -c --abbrev master
235:noellipses diff-tree -c --abbrev master
236diff-tree --cc master
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
245diff-tree --cc --shortstat master
246diff-tree --cc --summary REVERSE
247# improved by Timo's patch
248diff-tree --cc --patch-with-stat master
249# improved by Timo's patch
250diff-tree --cc --patch-with-stat --summary master
251# this is correct
252diff-tree --cc --patch-with-stat --summary side
253
254log master
255log -p master
256log --root master
257log --root -p master
258log --patch-with-stat master
259log --root --patch-with-stat master
260log --root --patch-with-stat --summary master
261# improved by Timo's patch
262log --root -c --patch-with-stat --summary master
263# improved by Timo's patch
264log --root --cc --patch-with-stat --summary master
265log -p --first-parent master
266log -m -p --first-parent master
267log -m -p master
268log -SF master
269log -S F master
270log -SF -p master
271log -SF master --max-count=0
272log -SF master --max-count=1
273log -SF master --max-count=2
274log -GF master
275log -GF -p master
276log -GF -p --pickaxe-all master
277log --decorate --all
278log --decorate=full --all
279
280rev-list --parents HEAD
281rev-list --children HEAD
282
283whatchanged master
284:noellipses whatchanged master
285whatchanged -p master
286whatchanged --root master
287:noellipses whatchanged --root master
288whatchanged --root -p master
289whatchanged --patch-with-stat master
290whatchanged --root --patch-with-stat master
291whatchanged --root --patch-with-stat --summary master
292# improved by Timo's patch
293whatchanged --root -c --patch-with-stat --summary master
294# improved by Timo's patch
295whatchanged --root --cc --patch-with-stat --summary master
296whatchanged -SF master
297:noellipses whatchanged -SF master
298whatchanged -SF -p master
299
300log --patch-with-stat master -- dir/
301whatchanged --patch-with-stat master -- dir/
302log --patch-with-stat --summary master -- dir/
303whatchanged --patch-with-stat --summary master -- dir/
304
305show initial
306show --root initial
307show side
308show master
309show -c master
310show -m master
311show --first-parent master
312show --stat side
313show --stat --summary side
314show --patch-with-stat side
315show --patch-with-raw side
316:noellipses show --patch-with-raw side
317show --patch-with-stat --summary side
318
319format-patch --stdout initial..side
320format-patch --stdout initial..master^
321format-patch --stdout initial..master
322format-patch --stdout --no-numbered initial..master
323format-patch --stdout --numbered initial..master
324format-patch --attach --stdout initial..side
325format-patch --attach --stdout --suffix=.diff initial..side
326format-patch --attach --stdout initial..master^
327format-patch --attach --stdout initial..master
328format-patch --inline --stdout initial..side
329format-patch --inline --stdout initial..master^
330format-patch --inline --stdout --numbered-files initial..master
331format-patch --inline --stdout initial..master
332format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
333config format.subjectprefix DIFFERENT_PREFIX
334format-patch --inline --stdout initial..master^^
335format-patch --stdout --cover-letter -n initial..master^
336
337diff --abbrev initial..side
338diff -U initial..side
339diff -U1 initial..side
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
346:noellipses diff --patch-with-raw initial..side
347diff --patch-with-stat -r initial..side
348diff --patch-with-raw -r initial..side
349:noellipses diff --patch-with-raw -r initial..side
350diff --name-status dir2 dir
351diff --no-index --name-status dir2 dir
352diff --no-index --name-status -- dir2 dir
353diff --no-index dir dir3
354diff master master^ side
355# Can't use spaces...
356diff --line-prefix=abc master master^ side
357diff --dirstat master~1 master~2
358diff --dirstat initial rearrange
359diff --dirstat-by-file initial rearrange
360diff --dirstat --cc master~1 master
361# No-index --abbrev and --no-abbrev
362diff --raw initial
363:noellipses diff --raw initial
364diff --raw --abbrev=4 initial
365:noellipses diff --raw --abbrev=4 initial
366diff --raw --no-abbrev initial
367diff --no-index --raw dir2 dir
368:noellipses diff --no-index --raw dir2 dir
369diff --no-index --raw --abbrev=4 dir2 dir
370:noellipses diff --no-index --raw --abbrev=4 dir2 dir
371diff --no-index --raw --no-abbrev dir2 dir
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
377EOF
378
379test_expect_success 'log -S requires an argument' '
380 test_must_fail git log -S
381'
382
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'
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'
397
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
408test_done