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 # Same merge as master, but with parents reversed. Hide it in a
99 # pseudo-ref to avoid impacting tests with --all.
100 commit=$(echo reverse |
101 git commit-tree -p master^2 -p master^1 master^{tree}) &&
102 git update-ref REVERSE $commit &&
104 git config diff.renames false &&
111 * [master] Merge branch 'side'
112 ! [rearrange] Rearranged lines in dir/sub
115 + [rearrange] Rearranged lines in dir/sub
116 - [master] Merge branch 'side'
120 +*++ [initial] Initial
123 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
135 BUG "unknown magic $magic" ;;
138 cmd="$magic $cmd" magic=
141 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
142 pfx=$(printf "%04d" $test_count)
143 expect="$TEST_DIRECTORY/t4013/diff.$test"
144 actual="$pfx-diff.$test"
146 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
151 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
155 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
156 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
162 *format-patch* | *-stat*)
163 test_i18ncmp "$expect" "$actual";;
165 test_cmp "$expect" "$actual";;
169 # this is to help developing new tests.
170 cp "$actual" "$expect"
177 diff-tree -r --abbrev initial
178 diff-tree -r --abbrev=4 initial
179 diff-tree --root initial
180 diff-tree --root --abbrev initial
181 :noellipses diff-tree --root --abbrev initial
182 diff-tree --root -r initial
183 diff-tree --root -r --abbrev initial
184 :noellipses diff-tree --root -r --abbrev initial
185 diff-tree --root -r --abbrev=4 initial
186 :noellipses diff-tree --root -r --abbrev=4 initial
188 diff-tree --root -p initial
189 diff-tree --patch-with-stat initial
190 diff-tree --root --patch-with-stat initial
191 diff-tree --patch-with-raw initial
192 diff-tree --root --patch-with-raw initial
194 diff-tree --pretty initial
195 diff-tree --pretty --root initial
196 diff-tree --pretty -p initial
197 diff-tree --pretty --stat initial
198 diff-tree --pretty --summary initial
199 diff-tree --pretty --stat --summary initial
200 diff-tree --pretty --root -p initial
201 diff-tree --pretty --root --stat initial
202 # improved by Timo's patch
203 diff-tree --pretty --root --summary initial
204 # improved by Timo's patch
205 diff-tree --pretty --root --summary -r initial
206 diff-tree --pretty --root --stat --summary initial
207 diff-tree --pretty --patch-with-stat initial
208 diff-tree --pretty --root --patch-with-stat initial
209 diff-tree --pretty --patch-with-raw initial
210 diff-tree --pretty --root --patch-with-raw initial
212 diff-tree --pretty=oneline initial
213 diff-tree --pretty=oneline --root initial
214 diff-tree --pretty=oneline -p initial
215 diff-tree --pretty=oneline --root -p initial
216 diff-tree --pretty=oneline --patch-with-stat initial
217 # improved by Timo's patch
218 diff-tree --pretty=oneline --root --patch-with-stat initial
219 diff-tree --pretty=oneline --patch-with-raw initial
220 diff-tree --pretty=oneline --root --patch-with-raw initial
222 diff-tree --pretty side
223 diff-tree --pretty -p side
224 diff-tree --pretty --patch-with-stat side
226 diff-tree initial mode
227 diff-tree --stat initial mode
228 diff-tree --summary initial mode
232 diff-tree -p -m master
234 diff-tree -c --abbrev master
235 :noellipses diff-tree -c --abbrev master
236 diff-tree --cc master
237 # stat only should show the diffstat with the first parent
238 diff-tree -c --stat master
239 diff-tree --cc --stat master
240 diff-tree -c --stat --summary master
241 diff-tree --cc --stat --summary master
242 # stat summary should show the diffstat and summary with the first parent
243 diff-tree -c --stat --summary side
244 diff-tree --cc --stat --summary side
245 diff-tree --cc --shortstat master
246 diff-tree --cc --summary REVERSE
247 # improved by Timo's patch
248 diff-tree --cc --patch-with-stat master
249 # improved by Timo's patch
250 diff-tree --cc --patch-with-stat --summary master
252 diff-tree --cc --patch-with-stat --summary side
258 log --patch-with-stat master
259 log --root --patch-with-stat master
260 log --root --patch-with-stat --summary master
261 # improved by Timo's patch
262 log --root -c --patch-with-stat --summary master
263 # improved by Timo's patch
264 log --root --cc --patch-with-stat --summary master
265 log -p --first-parent master
266 log -m -p --first-parent master
271 log -SF master --max-count=0
272 log -SF master --max-count=1
273 log -SF master --max-count=2
276 log -GF -p --pickaxe-all master
278 log --decorate=full --all
280 rev-list --parents HEAD
281 rev-list --children HEAD
284 :noellipses whatchanged master
285 whatchanged -p master
286 whatchanged --root master
287 :noellipses whatchanged --root master
288 whatchanged --root -p master
289 whatchanged --patch-with-stat master
290 whatchanged --root --patch-with-stat master
291 whatchanged --root --patch-with-stat --summary master
292 # improved by Timo's patch
293 whatchanged --root -c --patch-with-stat --summary master
294 # improved by Timo's patch
295 whatchanged --root --cc --patch-with-stat --summary master
296 whatchanged -SF master
297 :noellipses whatchanged -SF master
298 whatchanged -SF -p master
300 log --patch-with-stat master -- dir/
301 whatchanged --patch-with-stat master -- dir/
302 log --patch-with-stat --summary master -- dir/
303 whatchanged --patch-with-stat --summary master -- dir/
311 show --first-parent master
313 show --stat --summary side
314 show --patch-with-stat side
315 show --patch-with-raw side
316 :noellipses show --patch-with-raw side
317 show --patch-with-stat --summary side
319 format-patch --stdout initial..side
320 format-patch --stdout initial..master^
321 format-patch --stdout initial..master
322 format-patch --stdout --no-numbered initial..master
323 format-patch --stdout --numbered initial..master
324 format-patch --attach --stdout initial..side
325 format-patch --attach --stdout --suffix=.diff initial..side
326 format-patch --attach --stdout initial..master^
327 format-patch --attach --stdout initial..master
328 format-patch --inline --stdout initial..side
329 format-patch --inline --stdout initial..master^
330 format-patch --inline --stdout --numbered-files initial..master
331 format-patch --inline --stdout initial..master
332 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
333 config format.subjectprefix DIFFERENT_PREFIX
334 format-patch --inline --stdout initial..master^^
335 format-patch --stdout --cover-letter -n initial..master^
337 diff --abbrev initial..side
338 diff -U initial..side
339 diff -U1 initial..side
340 diff -r initial..side
341 diff --stat initial..side
342 diff -r --stat initial..side
344 diff --patch-with-stat initial..side
345 diff --patch-with-raw initial..side
346 :noellipses diff --patch-with-raw initial..side
347 diff --patch-with-stat -r initial..side
348 diff --patch-with-raw -r initial..side
349 :noellipses diff --patch-with-raw -r initial..side
350 diff --name-status dir2 dir
351 diff --no-index --name-status dir2 dir
352 diff --no-index --name-status -- dir2 dir
353 diff --no-index dir dir3
354 diff master master^ side
355 # Can't use spaces...
356 diff --line-prefix=abc master master^ side
357 diff --dirstat master~1 master~2
358 diff --dirstat initial rearrange
359 diff --dirstat-by-file initial rearrange
360 diff --dirstat --cc master~1 master
361 # No-index --abbrev and --no-abbrev
363 :noellipses diff --raw initial
364 diff --raw --abbrev=4 initial
365 :noellipses diff --raw --abbrev=4 initial
366 diff --raw --no-abbrev initial
367 diff --no-index --raw dir2 dir
368 :noellipses diff --no-index --raw dir2 dir
369 diff --no-index --raw --abbrev=4 dir2 dir
370 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
371 diff --no-index --raw --no-abbrev dir2 dir
373 diff-tree --pretty --root --stat --compact-summary initial
374 diff-tree --pretty -R --root --stat --compact-summary initial
375 diff-tree --stat --compact-summary initial mode
376 diff-tree -R --stat --compact-summary initial mode
379 test_expect_success 'log -S requires an argument' '
380 test_must_fail git log -S
383 test_expect_success 'diff --cached on unborn branch' '
384 echo ref: refs/heads/unborn >.git/HEAD &&
385 git diff --cached >result &&
386 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
389 test_expect_success 'diff --cached -- file on unborn branch' '
390 git diff --cached -- file0 >result &&
391 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
393 test_expect_success 'diff --line-prefix with spaces' '
394 git diff --line-prefix="| | | " --cached -- file0 >result &&
395 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
398 test_expect_success 'diff-tree --stdin with log formatting' '
399 cat >expect <<-\EOF &&
404 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
405 test_cmp expect actual