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
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
--no-diff-merges -p --first-parent master
301 log
--diff-merges=off
-p --first-parent master
302 log
--first-parent --diff-merges=off
-p master
303 log
-p --first-parent master
304 log
-m -p --first-parent master
309 log
-SF master
--max-count=0
310 log
-SF master
--max-count=1
311 log
-SF master
--max-count=2
314 log
-GF -p --pickaxe-all master
316 log
--decorate=full
--all
318 rev-list
--parents HEAD
319 rev-list
--children HEAD
322 :noellipses whatchanged master
323 whatchanged
-p master
324 whatchanged
--root master
325 :noellipses whatchanged
--root master
326 whatchanged
--root -p master
327 whatchanged
--patch-with-stat master
328 whatchanged
--root --patch-with-stat master
329 whatchanged
--root --patch-with-stat --summary master
330 # improved by Timo's patch
331 whatchanged
--root -c --patch-with-stat --summary master
332 # improved by Timo's patch
333 whatchanged
--root --cc --patch-with-stat --summary master
334 whatchanged
-SF master
335 :noellipses whatchanged
-SF master
336 whatchanged
-SF -p master
338 log
--patch-with-stat master
-- dir
/
339 whatchanged
--patch-with-stat master
-- dir
/
340 log
--patch-with-stat --summary master
-- dir
/
341 whatchanged
--patch-with-stat --summary master
-- dir
/
349 show
--first-parent master
351 show
--stat --summary side
352 show
--patch-with-stat side
353 show
--patch-with-raw side
354 :noellipses show
--patch-with-raw side
355 show
--patch-with-stat --summary side
357 format-patch
--stdout initial..side
358 format-patch
--stdout initial..master^
359 format-patch
--stdout initial..master
360 format-patch
--stdout --no-numbered initial..master
361 format-patch
--stdout --numbered initial..master
362 format-patch
--attach --stdout initial..side
363 format-patch
--attach --stdout --suffix=.
diff initial..side
364 format-patch
--attach --stdout initial..master^
365 format-patch
--attach --stdout initial..master
366 format-patch
--inline --stdout initial..side
367 format-patch
--inline --stdout initial..master^
368 format-patch
--inline --stdout --numbered-files initial..master
369 format-patch
--inline --stdout initial..master
370 format-patch
--inline --stdout --subject-prefix=TESTCASE initial..master
371 config format.subjectprefix DIFFERENT_PREFIX
372 format-patch
--inline --stdout initial..master^^
373 format-patch
--stdout --cover-letter -n initial..master^
375 diff --abbrev initial..side
376 diff -U initial..side
377 diff -U1 initial..side
378 diff -r initial..side
379 diff --stat initial..side
380 diff -r --stat initial..side
382 diff --patch-with-stat initial..side
383 diff --patch-with-raw initial..side
384 :noellipses
diff --patch-with-raw initial..side
385 diff --patch-with-stat -r initial..side
386 diff --patch-with-raw -r initial..side
387 :noellipses
diff --patch-with-raw -r initial..side
388 diff --name-status dir2 dir
389 diff --no-index --name-status dir2 dir
390 diff --no-index --name-status -- dir2 dir
391 diff --no-index dir dir3
392 diff master master^ side
393 # Can't use spaces...
394 diff --line-prefix=abc master master^ side
395 diff --dirstat master~
1 master~
2
396 diff --dirstat initial rearrange
397 diff --dirstat-by-file initial rearrange
398 diff --dirstat --cc master~
1 master
399 # No-index --abbrev and --no-abbrev
401 :noellipses
diff --raw initial
402 diff --raw --abbrev=4 initial
403 :noellipses
diff --raw --abbrev=4 initial
404 diff --raw --no-abbrev initial
405 diff --no-index --raw dir2 dir
406 :noellipses
diff --no-index --raw dir2 dir
407 diff --no-index --raw --abbrev=4 dir2 dir
408 :noellipses
diff --no-index --raw --abbrev=4 dir2 dir
409 diff --no-index --raw --no-abbrev dir2 dir
411 diff-tree
--pretty --root --stat --compact-summary initial
412 diff-tree
--pretty -R --root --stat --compact-summary initial
413 diff-tree
--pretty note
414 diff-tree
--pretty --notes note
415 diff-tree
--format=%N note
416 diff-tree
--stat --compact-summary initial mode
417 diff-tree
-R --stat --compact-summary initial mode
420 test_expect_success
'log -S requires an argument' '
421 test_must_fail git log -S
424 test_expect_success
'diff --cached on unborn branch' '
425 echo ref: refs/heads/unborn >.git/HEAD &&
426 git diff --cached >result &&
427 process_diffs result >actual &&
428 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
429 test_cmp expected actual
432 test_expect_success
'diff --cached -- file on unborn branch' '
433 git diff --cached -- file0 >result &&
434 process_diffs result >actual &&
435 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
436 test_cmp expected actual
438 test_expect_success
'diff --line-prefix with spaces' '
439 git diff --line-prefix="| | | " --cached -- file0 >result &&
440 process_diffs result >actual &&
441 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
442 test_cmp expected actual
445 test_expect_success
'diff-tree --stdin with log formatting' '
446 cat >expect <<-\EOF &&
451 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
452 test_cmp expect actual