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