3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='Various diff formatting options'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 .
"$TEST_DIRECTORY"/lib-diff.sh
14 test_expect_success setup
'
16 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
17 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
18 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
22 for i in 1 2 3; do echo $i; done >file0 &&
23 for i in A B; do echo $i; done >dir/sub &&
25 git add file0 file2 dir/sub &&
26 git commit -m Initial &&
31 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
32 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
33 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
35 for i in 4 5 6; do echo $i; done >>file0 &&
36 for i in C D; do echo $i; done >>dir/sub &&
38 git update-index --remove file0 file2 dir/sub &&
39 git commit -m "Second${LF}${LF}This is the second commit." &&
41 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
42 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
43 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
45 for i in A B C; do echo $i; done >file1 &&
47 for i in E F; do echo $i; done >>dir/sub &&
48 git update-index dir/sub &&
49 git commit -m Third &&
51 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
52 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
53 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
56 for i in A B C; do echo $i; done >>file0 &&
57 for i in 1 2; do echo $i; done >>dir/sub &&
60 git update-index file0 dir/sub &&
63 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
64 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
65 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
67 git checkout master &&
68 git pull -s ours . side &&
70 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
71 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
72 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
74 for i in A B C; do echo $i; done >>file0 &&
75 for i in 1 2; do echo $i; done >>dir/sub &&
76 git update-index file0 dir/sub &&
79 cp dir/sub dir3/sub &&
80 test-tool chmtime +1 dir3/sub &&
82 git config log.showroot false &&
85 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
86 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
87 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
88 git checkout -b rearrange initial &&
89 for i in B A; do echo $i; done >dir/sub &&
91 git commit -m "Rearranged lines in dir/sub" &&
92 git checkout master &&
94 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
95 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
96 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
97 git checkout -b mode initial &&
98 git update-index --chmod=+x file0 &&
99 git commit -m "update mode" &&
100 git checkout -f master &&
102 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
103 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
104 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
105 git checkout -b note initial &&
106 git update-index --chmod=+x file2 &&
107 git commit -m "update mode (file2)" &&
108 git notes add -m "note" &&
109 git checkout -f master &&
111 # Same merge as master, but with parents reversed. Hide it in a
112 # pseudo-ref to avoid impacting tests with --all.
113 commit=$(echo reverse |
114 git commit-tree -p master^2 -p master^1 master^{tree}) &&
115 git update-ref REVERSE $commit &&
117 git config diff.renames false &&
124 * [master
] Merge branch
'side'
125 ! [rearrange
] Rearranged lines
in dir
/sub
128 + [rearrange
] Rearranged lines
in dir
/sub
129 - [master
] Merge branch
'side'
133 +*++ [initial
] Initial
138 my $oid_length = length($ARGV[0]);
139 my $x40 = "[0-9a-f]{40}";
140 my $xab = "[0-9a-f]{4,16}";
141 my $orx = "[0-9a-f]" x $oid_length;
147 return "" unless length $oid;
149 if ($oid =~ /^(100644|100755|120000)$/) {
153 if ($oid =~ /^0*$/) {
159 if (length($oid) == 40) {
160 return $x x $oid_length;
162 return $x x length($oid);
167 s/($orx)/munge_oid($1)/ge;
168 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
169 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
170 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
171 s/^($x40)($| )/munge_oid($1) . $2/e;
172 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
178 V
=$
(git version |
sed -e 's/^git version //' -e 's/\./\\./g')
195 BUG
"unknown magic $magic" ;;
198 cmd
="$magic $cmd" magic
=
201 test=$
(echo "$label" |
sed -e 's|[/ ][/ ]*|_|g')
202 pfx
=$
(printf "%04d" $test_count)
203 expect
="$TEST_DIRECTORY/t4013/diff.$test"
204 actual
="$pfx-diff.$test"
206 test_expect_
$status "git $cmd # magic is ${magic:-(not used)}" '
211 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
215 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
216 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
221 process_diffs "$actual" >actual &&
222 process_diffs "$expect" >expect &&
224 *format-patch* | *-stat*)
225 test_cmp expect actual;;
227 test_cmp expect actual;;
229 rm -f "$actual" actual expect
231 # this is to help developing new tests.
232 cp "$actual" "$expect"
239 diff-tree
-r --abbrev initial
240 diff-tree
-r --abbrev=4 initial
241 diff-tree
--root initial
242 diff-tree
--root --abbrev initial
243 :noellipses diff-tree
--root --abbrev initial
244 diff-tree
--root -r initial
245 diff-tree
--root -r --abbrev initial
246 :noellipses diff-tree
--root -r --abbrev initial
247 diff-tree
--root -r --abbrev=4 initial
248 :noellipses diff-tree
--root -r --abbrev=4 initial
250 diff-tree
--root -p initial
251 diff-tree
--root -p --abbrev=10 initial
252 diff-tree
--root -p --full-index initial
253 diff-tree
--root -p --full-index --abbrev=10 initial
254 diff-tree
--patch-with-stat initial
255 diff-tree
--root --patch-with-stat initial
256 diff-tree
--patch-with-raw initial
257 diff-tree
--root --patch-with-raw initial
259 diff-tree
--pretty initial
260 diff-tree
--pretty --root initial
261 diff-tree
--pretty -p initial
262 diff-tree
--pretty --stat initial
263 diff-tree
--pretty --summary initial
264 diff-tree
--pretty --stat --summary initial
265 diff-tree
--pretty --root -p initial
266 diff-tree
--pretty --root --stat initial
267 # improved by Timo's patch
268 diff-tree
--pretty --root --summary initial
269 # improved by Timo's patch
270 diff-tree
--pretty --root --summary -r initial
271 diff-tree
--pretty --root --stat --summary initial
272 diff-tree
--pretty --patch-with-stat initial
273 diff-tree
--pretty --root --patch-with-stat initial
274 diff-tree
--pretty --patch-with-raw initial
275 diff-tree
--pretty --root --patch-with-raw initial
277 diff-tree
--pretty=oneline initial
278 diff-tree
--pretty=oneline
--root initial
279 diff-tree
--pretty=oneline
-p initial
280 diff-tree
--pretty=oneline
--root -p initial
281 diff-tree
--pretty=oneline
--patch-with-stat initial
282 # improved by Timo's patch
283 diff-tree
--pretty=oneline
--root --patch-with-stat initial
284 diff-tree
--pretty=oneline
--patch-with-raw initial
285 diff-tree
--pretty=oneline
--root --patch-with-raw initial
287 diff-tree
--pretty side
288 diff-tree
--pretty -p side
289 diff-tree
--pretty --patch-with-stat side
291 diff-tree initial mode
292 diff-tree
--stat initial mode
293 diff-tree
--summary initial mode
297 diff-tree
-p -m master
299 diff-tree
-c --abbrev master
300 :noellipses diff-tree
-c --abbrev master
301 diff-tree
--cc master
302 # stat only should show the diffstat with the first parent
303 diff-tree
-c --stat master
304 diff-tree
--cc --stat master
305 diff-tree
-c --stat --summary master
306 diff-tree
--cc --stat --summary master
307 # stat summary should show the diffstat and summary with the first parent
308 diff-tree
-c --stat --summary side
309 diff-tree
--cc --stat --summary side
310 diff-tree
--cc --shortstat master
311 diff-tree
--cc --summary REVERSE
312 # improved by Timo's patch
313 diff-tree
--cc --patch-with-stat master
314 # improved by Timo's patch
315 diff-tree
--cc --patch-with-stat --summary master
317 diff-tree
--cc --patch-with-stat --summary side
323 log
--patch-with-stat master
324 log
--root --patch-with-stat master
325 log
--root --patch-with-stat --summary master
326 # improved by Timo's patch
327 log
--root -c --patch-with-stat --summary master
328 # improved by Timo's patch
329 log
--root --cc --patch-with-stat --summary master
330 log
--no-diff-merges -p --first-parent master
331 log
--diff-merges=off
-p --first-parent master
332 log
--first-parent --diff-merges=off
-p master
333 log
-p --first-parent master
334 log
-p --diff-merges=first-parent master
335 log
--diff-merges=first-parent master
336 log
-m -p --first-parent master
338 log
--cc -m -p master
343 log
-SF master
--max-count=0
344 log
-SF master
--max-count=1
345 log
-SF master
--max-count=2
348 log
-GF -p --pickaxe-all master
349 log
-IA -IB -I1 -I2 -p master
351 log
--decorate=full
--all
353 rev-list
--parents HEAD
354 rev-list
--children HEAD
357 :noellipses whatchanged master
358 whatchanged
-p master
359 whatchanged
--root master
360 :noellipses whatchanged
--root master
361 whatchanged
--root -p master
362 whatchanged
--patch-with-stat master
363 whatchanged
--root --patch-with-stat master
364 whatchanged
--root --patch-with-stat --summary master
365 # improved by Timo's patch
366 whatchanged
--root -c --patch-with-stat --summary master
367 # improved by Timo's patch
368 whatchanged
--root --cc --patch-with-stat --summary master
369 whatchanged
-SF master
370 :noellipses whatchanged
-SF master
371 whatchanged
-SF -p master
373 log
--patch-with-stat master
-- dir
/
374 whatchanged
--patch-with-stat master
-- dir
/
375 log
--patch-with-stat --summary master
-- dir
/
376 whatchanged
--patch-with-stat --summary master
-- dir
/
384 show
--first-parent master
386 show
--stat --summary side
387 show
--patch-with-stat side
388 show
--patch-with-raw side
389 :noellipses show
--patch-with-raw side
390 show
--patch-with-stat --summary side
392 format-patch
--stdout initial..side
393 format-patch
--stdout initial..master^
394 format-patch
--stdout initial..master
395 format-patch
--stdout --no-numbered initial..master
396 format-patch
--stdout --numbered initial..master
397 format-patch
--attach --stdout initial..side
398 format-patch
--attach --stdout --suffix=.
diff initial..side
399 format-patch
--attach --stdout initial..master^
400 format-patch
--attach --stdout initial..master
401 format-patch
--inline --stdout initial..side
402 format-patch
--inline --stdout initial..master^
403 format-patch
--inline --stdout --numbered-files initial..master
404 format-patch
--inline --stdout initial..master
405 format-patch
--inline --stdout --subject-prefix=TESTCASE initial..master
406 config format.subjectprefix DIFFERENT_PREFIX
407 format-patch
--inline --stdout initial..master^^
408 format-patch
--stdout --cover-letter -n initial..master^
410 diff --abbrev initial..side
411 diff -U initial..side
412 diff -U1 initial..side
413 diff -r initial..side
414 diff --stat initial..side
415 diff -r --stat initial..side
417 diff --patch-with-stat initial..side
418 diff --patch-with-raw initial..side
419 :noellipses
diff --patch-with-raw initial..side
420 diff --patch-with-stat -r initial..side
421 diff --patch-with-raw -r initial..side
422 :noellipses
diff --patch-with-raw -r initial..side
423 diff --name-status dir2 dir
424 diff --no-index --name-status dir2 dir
425 diff --no-index --name-status -- dir2 dir
426 diff --no-index dir dir3
427 diff master master^ side
428 # Can't use spaces...
429 diff --line-prefix=abc master master^ side
430 diff --dirstat master~
1 master~
2
431 diff --dirstat initial rearrange
432 diff --dirstat-by-file initial rearrange
433 diff --dirstat --cc master~
1 master
434 # No-index --abbrev and --no-abbrev
436 :noellipses
diff --raw initial
437 diff --raw --abbrev=4 initial
438 :noellipses
diff --raw --abbrev=4 initial
439 diff --raw --no-abbrev initial
440 diff --no-index --raw dir2 dir
441 :noellipses
diff --no-index --raw dir2 dir
442 diff --no-index --raw --abbrev=4 dir2 dir
443 :noellipses
diff --no-index --raw --abbrev=4 dir2 dir
444 diff --no-index --raw --no-abbrev dir2 dir
446 diff-tree
--pretty --root --stat --compact-summary initial
447 diff-tree
--pretty -R --root --stat --compact-summary initial
448 diff-tree
--pretty note
449 diff-tree
--pretty --notes note
450 diff-tree
--format=%N note
451 diff-tree
--stat --compact-summary initial mode
452 diff-tree
-R --stat --compact-summary initial mode
455 test_expect_success
'log -S requires an argument' '
456 test_must_fail git log -S
459 test_expect_success
'diff --cached on unborn branch' '
460 echo ref: refs/heads/unborn >.git/HEAD &&
461 git diff --cached >result &&
462 process_diffs result >actual &&
463 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
464 test_cmp expected actual
467 test_expect_success
'diff --cached -- file on unborn branch' '
468 git diff --cached -- file0 >result &&
469 process_diffs result >actual &&
470 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
471 test_cmp expected actual
473 test_expect_success
'diff --line-prefix with spaces' '
474 git diff --line-prefix="| | | " --cached -- file0 >result &&
475 process_diffs result >actual &&
476 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
477 test_cmp expected actual
480 test_expect_success
'diff-tree --stdin with log formatting' '
481 cat >expect <<-\EOF &&
486 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
487 test_cmp expect actual
490 test_expect_success
'diff -I<regex>: setup' '
491 git checkout master &&
492 test_seq 50 >file0 &&
493 git commit -m "Set up -I<regex> test file" file0 &&
494 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
497 test_expect_success
'diff -I<regex>' '
498 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
499 cat >expect <<-\EOF &&
500 diff --git a/file0 b/file0
512 compare_diff_patch expect actual
515 test_expect_success
'diff -I<regex> --stat' '
516 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
517 cat >expect <<-\EOF &&
519 1 file changed, 1 deletion(-)
521 test_cmp expect actual
524 test_expect_success
'diff -I<regex>: detect malformed regex' '
525 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
526 test_i18ngrep "invalid regex given to -I: " error