]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - t/t4013-diff-various.sh
Merge branch 'js/default-branch-name'
[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 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
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
113 git config diff.renames false &&
114
115 git show-branch
116'
117
118: <<\EOF
119! [initial] Initial
120 * [master] Merge branch 'side' into master
121 ! [rearrange] Rearranged lines in dir/sub
122 ! [side] Side
123----
124 + [rearrange] Rearranged lines in dir/sub
125 - [master] Merge branch 'side' into master
126 * + [side] Side
127 * [master^] Third
128 * [master~2] Second
129+*++ [initial] Initial
130EOF
131
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
156V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
157while read magic cmd
158do
159 case "$magic" in
160 '' | '#'*)
161 continue ;;
162 :*)
163 magic=${magic#:}
164 label="$magic-$cmd"
165 case "$magic" in
166 noellipses) ;;
167 *)
168 BUG "unknown magic $magic" ;;
169 esac ;;
170 *)
171 cmd="$magic $cmd" magic=
172 label="$cmd" ;;
173 esac
174 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
175 pfx=$(printf "%04d" $test_count)
176 expect="$TEST_DIRECTORY/t4013/diff.$test"
177 actual="$pfx-diff.$test"
178
179 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
180 {
181 echo "$ git $cmd"
182 case "$magic" in
183 "")
184 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
185 noellipses)
186 git $cmd ;;
187 esac |
188 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
189 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
190 echo "\$"
191 } >"$actual" &&
192 if test -f "$expect"
193 then
194 process_diffs "$actual" >actual &&
195 process_diffs "$expect" >expect &&
196 case $cmd in
197 *format-patch* | *-stat*)
198 test_i18ncmp expect actual;;
199 *)
200 test_cmp expect actual;;
201 esac &&
202 rm -f "$actual" actual expect
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
216:noellipses diff-tree --root --abbrev initial
217diff-tree --root -r initial
218diff-tree --root -r --abbrev initial
219:noellipses diff-tree --root -r --abbrev initial
220diff-tree --root -r --abbrev=4 initial
221:noellipses diff-tree --root -r --abbrev=4 initial
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
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
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
252# improved by Timo's patch
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
261diff-tree initial mode
262diff-tree --stat initial mode
263diff-tree --summary initial mode
264
265diff-tree master
266diff-tree -p master
267diff-tree -p -m master
268diff-tree -c master
269diff-tree -c --abbrev master
270:noellipses diff-tree -c --abbrev master
271diff-tree --cc master
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
280diff-tree --cc --shortstat master
281diff-tree --cc --summary REVERSE
282# improved by Timo's patch
283diff-tree --cc --patch-with-stat master
284# improved by Timo's patch
285diff-tree --cc --patch-with-stat --summary master
286# this is correct
287diff-tree --cc --patch-with-stat --summary side
288
289log master
290log -p master
291log --root master
292log --root -p master
293log --patch-with-stat master
294log --root --patch-with-stat master
295log --root --patch-with-stat --summary master
296# improved by Timo's patch
297log --root -c --patch-with-stat --summary master
298# improved by Timo's patch
299log --root --cc --patch-with-stat --summary master
300log -p --first-parent master
301log -m -p --first-parent master
302log -m -p master
303log -SF master
304log -S F master
305log -SF -p master
306log -SF master --max-count=0
307log -SF master --max-count=1
308log -SF master --max-count=2
309log -GF master
310log -GF -p master
311log -GF -p --pickaxe-all master
312log --decorate --all
313log --decorate=full --all
314
315rev-list --parents HEAD
316rev-list --children HEAD
317
318whatchanged master
319:noellipses whatchanged master
320whatchanged -p master
321whatchanged --root master
322:noellipses whatchanged --root master
323whatchanged --root -p master
324whatchanged --patch-with-stat master
325whatchanged --root --patch-with-stat master
326whatchanged --root --patch-with-stat --summary master
327# improved by Timo's patch
328whatchanged --root -c --patch-with-stat --summary master
329# improved by Timo's patch
330whatchanged --root --cc --patch-with-stat --summary master
331whatchanged -SF master
332:noellipses whatchanged -SF master
333whatchanged -SF -p master
334
335log --patch-with-stat master -- dir/
336whatchanged --patch-with-stat master -- dir/
337log --patch-with-stat --summary master -- dir/
338whatchanged --patch-with-stat --summary master -- dir/
339
340show initial
341show --root initial
342show side
343show master
344show -c master
345show -m master
346show --first-parent master
347show --stat side
348show --stat --summary side
349show --patch-with-stat side
350show --patch-with-raw side
351:noellipses show --patch-with-raw side
352show --patch-with-stat --summary side
353
354format-patch --stdout initial..side
355format-patch --stdout initial..master^
356format-patch --stdout initial..master
357format-patch --stdout --no-numbered initial..master
358format-patch --stdout --numbered initial..master
359format-patch --attach --stdout initial..side
360format-patch --attach --stdout --suffix=.diff initial..side
361format-patch --attach --stdout initial..master^
362format-patch --attach --stdout initial..master
363format-patch --inline --stdout initial..side
364format-patch --inline --stdout initial..master^
365format-patch --inline --stdout --numbered-files initial..master
366format-patch --inline --stdout initial..master
367format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
368config format.subjectprefix DIFFERENT_PREFIX
369format-patch --inline --stdout initial..master^^
370format-patch --stdout --cover-letter -n initial..master^
371
372diff --abbrev initial..side
373diff -U initial..side
374diff -U1 initial..side
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
381:noellipses diff --patch-with-raw initial..side
382diff --patch-with-stat -r initial..side
383diff --patch-with-raw -r initial..side
384:noellipses diff --patch-with-raw -r initial..side
385diff --name-status dir2 dir
386diff --no-index --name-status dir2 dir
387diff --no-index --name-status -- dir2 dir
388diff --no-index dir dir3
389diff master master^ side
390# Can't use spaces...
391diff --line-prefix=abc master master^ side
392diff --dirstat master~1 master~2
393diff --dirstat initial rearrange
394diff --dirstat-by-file initial rearrange
395diff --dirstat --cc master~1 master
396# No-index --abbrev and --no-abbrev
397diff --raw initial
398:noellipses diff --raw initial
399diff --raw --abbrev=4 initial
400:noellipses diff --raw --abbrev=4 initial
401diff --raw --no-abbrev initial
402diff --no-index --raw dir2 dir
403:noellipses diff --no-index --raw dir2 dir
404diff --no-index --raw --abbrev=4 dir2 dir
405:noellipses diff --no-index --raw --abbrev=4 dir2 dir
406diff --no-index --raw --no-abbrev dir2 dir
407
408diff-tree --pretty --root --stat --compact-summary initial
409diff-tree --pretty -R --root --stat --compact-summary initial
410diff-tree --pretty note
411diff-tree --pretty --notes note
412diff-tree --format=%N note
413diff-tree --stat --compact-summary initial mode
414diff-tree -R --stat --compact-summary initial mode
415EOF
416
417test_expect_success 'log -S requires an argument' '
418 test_must_fail git log -S
419'
420
421test_expect_success 'diff --cached on unborn branch' '
422 echo ref: refs/heads/unborn >.git/HEAD &&
423 git diff --cached >result &&
424 process_diffs result >actual &&
425 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
426 test_cmp expected actual
427'
428
429test_expect_success 'diff --cached -- file on unborn branch' '
430 git diff --cached -- file0 >result &&
431 process_diffs result >actual &&
432 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
433 test_cmp expected actual
434'
435test_expect_success 'diff --line-prefix with spaces' '
436 git diff --line-prefix="| | | " --cached -- file0 >result &&
437 process_diffs result >actual &&
438 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
439 test_cmp expected actual
440'
441
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
452test_done