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
132 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
144 BUG "unknown magic $magic" ;;
147 cmd="$magic $cmd" magic=
150 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
151 pfx=$(printf "%04d" $test_count)
152 expect="$TEST_DIRECTORY/t4013/diff.$test"
153 actual="$pfx-diff.$test"
155 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
160 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
164 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
165 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
171 *format-patch* | *-stat*)
172 test_i18ncmp "$expect" "$actual";;
174 test_cmp "$expect" "$actual";;
178 # this is to help developing new tests.
179 cp "$actual" "$expect"
186 diff-tree -r --abbrev initial
187 diff-tree -r --abbrev=4 initial
188 diff-tree --root initial
189 diff-tree --root --abbrev initial
190 :noellipses diff-tree --root --abbrev initial
191 diff-tree --root -r initial
192 diff-tree --root -r --abbrev initial
193 :noellipses diff-tree --root -r --abbrev initial
194 diff-tree --root -r --abbrev=4 initial
195 :noellipses diff-tree --root -r --abbrev=4 initial
197 diff-tree --root -p initial
198 diff-tree --patch-with-stat initial
199 diff-tree --root --patch-with-stat initial
200 diff-tree --patch-with-raw initial
201 diff-tree --root --patch-with-raw initial
203 diff-tree --pretty initial
204 diff-tree --pretty --root initial
205 diff-tree --pretty -p initial
206 diff-tree --pretty --stat initial
207 diff-tree --pretty --summary initial
208 diff-tree --pretty --stat --summary initial
209 diff-tree --pretty --root -p initial
210 diff-tree --pretty --root --stat initial
211 # improved by Timo's patch
212 diff-tree --pretty --root --summary initial
213 # improved by Timo's patch
214 diff-tree --pretty --root --summary -r initial
215 diff-tree --pretty --root --stat --summary initial
216 diff-tree --pretty --patch-with-stat initial
217 diff-tree --pretty --root --patch-with-stat initial
218 diff-tree --pretty --patch-with-raw initial
219 diff-tree --pretty --root --patch-with-raw initial
221 diff-tree --pretty=oneline initial
222 diff-tree --pretty=oneline --root initial
223 diff-tree --pretty=oneline -p initial
224 diff-tree --pretty=oneline --root -p initial
225 diff-tree --pretty=oneline --patch-with-stat initial
226 # improved by Timo's patch
227 diff-tree --pretty=oneline --root --patch-with-stat initial
228 diff-tree --pretty=oneline --patch-with-raw initial
229 diff-tree --pretty=oneline --root --patch-with-raw initial
231 diff-tree --pretty side
232 diff-tree --pretty -p side
233 diff-tree --pretty --patch-with-stat side
235 diff-tree initial mode
236 diff-tree --stat initial mode
237 diff-tree --summary initial mode
241 diff-tree -p -m master
243 diff-tree -c --abbrev master
244 :noellipses diff-tree -c --abbrev master
245 diff-tree --cc master
246 # stat only should show the diffstat with the first parent
247 diff-tree -c --stat master
248 diff-tree --cc --stat master
249 diff-tree -c --stat --summary master
250 diff-tree --cc --stat --summary master
251 # stat summary should show the diffstat and summary with the first parent
252 diff-tree -c --stat --summary side
253 diff-tree --cc --stat --summary side
254 diff-tree --cc --shortstat master
255 diff-tree --cc --summary REVERSE
256 # improved by Timo's patch
257 diff-tree --cc --patch-with-stat master
258 # improved by Timo's patch
259 diff-tree --cc --patch-with-stat --summary master
261 diff-tree --cc --patch-with-stat --summary side
267 log --patch-with-stat master
268 log --root --patch-with-stat master
269 log --root --patch-with-stat --summary master
270 # improved by Timo's patch
271 log --root -c --patch-with-stat --summary master
272 # improved by Timo's patch
273 log --root --cc --patch-with-stat --summary master
274 log -p --first-parent master
275 log -m -p --first-parent master
280 log -SF master --max-count=0
281 log -SF master --max-count=1
282 log -SF master --max-count=2
285 log -GF -p --pickaxe-all master
287 log --decorate=full --all
289 rev-list --parents HEAD
290 rev-list --children HEAD
293 :noellipses whatchanged master
294 whatchanged -p master
295 whatchanged --root master
296 :noellipses whatchanged --root master
297 whatchanged --root -p master
298 whatchanged --patch-with-stat master
299 whatchanged --root --patch-with-stat master
300 whatchanged --root --patch-with-stat --summary master
301 # improved by Timo's patch
302 whatchanged --root -c --patch-with-stat --summary master
303 # improved by Timo's patch
304 whatchanged --root --cc --patch-with-stat --summary master
305 whatchanged -SF master
306 :noellipses whatchanged -SF master
307 whatchanged -SF -p master
309 log --patch-with-stat master -- dir/
310 whatchanged --patch-with-stat master -- dir/
311 log --patch-with-stat --summary master -- dir/
312 whatchanged --patch-with-stat --summary master -- dir/
320 show --first-parent master
322 show --stat --summary side
323 show --patch-with-stat side
324 show --patch-with-raw side
325 :noellipses show --patch-with-raw side
326 show --patch-with-stat --summary side
328 format-patch --stdout initial..side
329 format-patch --stdout initial..master^
330 format-patch --stdout initial..master
331 format-patch --stdout --no-numbered initial..master
332 format-patch --stdout --numbered initial..master
333 format-patch --attach --stdout initial..side
334 format-patch --attach --stdout --suffix=.diff initial..side
335 format-patch --attach --stdout initial..master^
336 format-patch --attach --stdout initial..master
337 format-patch --inline --stdout initial..side
338 format-patch --inline --stdout initial..master^
339 format-patch --inline --stdout --numbered-files initial..master
340 format-patch --inline --stdout initial..master
341 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
342 config format.subjectprefix DIFFERENT_PREFIX
343 format-patch --inline --stdout initial..master^^
344 format-patch --stdout --cover-letter -n initial..master^
346 diff --abbrev initial..side
347 diff -U initial..side
348 diff -U1 initial..side
349 diff -r initial..side
350 diff --stat initial..side
351 diff -r --stat initial..side
353 diff --patch-with-stat initial..side
354 diff --patch-with-raw initial..side
355 :noellipses diff --patch-with-raw initial..side
356 diff --patch-with-stat -r initial..side
357 diff --patch-with-raw -r initial..side
358 :noellipses diff --patch-with-raw -r initial..side
359 diff --name-status dir2 dir
360 diff --no-index --name-status dir2 dir
361 diff --no-index --name-status -- dir2 dir
362 diff --no-index dir dir3
363 diff master master^ side
364 # Can't use spaces...
365 diff --line-prefix=abc master master^ side
366 diff --dirstat master~1 master~2
367 diff --dirstat initial rearrange
368 diff --dirstat-by-file initial rearrange
369 diff --dirstat --cc master~1 master
370 # No-index --abbrev and --no-abbrev
372 :noellipses diff --raw initial
373 diff --raw --abbrev=4 initial
374 :noellipses diff --raw --abbrev=4 initial
375 diff --raw --no-abbrev initial
376 diff --no-index --raw dir2 dir
377 :noellipses diff --no-index --raw dir2 dir
378 diff --no-index --raw --abbrev=4 dir2 dir
379 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
380 diff --no-index --raw --no-abbrev dir2 dir
382 diff-tree --pretty --root --stat --compact-summary initial
383 diff-tree --pretty -R --root --stat --compact-summary initial
384 diff-tree --pretty note
385 diff-tree --pretty --notes note
386 diff-tree --format=%N note
387 diff-tree --stat --compact-summary initial mode
388 diff-tree -R --stat --compact-summary initial mode
391 test_expect_success 'log -S requires an argument' '
392 test_must_fail git log -S
395 test_expect_success 'diff --cached on unborn branch' '
396 echo ref: refs/heads/unborn >.git/HEAD &&
397 git diff --cached >result &&
398 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
401 test_expect_success 'diff --cached -- file on unborn branch' '
402 git diff --cached -- file0 >result &&
403 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
405 test_expect_success 'diff --line-prefix with spaces' '
406 git diff --line-prefix="| | | " --cached -- file0 >result &&
407 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
410 test_expect_success 'diff-tree --stdin with log formatting' '
411 cat >expect <<-\EOF &&
416 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
417 test_cmp expect actual