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'
121 ! [rearrange] Rearranged lines in dir/sub
124 + [rearrange] Rearranged lines in dir/sub
125 - [master] Merge branch 'side'
129 +*++ [initial] Initial
134 my $oid_length = length($ARGV[0]);
135 my $x40 = "[0-9a-f]{40}";
136 my $xab = "[0-9a-f]{4,16}";
137 my $orx = "[0-9a-f]" x $oid_length;
143 return "" unless length $oid;
145 if ($oid =~ /^(100644|100755|120000)$/) {
149 if ($oid =~ /^0*$/) {
155 if (length($oid) == 40) {
156 return $x x $oid_length;
158 return $x x length($oid);
163 s/($orx)/munge_oid($1)/ge;
164 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
165 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
166 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
167 s/^($x40)($| )/munge_oid($1) . $2/e;
168 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
174 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
186 BUG "unknown magic $magic" ;;
189 cmd="$magic $cmd" magic=
192 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
193 pfx=$(printf "%04d" $test_count)
194 expect="$TEST_DIRECTORY/t4013/diff.$test"
195 actual="$pfx-diff.$test"
197 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
202 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
206 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
207 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
212 process_diffs "$actual" >actual &&
213 process_diffs "$expect" >expect &&
215 *format-patch* | *-stat*)
216 test_i18ncmp expect actual;;
218 test_cmp expect actual;;
220 rm -f "$actual" actual expect
222 # this is to help developing new tests.
223 cp "$actual" "$expect"
230 diff-tree -r --abbrev initial
231 diff-tree -r --abbrev=4 initial
232 diff-tree --root initial
233 diff-tree --root --abbrev initial
234 :noellipses diff-tree --root --abbrev initial
235 diff-tree --root -r initial
236 diff-tree --root -r --abbrev initial
237 :noellipses diff-tree --root -r --abbrev initial
238 diff-tree --root -r --abbrev=4 initial
239 :noellipses diff-tree --root -r --abbrev=4 initial
241 diff-tree --root -p initial
242 diff-tree --patch-with-stat initial
243 diff-tree --root --patch-with-stat initial
244 diff-tree --patch-with-raw initial
245 diff-tree --root --patch-with-raw initial
247 diff-tree --pretty initial
248 diff-tree --pretty --root initial
249 diff-tree --pretty -p initial
250 diff-tree --pretty --stat initial
251 diff-tree --pretty --summary initial
252 diff-tree --pretty --stat --summary initial
253 diff-tree --pretty --root -p initial
254 diff-tree --pretty --root --stat initial
255 # improved by Timo's patch
256 diff-tree --pretty --root --summary initial
257 # improved by Timo's patch
258 diff-tree --pretty --root --summary -r initial
259 diff-tree --pretty --root --stat --summary initial
260 diff-tree --pretty --patch-with-stat initial
261 diff-tree --pretty --root --patch-with-stat initial
262 diff-tree --pretty --patch-with-raw initial
263 diff-tree --pretty --root --patch-with-raw initial
265 diff-tree --pretty=oneline initial
266 diff-tree --pretty=oneline --root initial
267 diff-tree --pretty=oneline -p initial
268 diff-tree --pretty=oneline --root -p initial
269 diff-tree --pretty=oneline --patch-with-stat initial
270 # improved by Timo's patch
271 diff-tree --pretty=oneline --root --patch-with-stat initial
272 diff-tree --pretty=oneline --patch-with-raw initial
273 diff-tree --pretty=oneline --root --patch-with-raw initial
275 diff-tree --pretty side
276 diff-tree --pretty -p side
277 diff-tree --pretty --patch-with-stat side
279 diff-tree initial mode
280 diff-tree --stat initial mode
281 diff-tree --summary initial mode
285 diff-tree -p -m master
287 diff-tree -c --abbrev master
288 :noellipses diff-tree -c --abbrev master
289 diff-tree --cc master
290 # stat only should show the diffstat with the first parent
291 diff-tree -c --stat master
292 diff-tree --cc --stat master
293 diff-tree -c --stat --summary master
294 diff-tree --cc --stat --summary master
295 # stat summary should show the diffstat and summary with the first parent
296 diff-tree -c --stat --summary side
297 diff-tree --cc --stat --summary side
298 diff-tree --cc --shortstat master
299 diff-tree --cc --summary REVERSE
300 # improved by Timo's patch
301 diff-tree --cc --patch-with-stat master
302 # improved by Timo's patch
303 diff-tree --cc --patch-with-stat --summary master
305 diff-tree --cc --patch-with-stat --summary side
311 log --patch-with-stat master
312 log --root --patch-with-stat master
313 log --root --patch-with-stat --summary master
314 # improved by Timo's patch
315 log --root -c --patch-with-stat --summary master
316 # improved by Timo's patch
317 log --root --cc --patch-with-stat --summary master
318 log -p --first-parent master
319 log -m -p --first-parent master
324 log -SF master --max-count=0
325 log -SF master --max-count=1
326 log -SF master --max-count=2
329 log -GF -p --pickaxe-all master
331 log --decorate=full --all
333 rev-list --parents HEAD
334 rev-list --children HEAD
337 :noellipses whatchanged master
338 whatchanged -p master
339 whatchanged --root master
340 :noellipses whatchanged --root master
341 whatchanged --root -p master
342 whatchanged --patch-with-stat master
343 whatchanged --root --patch-with-stat master
344 whatchanged --root --patch-with-stat --summary master
345 # improved by Timo's patch
346 whatchanged --root -c --patch-with-stat --summary master
347 # improved by Timo's patch
348 whatchanged --root --cc --patch-with-stat --summary master
349 whatchanged -SF master
350 :noellipses whatchanged -SF master
351 whatchanged -SF -p master
353 log --patch-with-stat master -- dir/
354 whatchanged --patch-with-stat master -- dir/
355 log --patch-with-stat --summary master -- dir/
356 whatchanged --patch-with-stat --summary master -- dir/
364 show --first-parent master
366 show --stat --summary side
367 show --patch-with-stat side
368 show --patch-with-raw side
369 :noellipses show --patch-with-raw side
370 show --patch-with-stat --summary side
372 format-patch --stdout initial..side
373 format-patch --stdout initial..master^
374 format-patch --stdout initial..master
375 format-patch --stdout --no-numbered initial..master
376 format-patch --stdout --numbered initial..master
377 format-patch --attach --stdout initial..side
378 format-patch --attach --stdout --suffix=.diff initial..side
379 format-patch --attach --stdout initial..master^
380 format-patch --attach --stdout initial..master
381 format-patch --inline --stdout initial..side
382 format-patch --inline --stdout initial..master^
383 format-patch --inline --stdout --numbered-files initial..master
384 format-patch --inline --stdout initial..master
385 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
386 config format.subjectprefix DIFFERENT_PREFIX
387 format-patch --inline --stdout initial..master^^
388 format-patch --stdout --cover-letter -n initial..master^
390 diff --abbrev initial..side
391 diff -U initial..side
392 diff -U1 initial..side
393 diff -r initial..side
394 diff --stat initial..side
395 diff -r --stat initial..side
397 diff --patch-with-stat initial..side
398 diff --patch-with-raw initial..side
399 :noellipses diff --patch-with-raw initial..side
400 diff --patch-with-stat -r initial..side
401 diff --patch-with-raw -r initial..side
402 :noellipses diff --patch-with-raw -r initial..side
403 diff --name-status dir2 dir
404 diff --no-index --name-status dir2 dir
405 diff --no-index --name-status -- dir2 dir
406 diff --no-index dir dir3
407 diff master master^ side
408 # Can't use spaces...
409 diff --line-prefix=abc master master^ side
410 diff --dirstat master~1 master~2
411 diff --dirstat initial rearrange
412 diff --dirstat-by-file initial rearrange
413 diff --dirstat --cc master~1 master
414 # No-index --abbrev and --no-abbrev
416 :noellipses diff --raw initial
417 diff --raw --abbrev=4 initial
418 :noellipses diff --raw --abbrev=4 initial
419 diff --raw --no-abbrev initial
420 diff --no-index --raw dir2 dir
421 :noellipses diff --no-index --raw dir2 dir
422 diff --no-index --raw --abbrev=4 dir2 dir
423 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
424 diff --no-index --raw --no-abbrev dir2 dir
426 diff-tree --pretty --root --stat --compact-summary initial
427 diff-tree --pretty -R --root --stat --compact-summary initial
428 diff-tree --pretty note
429 diff-tree --pretty --notes note
430 diff-tree --format=%N note
431 diff-tree --stat --compact-summary initial mode
432 diff-tree -R --stat --compact-summary initial mode
435 test_expect_success 'log -S requires an argument' '
436 test_must_fail git log -S
439 test_expect_success 'diff --cached on unborn branch' '
440 echo ref: refs/heads/unborn >.git/HEAD &&
441 git diff --cached >result &&
442 process_diffs result >actual &&
443 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
444 test_cmp expected actual
447 test_expect_success 'diff --cached -- file on unborn branch' '
448 git diff --cached -- file0 >result &&
449 process_diffs result >actual &&
450 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
451 test_cmp expected actual
453 test_expect_success 'diff --line-prefix with spaces' '
454 git diff --line-prefix="| | | " --cached -- file0 >result &&
455 process_diffs result >actual &&
456 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
457 test_cmp expected actual
460 test_expect_success 'diff-tree --stdin with log formatting' '
461 cat >expect <<-\EOF &&
466 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
467 test_cmp expect actual