]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4013-diff-various.sh
path.c: don't call the match function without value in trie_find()
[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
a40d384c
JH
10LF='
11'
12
3c2f75b5
JH
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 &&
3cb56738 20 mkdir dir2 &&
3c2f75b5
JH
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 &&
a40d384c 38 git commit -m "Second${LF}${LF}This is the second commit." &&
3c2f75b5
JH
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
d61027b2
MS
77 mkdir dir3 &&
78 cp dir/sub dir3/sub &&
0e496492 79 test-tool chmtime +1 dir3/sub &&
d61027b2 80
e0d10e1c 81 git config log.showroot false &&
8ff99e74 82 git commit --amend &&
204f01a2
JH
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
58aaced4
SB
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
04b19fca
JK
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
5404c116
MM
107 git config diff.renames false &&
108
3c2f75b5
JH
109 git show-branch
110'
111
112: <<\EOF
113! [initial] Initial
114 * [master] Merge branch 'side'
204f01a2
JH
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
3c2f75b5
JH
124EOF
125
4ff03347 126V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
b4c02c30 127while read magic cmd
3c2f75b5 128do
b4c02c30
AR
129 case "$magic" in
130 '' | '#'*)
131 continue ;;
132 :*)
133 magic=${magic#:}
134 label="$magic-$cmd"
135 case "$magic" in
136 noellipses) ;;
137 *)
165293af 138 BUG "unknown magic $magic" ;;
b4c02c30
AR
139 esac ;;
140 *)
141 cmd="$magic $cmd" magic=
142 label="$cmd" ;;
3c2f75b5 143 esac
b4c02c30 144 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
4ff03347 145 pfx=$(printf "%04d" $test_count)
bfdbee98 146 expect="$TEST_DIRECTORY/t4013/diff.$test"
3c2f75b5
JH
147 actual="$pfx-diff.$test"
148
de231e57 149 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
3c2f75b5 150 {
b4c02c30
AR
151 echo "$ git $cmd"
152 case "$magic" in
153 "")
154 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
155 noellipses)
156 git $cmd ;;
157 esac |
6c7f4ceb 158 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
33ee4cfb 159 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
3c2f75b5
JH
160 echo "\$"
161 } >"$actual" &&
162 if test -f "$expect"
163 then
6dd88832
JN
164 case $cmd in
165 *format-patch* | *-stat*)
166 test_i18ncmp "$expect" "$actual";;
167 *)
168 test_cmp "$expect" "$actual";;
169 esac &&
3c2f75b5
JH
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
c2f1d398 184:noellipses diff-tree --root --abbrev initial
3c2f75b5
JH
185diff-tree --root -r initial
186diff-tree --root -r --abbrev initial
c2f1d398 187:noellipses diff-tree --root -r --abbrev initial
3c2f75b5 188diff-tree --root -r --abbrev=4 initial
c2f1d398 189:noellipses diff-tree --root -r --abbrev=4 initial
3c2f75b5
JH
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
026625e7
JH
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
3c2f75b5
JH
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
026625e7 220# improved by Timo's patch
3c2f75b5
JH
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
58aaced4
SB
229diff-tree initial mode
230diff-tree --stat initial mode
231diff-tree --summary initial mode
232
3c2f75b5
JH
233diff-tree master
234diff-tree -p master
235diff-tree -p -m master
236diff-tree -c master
237diff-tree -c --abbrev master
c2f1d398 238:noellipses diff-tree -c --abbrev master
3c2f75b5 239diff-tree --cc master
47979d5d
JH
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
8290faa0 248diff-tree --cc --shortstat master
04b19fca 249diff-tree --cc --summary REVERSE
026625e7
JH
250# improved by Timo's patch
251diff-tree --cc --patch-with-stat master
252# improved by Timo's patch
47979d5d
JH
253diff-tree --cc --patch-with-stat --summary master
254# this is correct
255diff-tree --cc --patch-with-stat --summary side
3c2f75b5
JH
256
257log master
258log -p master
259log --root master
260log --root -p master
261log --patch-with-stat master
262log --root --patch-with-stat master
47979d5d 263log --root --patch-with-stat --summary master
026625e7 264# improved by Timo's patch
47979d5d 265log --root -c --patch-with-stat --summary master
026625e7 266# improved by Timo's patch
47979d5d 267log --root --cc --patch-with-stat --summary master
126f431a
JH
268log -p --first-parent master
269log -m -p --first-parent master
270log -m -p master
3c2f75b5 271log -SF master
dea007fb 272log -S F master
47979d5d 273log -SF -p master
251df09b
MM
274log -SF master --max-count=0
275log -SF master --max-count=1
276log -SF master --max-count=2
bf1dfc31
JH
277log -GF master
278log -GF -p master
279log -GF -p --pickaxe-all master
28fd76bd 280log --decorate --all
33e7018c 281log --decorate=full --all
3c2f75b5 282
fcbc6efc
TR
283rev-list --parents HEAD
284rev-list --children HEAD
3c2f75b5
JH
285
286whatchanged master
c2f1d398 287:noellipses whatchanged master
3c2f75b5
JH
288whatchanged -p master
289whatchanged --root master
c2f1d398 290:noellipses whatchanged --root master
3c2f75b5
JH
291whatchanged --root -p master
292whatchanged --patch-with-stat master
293whatchanged --root --patch-with-stat master
294whatchanged --root --patch-with-stat --summary master
026625e7 295# improved by Timo's patch
47979d5d 296whatchanged --root -c --patch-with-stat --summary master
026625e7 297# improved by Timo's patch
47979d5d 298whatchanged --root --cc --patch-with-stat --summary master
3c2f75b5 299whatchanged -SF master
c2f1d398 300:noellipses whatchanged -SF master
47979d5d 301whatchanged -SF -p master
3c2f75b5
JH
302
303log --patch-with-stat master -- dir/
304whatchanged --patch-with-stat master -- dir/
47979d5d
JH
305log --patch-with-stat --summary master -- dir/
306whatchanged --patch-with-stat --summary master -- dir/
3c2f75b5
JH
307
308show initial
309show --root initial
310show side
311show master
b4490059 312show -c master
2bf65873
JH
313show -m master
314show --first-parent master
3c2f75b5
JH
315show --stat side
316show --stat --summary side
317show --patch-with-stat side
318show --patch-with-raw side
c2f1d398 319:noellipses show --patch-with-raw side
3c2f75b5
JH
320show --patch-with-stat --summary side
321
d410e43b
JH
322format-patch --stdout initial..side
323format-patch --stdout initial..master^
324format-patch --stdout initial..master
a567fdcb
BG
325format-patch --stdout --no-numbered initial..master
326format-patch --stdout --numbered initial..master
d410e43b 327format-patch --attach --stdout initial..side
108dab28 328format-patch --attach --stdout --suffix=.diff initial..side
d410e43b
JH
329format-patch --attach --stdout initial..master^
330format-patch --attach --stdout initial..master
c112f689
JS
331format-patch --inline --stdout initial..side
332format-patch --inline --stdout initial..master^
747e2505 333format-patch --inline --stdout --numbered-files initial..master
a567fdcb 334format-patch --inline --stdout initial..master
171ddd91 335format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
dbd21447
AR
336config format.subjectprefix DIFFERENT_PREFIX
337format-patch --inline --stdout initial..master^^
a5a27c79 338format-patch --stdout --cover-letter -n initial..master^
d410e43b 339
b319b02e 340diff --abbrev initial..side
8ef05193
NTND
341diff -U initial..side
342diff -U1 initial..side
b319b02e
JH
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
c2f1d398 349:noellipses diff --patch-with-raw initial..side
b319b02e
JH
350diff --patch-with-stat -r initial..side
351diff --patch-with-raw -r initial..side
c2f1d398 352:noellipses diff --patch-with-raw -r initial..side
3cb56738 353diff --name-status dir2 dir
0569e9b8 354diff --no-index --name-status dir2 dir
e423ffd8 355diff --no-index --name-status -- dir2 dir
d61027b2 356diff --no-index dir dir3
b75271d9 357diff master master^ side
660e113c
JK
358# Can't use spaces...
359diff --line-prefix=abc master master^ side
f37bfb7a 360diff --dirstat master~1 master~2
204f01a2 361diff --dirstat initial rearrange
0133dab7 362diff --dirstat-by-file initial rearrange
dac03b55 363diff --dirstat --cc master~1 master
43d1948b
JB
364# No-index --abbrev and --no-abbrev
365diff --raw initial
c2f1d398 366:noellipses diff --raw initial
43d1948b 367diff --raw --abbrev=4 initial
c2f1d398 368:noellipses diff --raw --abbrev=4 initial
43d1948b
JB
369diff --raw --no-abbrev initial
370diff --no-index --raw dir2 dir
c2f1d398 371:noellipses diff --no-index --raw dir2 dir
43d1948b 372diff --no-index --raw --abbrev=4 dir2 dir
c2f1d398 373:noellipses diff --no-index --raw --abbrev=4 dir2 dir
43d1948b 374diff --no-index --raw --no-abbrev dir2 dir
ddf88fa6
NTND
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
3c2f75b5
JH
380EOF
381
dea007fb
MM
382test_expect_success 'log -S requires an argument' '
383 test_must_fail git log -S
384'
385
a2b7a3b3
NTND
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'
660e113c
JK
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'
a2b7a3b3 400
d299e9e5
JK
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
3c2f75b5 411test_done