3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Various diff formatting options'
10 test_expect_success setup '
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 &&
18 for i in 1 2 3; do echo $i; done >file0 &&
19 for i in A B; do echo $i; done >dir/sub &&
21 git add file0 file2 dir/sub &&
22 git commit -m Initial &&
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 &&
31 for i in 4 5 6; do echo $i; done >>file0 &&
32 for i in C D; do echo $i; done >>dir/sub &&
34 git update-index --remove file0 file2 dir/sub &&
35 git commit -m "Second${LF}${LF}This is the second commit." &&
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 &&
41 for i in A B C; do echo $i; done >file1 &&
43 for i in E F; do echo $i; done >>dir/sub &&
44 git update-index dir/sub &&
45 git commit -m Third &&
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 &&
52 for i in A B C; do echo $i; done >>file0 &&
53 for i in 1 2; do echo $i; done >>dir/sub &&
56 git update-index file0 dir/sub &&
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 &&
63 git checkout master &&
64 git pull -s ours . side &&
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 &&
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 &&
75 cp dir/sub dir3/sub &&
76 test-tool chmtime +1 dir3/sub &&
78 git config log.showroot false &&
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 &&
87 git commit -m "Rearranged lines in dir/sub" &&
88 git checkout master &&
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 &&
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 &&
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 &&
113 git config diff.renames false &&
120 * [master] Merge branch 'side' into master
121 ! [rearrange] Rearranged lines in dir/sub
124 + [rearrange] Rearranged lines in dir/sub
125 - [master] Merge branch 'side' into master
129 +*++ [initial] Initial
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" \
156 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
168 BUG "unknown magic $magic" ;;
171 cmd="$magic $cmd" magic=
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"
179 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
184 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
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\"/"
194 process_diffs "$actual" >actual &&
195 process_diffs "$expect" >expect &&
197 *format-patch* | *-stat*)
198 test_i18ncmp expect actual;;
200 test_cmp expect actual;;
202 rm -f "$actual" actual expect
204 # this is to help developing new tests.
205 cp "$actual" "$expect"
212 diff-tree -r --abbrev initial
213 diff-tree -r --abbrev=4 initial
214 diff-tree --root initial
215 diff-tree --root --abbrev initial
216 :noellipses diff-tree --root --abbrev initial
217 diff-tree --root -r initial
218 diff-tree --root -r --abbrev initial
219 :noellipses diff-tree --root -r --abbrev initial
220 diff-tree --root -r --abbrev=4 initial
221 :noellipses diff-tree --root -r --abbrev=4 initial
223 diff-tree --root -p initial
224 diff-tree --patch-with-stat initial
225 diff-tree --root --patch-with-stat initial
226 diff-tree --patch-with-raw initial
227 diff-tree --root --patch-with-raw initial
229 diff-tree --pretty initial
230 diff-tree --pretty --root initial
231 diff-tree --pretty -p initial
232 diff-tree --pretty --stat initial
233 diff-tree --pretty --summary initial
234 diff-tree --pretty --stat --summary initial
235 diff-tree --pretty --root -p initial
236 diff-tree --pretty --root --stat initial
237 # improved by Timo's patch
238 diff-tree --pretty --root --summary initial
239 # improved by Timo's patch
240 diff-tree --pretty --root --summary -r initial
241 diff-tree --pretty --root --stat --summary initial
242 diff-tree --pretty --patch-with-stat initial
243 diff-tree --pretty --root --patch-with-stat initial
244 diff-tree --pretty --patch-with-raw initial
245 diff-tree --pretty --root --patch-with-raw initial
247 diff-tree --pretty=oneline initial
248 diff-tree --pretty=oneline --root initial
249 diff-tree --pretty=oneline -p initial
250 diff-tree --pretty=oneline --root -p initial
251 diff-tree --pretty=oneline --patch-with-stat initial
252 # improved by Timo's patch
253 diff-tree --pretty=oneline --root --patch-with-stat initial
254 diff-tree --pretty=oneline --patch-with-raw initial
255 diff-tree --pretty=oneline --root --patch-with-raw initial
257 diff-tree --pretty side
258 diff-tree --pretty -p side
259 diff-tree --pretty --patch-with-stat side
261 diff-tree initial mode
262 diff-tree --stat initial mode
263 diff-tree --summary initial mode
267 diff-tree -p -m master
269 diff-tree -c --abbrev master
270 :noellipses diff-tree -c --abbrev master
271 diff-tree --cc master
272 # stat only should show the diffstat with the first parent
273 diff-tree -c --stat master
274 diff-tree --cc --stat master
275 diff-tree -c --stat --summary master
276 diff-tree --cc --stat --summary master
277 # stat summary should show the diffstat and summary with the first parent
278 diff-tree -c --stat --summary side
279 diff-tree --cc --stat --summary side
280 diff-tree --cc --shortstat master
281 diff-tree --cc --summary REVERSE
282 # improved by Timo's patch
283 diff-tree --cc --patch-with-stat master
284 # improved by Timo's patch
285 diff-tree --cc --patch-with-stat --summary master
287 diff-tree --cc --patch-with-stat --summary side
293 log --patch-with-stat master
294 log --root --patch-with-stat master
295 log --root --patch-with-stat --summary master
296 # improved by Timo's patch
297 log --root -c --patch-with-stat --summary master
298 # improved by Timo's patch
299 log --root --cc --patch-with-stat --summary master
300 log -p --first-parent master
301 log -m -p --first-parent master
306 log -SF master --max-count=0
307 log -SF master --max-count=1
308 log -SF master --max-count=2
311 log -GF -p --pickaxe-all master
313 log --decorate=full --all
315 rev-list --parents HEAD
316 rev-list --children HEAD
319 :noellipses whatchanged master
320 whatchanged -p master
321 whatchanged --root master
322 :noellipses whatchanged --root master
323 whatchanged --root -p master
324 whatchanged --patch-with-stat master
325 whatchanged --root --patch-with-stat master
326 whatchanged --root --patch-with-stat --summary master
327 # improved by Timo's patch
328 whatchanged --root -c --patch-with-stat --summary master
329 # improved by Timo's patch
330 whatchanged --root --cc --patch-with-stat --summary master
331 whatchanged -SF master
332 :noellipses whatchanged -SF master
333 whatchanged -SF -p master
335 log --patch-with-stat master -- dir/
336 whatchanged --patch-with-stat master -- dir/
337 log --patch-with-stat --summary master -- dir/
338 whatchanged --patch-with-stat --summary master -- dir/
346 show --first-parent master
348 show --stat --summary side
349 show --patch-with-stat side
350 show --patch-with-raw side
351 :noellipses show --patch-with-raw side
352 show --patch-with-stat --summary side
354 format-patch --stdout initial..side
355 format-patch --stdout initial..master^
356 format-patch --stdout initial..master
357 format-patch --stdout --no-numbered initial..master
358 format-patch --stdout --numbered initial..master
359 format-patch --attach --stdout initial..side
360 format-patch --attach --stdout --suffix=.diff initial..side
361 format-patch --attach --stdout initial..master^
362 format-patch --attach --stdout initial..master
363 format-patch --inline --stdout initial..side
364 format-patch --inline --stdout initial..master^
365 format-patch --inline --stdout --numbered-files initial..master
366 format-patch --inline --stdout initial..master
367 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
368 config format.subjectprefix DIFFERENT_PREFIX
369 format-patch --inline --stdout initial..master^^
370 format-patch --stdout --cover-letter -n initial..master^
372 diff --abbrev initial..side
373 diff -U initial..side
374 diff -U1 initial..side
375 diff -r initial..side
376 diff --stat initial..side
377 diff -r --stat initial..side
379 diff --patch-with-stat initial..side
380 diff --patch-with-raw initial..side
381 :noellipses diff --patch-with-raw initial..side
382 diff --patch-with-stat -r initial..side
383 diff --patch-with-raw -r initial..side
384 :noellipses diff --patch-with-raw -r initial..side
385 diff --name-status dir2 dir
386 diff --no-index --name-status dir2 dir
387 diff --no-index --name-status -- dir2 dir
388 diff --no-index dir dir3
389 diff master master^ side
390 # Can't use spaces...
391 diff --line-prefix=abc master master^ side
392 diff --dirstat master~1 master~2
393 diff --dirstat initial rearrange
394 diff --dirstat-by-file initial rearrange
395 diff --dirstat --cc master~1 master
396 # No-index --abbrev and --no-abbrev
398 :noellipses diff --raw initial
399 diff --raw --abbrev=4 initial
400 :noellipses diff --raw --abbrev=4 initial
401 diff --raw --no-abbrev initial
402 diff --no-index --raw dir2 dir
403 :noellipses diff --no-index --raw dir2 dir
404 diff --no-index --raw --abbrev=4 dir2 dir
405 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
406 diff --no-index --raw --no-abbrev dir2 dir
408 diff-tree --pretty --root --stat --compact-summary initial
409 diff-tree --pretty -R --root --stat --compact-summary initial
410 diff-tree --pretty note
411 diff-tree --pretty --notes note
412 diff-tree --format=%N note
413 diff-tree --stat --compact-summary initial mode
414 diff-tree -R --stat --compact-summary initial mode
417 test_expect_success 'log -S requires an argument' '
418 test_must_fail git log -S
421 test_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
429 test_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
435 test_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
442 test_expect_success 'diff-tree --stdin with log formatting' '
443 cat >expect <<-\EOF &&
448 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
449 test_cmp expect actual