3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Various diff formatting options'
9 . "$TEST_DIRECTORY"/diff-lib.sh
11 test_expect_success setup '
13 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
14 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
15 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
19 for i in 1 2 3; do echo $i; done >file0 &&
20 for i in A B; do echo $i; done >dir/sub &&
22 git add file0 file2 dir/sub &&
23 git commit -m Initial &&
28 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
29 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
30 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
32 for i in 4 5 6; do echo $i; done >>file0 &&
33 for i in C D; do echo $i; done >>dir/sub &&
35 git update-index --remove file0 file2 dir/sub &&
36 git commit -m "Second${LF}${LF}This is the second commit." &&
38 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
39 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
40 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
42 for i in A B C; do echo $i; done >file1 &&
44 for i in E F; do echo $i; done >>dir/sub &&
45 git update-index dir/sub &&
46 git commit -m Third &&
48 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
49 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
50 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
53 for i in A B C; do echo $i; done >>file0 &&
54 for i in 1 2; do echo $i; done >>dir/sub &&
57 git update-index file0 dir/sub &&
60 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
61 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
62 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
64 git checkout master &&
65 git pull -s ours . side &&
67 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
68 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
69 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
71 for i in A B C; do echo $i; done >>file0 &&
72 for i in 1 2; do echo $i; done >>dir/sub &&
73 git update-index file0 dir/sub &&
76 cp dir/sub dir3/sub &&
77 test-tool chmtime +1 dir3/sub &&
79 git config log.showroot false &&
82 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
83 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
84 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
85 git checkout -b rearrange initial &&
86 for i in B A; do echo $i; done >dir/sub &&
88 git commit -m "Rearranged lines in dir/sub" &&
89 git checkout master &&
91 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
92 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
93 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
94 git checkout -b mode initial &&
95 git update-index --chmod=+x file0 &&
96 git commit -m "update mode" &&
97 git checkout -f master &&
99 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
100 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
101 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
102 git checkout -b note initial &&
103 git update-index --chmod=+x file2 &&
104 git commit -m "update mode (file2)" &&
105 git notes add -m "note" &&
106 git checkout -f master &&
108 # Same merge as master, but with parents reversed. Hide it in a
109 # pseudo-ref to avoid impacting tests with --all.
110 commit=$(echo reverse |
111 git commit-tree -p master^2 -p master^1 master^{tree}) &&
112 git update-ref REVERSE $commit &&
114 git config diff.renames false &&
121 * [master] Merge branch 'side' into master
122 ! [rearrange] Rearranged lines in dir/sub
125 + [rearrange] Rearranged lines in dir/sub
126 - [master] Merge branch 'side' into master
130 +*++ [initial] Initial
134 _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" &&
135 _x07="$_x05[0-9a-f][0-9a-f]" &&
136 sed -e "s/$OID_REGEX/$ZERO_OID/g" \
137 -e "s/From $_x40 /From $ZERO_OID /" \
138 -e "s/from $_x40)/from $ZERO_OID)/" \
139 -e "s/commit $_x40\$/commit $ZERO_OID/" \
140 -e "s/commit $_x40 (/commit $ZERO_OID (/" \
141 -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \
142 -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \
143 -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \
144 -e "s/^$_x40 /$ZERO_OID /" \
145 -e "s/^$_x40$/$ZERO_OID/" \
146 -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \
147 -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \
148 -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \
149 -e "s/$_x07 $_x07 /fffffff fffffff /g" \
150 -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \
151 -e "s/$_x07\.\.\./fffffff.../g" \
152 -e "s/ $_x04\.\.\./ ffff.../g" \
153 -e "s/ $_x04/ ffff/g" \
157 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
169 BUG "unknown magic $magic" ;;
172 cmd="$magic $cmd" magic=
175 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
176 pfx=$(printf "%04d" $test_count)
177 expect="$TEST_DIRECTORY/t4013/diff.$test"
178 actual="$pfx-diff.$test"
180 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
185 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
189 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
190 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
195 process_diffs "$actual" >actual &&
196 process_diffs "$expect" >expect &&
198 *format-patch* | *-stat*)
199 test_i18ncmp expect actual;;
201 test_cmp expect actual;;
203 rm -f "$actual" actual expect
205 # this is to help developing new tests.
206 cp "$actual" "$expect"
213 diff-tree -r --abbrev initial
214 diff-tree -r --abbrev=4 initial
215 diff-tree --root initial
216 diff-tree --root --abbrev initial
217 :noellipses diff-tree --root --abbrev initial
218 diff-tree --root -r initial
219 diff-tree --root -r --abbrev initial
220 :noellipses diff-tree --root -r --abbrev initial
221 diff-tree --root -r --abbrev=4 initial
222 :noellipses diff-tree --root -r --abbrev=4 initial
224 diff-tree --root -p initial
225 diff-tree --patch-with-stat initial
226 diff-tree --root --patch-with-stat initial
227 diff-tree --patch-with-raw initial
228 diff-tree --root --patch-with-raw initial
230 diff-tree --pretty initial
231 diff-tree --pretty --root initial
232 diff-tree --pretty -p initial
233 diff-tree --pretty --stat initial
234 diff-tree --pretty --summary initial
235 diff-tree --pretty --stat --summary initial
236 diff-tree --pretty --root -p initial
237 diff-tree --pretty --root --stat initial
238 # improved by Timo's patch
239 diff-tree --pretty --root --summary initial
240 # improved by Timo's patch
241 diff-tree --pretty --root --summary -r initial
242 diff-tree --pretty --root --stat --summary initial
243 diff-tree --pretty --patch-with-stat initial
244 diff-tree --pretty --root --patch-with-stat initial
245 diff-tree --pretty --patch-with-raw initial
246 diff-tree --pretty --root --patch-with-raw initial
248 diff-tree --pretty=oneline initial
249 diff-tree --pretty=oneline --root initial
250 diff-tree --pretty=oneline -p initial
251 diff-tree --pretty=oneline --root -p initial
252 diff-tree --pretty=oneline --patch-with-stat initial
253 # improved by Timo's patch
254 diff-tree --pretty=oneline --root --patch-with-stat initial
255 diff-tree --pretty=oneline --patch-with-raw initial
256 diff-tree --pretty=oneline --root --patch-with-raw initial
258 diff-tree --pretty side
259 diff-tree --pretty -p side
260 diff-tree --pretty --patch-with-stat side
262 diff-tree initial mode
263 diff-tree --stat initial mode
264 diff-tree --summary initial mode
268 diff-tree -p -m master
270 diff-tree -c --abbrev master
271 :noellipses diff-tree -c --abbrev master
272 diff-tree --cc master
273 # stat only should show the diffstat with the first parent
274 diff-tree -c --stat master
275 diff-tree --cc --stat master
276 diff-tree -c --stat --summary master
277 diff-tree --cc --stat --summary master
278 # stat summary should show the diffstat and summary with the first parent
279 diff-tree -c --stat --summary side
280 diff-tree --cc --stat --summary side
281 diff-tree --cc --shortstat master
282 diff-tree --cc --summary REVERSE
283 # improved by Timo's patch
284 diff-tree --cc --patch-with-stat master
285 # improved by Timo's patch
286 diff-tree --cc --patch-with-stat --summary master
288 diff-tree --cc --patch-with-stat --summary side
294 log --patch-with-stat master
295 log --root --patch-with-stat master
296 log --root --patch-with-stat --summary master
297 # improved by Timo's patch
298 log --root -c --patch-with-stat --summary master
299 # improved by Timo's patch
300 log --root --cc --patch-with-stat --summary master
301 log -p --first-parent master
302 log -m -p --first-parent master
307 log -SF master --max-count=0
308 log -SF master --max-count=1
309 log -SF master --max-count=2
312 log -GF -p --pickaxe-all master
313 log -IA -IB -I1 -I2 -p master
315 log --decorate=full --all
317 rev-list --parents HEAD
318 rev-list --children HEAD
321 :noellipses whatchanged master
322 whatchanged -p master
323 whatchanged --root master
324 :noellipses whatchanged --root master
325 whatchanged --root -p master
326 whatchanged --patch-with-stat master
327 whatchanged --root --patch-with-stat master
328 whatchanged --root --patch-with-stat --summary master
329 # improved by Timo's patch
330 whatchanged --root -c --patch-with-stat --summary master
331 # improved by Timo's patch
332 whatchanged --root --cc --patch-with-stat --summary master
333 whatchanged -SF master
334 :noellipses whatchanged -SF master
335 whatchanged -SF -p master
337 log --patch-with-stat master -- dir/
338 whatchanged --patch-with-stat master -- dir/
339 log --patch-with-stat --summary master -- dir/
340 whatchanged --patch-with-stat --summary master -- dir/
348 show --first-parent master
350 show --stat --summary side
351 show --patch-with-stat side
352 show --patch-with-raw side
353 :noellipses show --patch-with-raw side
354 show --patch-with-stat --summary side
356 format-patch --stdout initial..side
357 format-patch --stdout initial..master^
358 format-patch --stdout initial..master
359 format-patch --stdout --no-numbered initial..master
360 format-patch --stdout --numbered initial..master
361 format-patch --attach --stdout initial..side
362 format-patch --attach --stdout --suffix=.diff initial..side
363 format-patch --attach --stdout initial..master^
364 format-patch --attach --stdout initial..master
365 format-patch --inline --stdout initial..side
366 format-patch --inline --stdout initial..master^
367 format-patch --inline --stdout --numbered-files initial..master
368 format-patch --inline --stdout initial..master
369 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
370 config format.subjectprefix DIFFERENT_PREFIX
371 format-patch --inline --stdout initial..master^^
372 format-patch --stdout --cover-letter -n initial..master^
374 diff --abbrev initial..side
375 diff -U initial..side
376 diff -U1 initial..side
377 diff -r initial..side
378 diff --stat initial..side
379 diff -r --stat initial..side
381 diff --patch-with-stat initial..side
382 diff --patch-with-raw initial..side
383 :noellipses diff --patch-with-raw initial..side
384 diff --patch-with-stat -r initial..side
385 diff --patch-with-raw -r initial..side
386 :noellipses diff --patch-with-raw -r initial..side
387 diff --name-status dir2 dir
388 diff --no-index --name-status dir2 dir
389 diff --no-index --name-status -- dir2 dir
390 diff --no-index dir dir3
391 diff master master^ side
392 # Can't use spaces...
393 diff --line-prefix=abc master master^ side
394 diff --dirstat master~1 master~2
395 diff --dirstat initial rearrange
396 diff --dirstat-by-file initial rearrange
397 diff --dirstat --cc master~1 master
398 # No-index --abbrev and --no-abbrev
400 :noellipses diff --raw initial
401 diff --raw --abbrev=4 initial
402 :noellipses diff --raw --abbrev=4 initial
403 diff --raw --no-abbrev initial
404 diff --no-index --raw dir2 dir
405 :noellipses diff --no-index --raw dir2 dir
406 diff --no-index --raw --abbrev=4 dir2 dir
407 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
408 diff --no-index --raw --no-abbrev dir2 dir
410 diff-tree --pretty --root --stat --compact-summary initial
411 diff-tree --pretty -R --root --stat --compact-summary initial
412 diff-tree --pretty note
413 diff-tree --pretty --notes note
414 diff-tree --format=%N note
415 diff-tree --stat --compact-summary initial mode
416 diff-tree -R --stat --compact-summary initial mode
419 test_expect_success 'log -S requires an argument' '
420 test_must_fail git log -S
423 test_expect_success 'diff --cached on unborn branch' '
424 echo ref: refs/heads/unborn >.git/HEAD &&
425 git diff --cached >result &&
426 process_diffs result >actual &&
427 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
428 test_cmp expected actual
431 test_expect_success 'diff --cached -- file on unborn branch' '
432 git diff --cached -- file0 >result &&
433 process_diffs result >actual &&
434 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
435 test_cmp expected actual
437 test_expect_success 'diff --line-prefix with spaces' '
438 git diff --line-prefix="| | | " --cached -- file0 >result &&
439 process_diffs result >actual &&
440 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
441 test_cmp expected actual
444 test_expect_success 'diff-tree --stdin with log formatting' '
445 cat >expect <<-\EOF &&
450 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
451 test_cmp expect actual
454 test_expect_success 'diff -I<regex>: setup' '
455 git checkout master &&
456 test_seq 50 >file0 &&
457 git commit -m "Set up -I<regex> test file" file0 &&
458 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
461 test_expect_success 'diff -I<regex>' '
462 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
463 cat >expect <<-\EOF &&
464 diff --git a/file0 b/file0
476 compare_diff_patch expect actual
479 test_expect_success 'diff -I<regex> --stat' '
480 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
481 cat >expect <<-\EOF &&
483 1 file changed, 1 deletion(-)
485 test_cmp expect actual
488 test_expect_success 'diff -I<regex>: detect malformed regex' '
489 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
490 test_i18ngrep "invalid regex given to -I: " error