]> git.ipfire.org Git - thirdparty/git.git/blob - 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
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='Various diff formatting options'
7
8 . ./test-lib.sh
9
10 LF='
11 '
12
13 test_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
124 EOF
125
126 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
127 while read magic cmd
128 do
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 '
177 done <<\EOF
178 diff-tree initial
179 diff-tree -r initial
180 diff-tree -r --abbrev initial
181 diff-tree -r --abbrev=4 initial
182 diff-tree --root initial
183 diff-tree --root --abbrev initial
184 :noellipses diff-tree --root --abbrev initial
185 diff-tree --root -r initial
186 diff-tree --root -r --abbrev initial
187 :noellipses diff-tree --root -r --abbrev initial
188 diff-tree --root -r --abbrev=4 initial
189 :noellipses diff-tree --root -r --abbrev=4 initial
190 diff-tree -p initial
191 diff-tree --root -p initial
192 diff-tree --patch-with-stat initial
193 diff-tree --root --patch-with-stat initial
194 diff-tree --patch-with-raw initial
195 diff-tree --root --patch-with-raw initial
196
197 diff-tree --pretty initial
198 diff-tree --pretty --root initial
199 diff-tree --pretty -p initial
200 diff-tree --pretty --stat initial
201 diff-tree --pretty --summary initial
202 diff-tree --pretty --stat --summary initial
203 diff-tree --pretty --root -p initial
204 diff-tree --pretty --root --stat initial
205 # improved by Timo's patch
206 diff-tree --pretty --root --summary initial
207 # improved by Timo's patch
208 diff-tree --pretty --root --summary -r initial
209 diff-tree --pretty --root --stat --summary initial
210 diff-tree --pretty --patch-with-stat initial
211 diff-tree --pretty --root --patch-with-stat initial
212 diff-tree --pretty --patch-with-raw initial
213 diff-tree --pretty --root --patch-with-raw initial
214
215 diff-tree --pretty=oneline initial
216 diff-tree --pretty=oneline --root initial
217 diff-tree --pretty=oneline -p initial
218 diff-tree --pretty=oneline --root -p initial
219 diff-tree --pretty=oneline --patch-with-stat initial
220 # improved by Timo's patch
221 diff-tree --pretty=oneline --root --patch-with-stat initial
222 diff-tree --pretty=oneline --patch-with-raw initial
223 diff-tree --pretty=oneline --root --patch-with-raw initial
224
225 diff-tree --pretty side
226 diff-tree --pretty -p side
227 diff-tree --pretty --patch-with-stat side
228
229 diff-tree initial mode
230 diff-tree --stat initial mode
231 diff-tree --summary initial mode
232
233 diff-tree master
234 diff-tree -p master
235 diff-tree -p -m master
236 diff-tree -c master
237 diff-tree -c --abbrev master
238 :noellipses diff-tree -c --abbrev master
239 diff-tree --cc master
240 # stat only should show the diffstat with the first parent
241 diff-tree -c --stat master
242 diff-tree --cc --stat master
243 diff-tree -c --stat --summary master
244 diff-tree --cc --stat --summary master
245 # stat summary should show the diffstat and summary with the first parent
246 diff-tree -c --stat --summary side
247 diff-tree --cc --stat --summary side
248 diff-tree --cc --shortstat master
249 diff-tree --cc --summary REVERSE
250 # improved by Timo's patch
251 diff-tree --cc --patch-with-stat master
252 # improved by Timo's patch
253 diff-tree --cc --patch-with-stat --summary master
254 # this is correct
255 diff-tree --cc --patch-with-stat --summary side
256
257 log master
258 log -p master
259 log --root master
260 log --root -p master
261 log --patch-with-stat master
262 log --root --patch-with-stat master
263 log --root --patch-with-stat --summary master
264 # improved by Timo's patch
265 log --root -c --patch-with-stat --summary master
266 # improved by Timo's patch
267 log --root --cc --patch-with-stat --summary master
268 log -p --first-parent master
269 log -m -p --first-parent master
270 log -m -p master
271 log -SF master
272 log -S F master
273 log -SF -p master
274 log -SF master --max-count=0
275 log -SF master --max-count=1
276 log -SF master --max-count=2
277 log -GF master
278 log -GF -p master
279 log -GF -p --pickaxe-all master
280 log --decorate --all
281 log --decorate=full --all
282
283 rev-list --parents HEAD
284 rev-list --children HEAD
285
286 whatchanged master
287 :noellipses whatchanged master
288 whatchanged -p master
289 whatchanged --root master
290 :noellipses whatchanged --root master
291 whatchanged --root -p master
292 whatchanged --patch-with-stat master
293 whatchanged --root --patch-with-stat master
294 whatchanged --root --patch-with-stat --summary master
295 # improved by Timo's patch
296 whatchanged --root -c --patch-with-stat --summary master
297 # improved by Timo's patch
298 whatchanged --root --cc --patch-with-stat --summary master
299 whatchanged -SF master
300 :noellipses whatchanged -SF master
301 whatchanged -SF -p master
302
303 log --patch-with-stat master -- dir/
304 whatchanged --patch-with-stat master -- dir/
305 log --patch-with-stat --summary master -- dir/
306 whatchanged --patch-with-stat --summary master -- dir/
307
308 show initial
309 show --root initial
310 show side
311 show master
312 show -c master
313 show -m master
314 show --first-parent master
315 show --stat side
316 show --stat --summary side
317 show --patch-with-stat side
318 show --patch-with-raw side
319 :noellipses show --patch-with-raw side
320 show --patch-with-stat --summary side
321
322 format-patch --stdout initial..side
323 format-patch --stdout initial..master^
324 format-patch --stdout initial..master
325 format-patch --stdout --no-numbered initial..master
326 format-patch --stdout --numbered initial..master
327 format-patch --attach --stdout initial..side
328 format-patch --attach --stdout --suffix=.diff initial..side
329 format-patch --attach --stdout initial..master^
330 format-patch --attach --stdout initial..master
331 format-patch --inline --stdout initial..side
332 format-patch --inline --stdout initial..master^
333 format-patch --inline --stdout --numbered-files initial..master
334 format-patch --inline --stdout initial..master
335 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
336 config format.subjectprefix DIFFERENT_PREFIX
337 format-patch --inline --stdout initial..master^^
338 format-patch --stdout --cover-letter -n initial..master^
339
340 diff --abbrev initial..side
341 diff -U initial..side
342 diff -U1 initial..side
343 diff -r initial..side
344 diff --stat initial..side
345 diff -r --stat initial..side
346 diff initial..side
347 diff --patch-with-stat initial..side
348 diff --patch-with-raw initial..side
349 :noellipses diff --patch-with-raw initial..side
350 diff --patch-with-stat -r initial..side
351 diff --patch-with-raw -r initial..side
352 :noellipses diff --patch-with-raw -r initial..side
353 diff --name-status dir2 dir
354 diff --no-index --name-status dir2 dir
355 diff --no-index --name-status -- dir2 dir
356 diff --no-index dir dir3
357 diff master master^ side
358 # Can't use spaces...
359 diff --line-prefix=abc master master^ side
360 diff --dirstat master~1 master~2
361 diff --dirstat initial rearrange
362 diff --dirstat-by-file initial rearrange
363 diff --dirstat --cc master~1 master
364 # No-index --abbrev and --no-abbrev
365 diff --raw initial
366 :noellipses diff --raw initial
367 diff --raw --abbrev=4 initial
368 :noellipses diff --raw --abbrev=4 initial
369 diff --raw --no-abbrev initial
370 diff --no-index --raw dir2 dir
371 :noellipses diff --no-index --raw dir2 dir
372 diff --no-index --raw --abbrev=4 dir2 dir
373 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
374 diff --no-index --raw --no-abbrev dir2 dir
375
376 diff-tree --pretty --root --stat --compact-summary initial
377 diff-tree --pretty -R --root --stat --compact-summary initial
378 diff-tree --stat --compact-summary initial mode
379 diff-tree -R --stat --compact-summary initial mode
380 EOF
381
382 test_expect_success 'log -S requires an argument' '
383 test_must_fail git log -S
384 '
385
386 test_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
392 test_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 '
396 test_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
401 test_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
411 test_done