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'
122 ! [rearrange] Rearranged lines in dir/sub
125 + [rearrange] Rearranged lines in dir/sub
126 - [master] Merge branch 'side'
130 +*++ [initial] Initial
135 my $oid_length = length($ARGV[0]);
136 my $x40 = "[0-9a-f]{40}";
137 my $xab = "[0-9a-f]{4,16}";
138 my $orx = "[0-9a-f]" x $oid_length;
144 return "" unless length $oid;
146 if ($oid =~ /^(100644|100755|120000)$/) {
150 if ($oid =~ /^0*$/) {
156 if (length($oid) == 40) {
157 return $x x $oid_length;
159 return $x x length($oid);
164 s/($orx)/munge_oid($1)/ge;
165 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
166 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
167 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
168 s/^($x40)($| )/munge_oid($1) . $2/e;
169 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
175 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
187 BUG "unknown magic $magic" ;;
190 cmd="$magic $cmd" magic=
193 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
194 pfx=$(printf "%04d" $test_count)
195 expect="$TEST_DIRECTORY/t4013/diff.$test"
196 actual="$pfx-diff.$test"
198 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
203 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
207 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
208 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
213 process_diffs "$actual" >actual &&
214 process_diffs "$expect" >expect &&
216 *format-patch* | *-stat*)
217 test_i18ncmp expect actual;;
219 test_cmp expect actual;;
221 rm -f "$actual" actual expect
223 # this is to help developing new tests.
224 cp "$actual" "$expect"
231 diff-tree -r --abbrev initial
232 diff-tree -r --abbrev=4 initial
233 diff-tree --root initial
234 diff-tree --root --abbrev initial
235 :noellipses diff-tree --root --abbrev initial
236 diff-tree --root -r initial
237 diff-tree --root -r --abbrev initial
238 :noellipses diff-tree --root -r --abbrev initial
239 diff-tree --root -r --abbrev=4 initial
240 :noellipses diff-tree --root -r --abbrev=4 initial
242 diff-tree --root -p initial
243 diff-tree --root -p --abbrev=10 initial
244 diff-tree --root -p --full-index initial
245 diff-tree --root -p --full-index --abbrev=10 initial
246 diff-tree --patch-with-stat initial
247 diff-tree --root --patch-with-stat initial
248 diff-tree --patch-with-raw initial
249 diff-tree --root --patch-with-raw initial
251 diff-tree --pretty initial
252 diff-tree --pretty --root initial
253 diff-tree --pretty -p initial
254 diff-tree --pretty --stat initial
255 diff-tree --pretty --summary initial
256 diff-tree --pretty --stat --summary initial
257 diff-tree --pretty --root -p initial
258 diff-tree --pretty --root --stat initial
259 # improved by Timo's patch
260 diff-tree --pretty --root --summary initial
261 # improved by Timo's patch
262 diff-tree --pretty --root --summary -r initial
263 diff-tree --pretty --root --stat --summary initial
264 diff-tree --pretty --patch-with-stat initial
265 diff-tree --pretty --root --patch-with-stat initial
266 diff-tree --pretty --patch-with-raw initial
267 diff-tree --pretty --root --patch-with-raw initial
269 diff-tree --pretty=oneline initial
270 diff-tree --pretty=oneline --root initial
271 diff-tree --pretty=oneline -p initial
272 diff-tree --pretty=oneline --root -p initial
273 diff-tree --pretty=oneline --patch-with-stat initial
274 # improved by Timo's patch
275 diff-tree --pretty=oneline --root --patch-with-stat initial
276 diff-tree --pretty=oneline --patch-with-raw initial
277 diff-tree --pretty=oneline --root --patch-with-raw initial
279 diff-tree --pretty side
280 diff-tree --pretty -p side
281 diff-tree --pretty --patch-with-stat side
283 diff-tree initial mode
284 diff-tree --stat initial mode
285 diff-tree --summary initial mode
289 diff-tree -p -m master
291 diff-tree -c --abbrev master
292 :noellipses diff-tree -c --abbrev master
293 diff-tree --cc master
294 # stat only should show the diffstat with the first parent
295 diff-tree -c --stat master
296 diff-tree --cc --stat master
297 diff-tree -c --stat --summary master
298 diff-tree --cc --stat --summary master
299 # stat summary should show the diffstat and summary with the first parent
300 diff-tree -c --stat --summary side
301 diff-tree --cc --stat --summary side
302 diff-tree --cc --shortstat master
303 diff-tree --cc --summary REVERSE
304 # improved by Timo's patch
305 diff-tree --cc --patch-with-stat master
306 # improved by Timo's patch
307 diff-tree --cc --patch-with-stat --summary master
309 diff-tree --cc --patch-with-stat --summary side
315 log --patch-with-stat master
316 log --root --patch-with-stat master
317 log --root --patch-with-stat --summary master
318 # improved by Timo's patch
319 log --root -c --patch-with-stat --summary master
320 # improved by Timo's patch
321 log --root --cc --patch-with-stat --summary master
322 log --no-diff-merges -p --first-parent master
323 log --diff-merges=off -p --first-parent master
324 log --first-parent --diff-merges=off -p master
325 log -p --first-parent master
326 log -m -p --first-parent master
331 log -SF master --max-count=0
332 log -SF master --max-count=1
333 log -SF master --max-count=2
336 log -GF -p --pickaxe-all master
337 log -IA -IB -I1 -I2 -p master
339 log --decorate=full --all
341 rev-list --parents HEAD
342 rev-list --children HEAD
345 :noellipses whatchanged master
346 whatchanged -p master
347 whatchanged --root master
348 :noellipses whatchanged --root master
349 whatchanged --root -p master
350 whatchanged --patch-with-stat master
351 whatchanged --root --patch-with-stat master
352 whatchanged --root --patch-with-stat --summary master
353 # improved by Timo's patch
354 whatchanged --root -c --patch-with-stat --summary master
355 # improved by Timo's patch
356 whatchanged --root --cc --patch-with-stat --summary master
357 whatchanged -SF master
358 :noellipses whatchanged -SF master
359 whatchanged -SF -p master
361 log --patch-with-stat master -- dir/
362 whatchanged --patch-with-stat master -- dir/
363 log --patch-with-stat --summary master -- dir/
364 whatchanged --patch-with-stat --summary master -- dir/
372 show --first-parent master
374 show --stat --summary side
375 show --patch-with-stat side
376 show --patch-with-raw side
377 :noellipses show --patch-with-raw side
378 show --patch-with-stat --summary side
380 format-patch --stdout initial..side
381 format-patch --stdout initial..master^
382 format-patch --stdout initial..master
383 format-patch --stdout --no-numbered initial..master
384 format-patch --stdout --numbered initial..master
385 format-patch --attach --stdout initial..side
386 format-patch --attach --stdout --suffix=.diff initial..side
387 format-patch --attach --stdout initial..master^
388 format-patch --attach --stdout initial..master
389 format-patch --inline --stdout initial..side
390 format-patch --inline --stdout initial..master^
391 format-patch --inline --stdout --numbered-files initial..master
392 format-patch --inline --stdout initial..master
393 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
394 config format.subjectprefix DIFFERENT_PREFIX
395 format-patch --inline --stdout initial..master^^
396 format-patch --stdout --cover-letter -n initial..master^
398 diff --abbrev initial..side
399 diff -U initial..side
400 diff -U1 initial..side
401 diff -r initial..side
402 diff --stat initial..side
403 diff -r --stat initial..side
405 diff --patch-with-stat initial..side
406 diff --patch-with-raw initial..side
407 :noellipses diff --patch-with-raw initial..side
408 diff --patch-with-stat -r initial..side
409 diff --patch-with-raw -r initial..side
410 :noellipses diff --patch-with-raw -r initial..side
411 diff --name-status dir2 dir
412 diff --no-index --name-status dir2 dir
413 diff --no-index --name-status -- dir2 dir
414 diff --no-index dir dir3
415 diff master master^ side
416 # Can't use spaces...
417 diff --line-prefix=abc master master^ side
418 diff --dirstat master~1 master~2
419 diff --dirstat initial rearrange
420 diff --dirstat-by-file initial rearrange
421 diff --dirstat --cc master~1 master
422 # No-index --abbrev and --no-abbrev
424 :noellipses diff --raw initial
425 diff --raw --abbrev=4 initial
426 :noellipses diff --raw --abbrev=4 initial
427 diff --raw --no-abbrev initial
428 diff --no-index --raw dir2 dir
429 :noellipses diff --no-index --raw dir2 dir
430 diff --no-index --raw --abbrev=4 dir2 dir
431 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
432 diff --no-index --raw --no-abbrev dir2 dir
434 diff-tree --pretty --root --stat --compact-summary initial
435 diff-tree --pretty -R --root --stat --compact-summary initial
436 diff-tree --pretty note
437 diff-tree --pretty --notes note
438 diff-tree --format=%N note
439 diff-tree --stat --compact-summary initial mode
440 diff-tree -R --stat --compact-summary initial mode
443 test_expect_success 'log -S requires an argument' '
444 test_must_fail git log -S
447 test_expect_success 'diff --cached on unborn branch' '
448 echo ref: refs/heads/unborn >.git/HEAD &&
449 git diff --cached >result &&
450 process_diffs result >actual &&
451 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
452 test_cmp expected actual
455 test_expect_success 'diff --cached -- file on unborn branch' '
456 git diff --cached -- file0 >result &&
457 process_diffs result >actual &&
458 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
459 test_cmp expected actual
461 test_expect_success 'diff --line-prefix with spaces' '
462 git diff --line-prefix="| | | " --cached -- file0 >result &&
463 process_diffs result >actual &&
464 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
465 test_cmp expected actual
468 test_expect_success 'diff-tree --stdin with log formatting' '
469 cat >expect <<-\EOF &&
474 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
475 test_cmp expect actual
478 test_expect_success 'diff -I<regex>: setup' '
479 git checkout master &&
480 test_seq 50 >file0 &&
481 git commit -m "Set up -I<regex> test file" file0 &&
482 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
485 test_expect_success 'diff -I<regex>' '
486 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
487 cat >expect <<-\EOF &&
488 diff --git a/file0 b/file0
500 compare_diff_patch expect actual
503 test_expect_success 'diff -I<regex> --stat' '
504 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
505 cat >expect <<-\EOF &&
507 1 file changed, 1 deletion(-)
509 test_cmp expect actual
512 test_expect_success 'diff -I<regex>: detect malformed regex' '
513 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
514 test_i18ngrep "invalid regex given to -I: " error