bloom: ignore renames when computing changed paths
[git.git] / t / t4013-diff-various.sh
blobdde3f11fec364c22470b56f44508c0cd3284e4b2
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Various diff formatting options'
8 . ./test-lib.sh
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 &&
16 mkdir dir &&
17 mkdir dir2 &&
18 for i in 1 2 3; do echo $i; done >file0 &&
19 for i in A B; do echo $i; done >dir/sub &&
20 cat file0 >file2 &&
21 git add file0 file2 dir/sub &&
22 git commit -m Initial &&
24 git branch initial &&
25 git branch side &&
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 &&
33 rm -f file2 &&
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 &&
42 git add 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 &&
51 git checkout side &&
52 for i in A B C; do echo $i; done >>file0 &&
53 for i in 1 2; do echo $i; done >>dir/sub &&
54 cat dir/sub >file3 &&
55 git add file3 &&
56 git update-index file0 dir/sub &&
57 git commit -m Side &&
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 &&
74 mkdir dir3 &&
75 cp dir/sub dir3/sub &&
76 test-tool chmtime +1 dir3/sub &&
78 git config log.showroot false &&
79 git commit --amend &&
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 &&
86 git add 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 &&
106 git show-branch
109 : <<\EOF
110 ! [initial] Initial
111 * [master] Merge branch 'side'
112 ! [rearrange] Rearranged lines in dir/sub
113 ! [side] Side
114 ----
115 + [rearrange] Rearranged lines in dir/sub
116 - [master] Merge branch 'side'
117 * + [side] Side
118 * [master^] Third
119 * [master~2] Second
120 +*++ [initial] Initial
123 process_diffs () {
124 _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" &&
125 _x07="$_x05[0-9a-f][0-9a-f]" &&
126 sed -e "s/$OID_REGEX/$ZERO_OID/g" \
127 -e "s/From $_x40 /From $ZERO_OID /" \
128 -e "s/from $_x40)/from $ZERO_OID)/" \
129 -e "s/commit $_x40\$/commit $ZERO_OID/" \
130 -e "s/commit $_x40 (/commit $ZERO_OID (/" \
131 -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \
132 -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \
133 -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \
134 -e "s/^$_x40 /$ZERO_OID /" \
135 -e "s/^$_x40$/$ZERO_OID/" \
136 -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \
137 -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \
138 -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \
139 -e "s/$_x07 $_x07 /fffffff fffffff /g" \
140 -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \
141 -e "s/$_x07\.\.\./fffffff.../g" \
142 -e "s/ $_x04\.\.\./ ffff.../g" \
143 -e "s/ $_x04/ ffff/g" \
144 "$1"
147 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
148 while read magic cmd
150 case "$magic" in
151 '' | '#'*)
152 continue ;;
154 magic=${magic#:}
155 label="$magic-$cmd"
156 case "$magic" in
157 noellipses) ;;
159 BUG "unknown magic $magic" ;;
160 esac ;;
162 cmd="$magic $cmd" magic=
163 label="$cmd" ;;
164 esac
165 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
166 pfx=$(printf "%04d" $test_count)
167 expect="$TEST_DIRECTORY/t4013/diff.$test"
168 actual="$pfx-diff.$test"
170 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
172 echo "$ git $cmd"
173 case "$magic" in
175 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
176 noellipses)
177 git $cmd ;;
178 esac |
179 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
180 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
181 echo "\$"
182 } >"$actual" &&
183 if test -f "$expect"
184 then
185 process_diffs "$actual" >actual &&
186 process_diffs "$expect" >expect &&
187 case $cmd in
188 *format-patch* | *-stat*)
189 test_i18ncmp expect actual;;
191 test_cmp expect actual;;
192 esac &&
193 rm -f "$actual" actual expect
194 else
195 # this is to help developing new tests.
196 cp "$actual" "$expect"
197 false
200 done <<\EOF
201 diff-tree initial
202 diff-tree -r initial
203 diff-tree -r --abbrev initial
204 diff-tree -r --abbrev=4 initial
205 diff-tree --root initial
206 diff-tree --root --abbrev initial
207 :noellipses diff-tree --root --abbrev initial
208 diff-tree --root -r initial
209 diff-tree --root -r --abbrev initial
210 :noellipses diff-tree --root -r --abbrev initial
211 diff-tree --root -r --abbrev=4 initial
212 :noellipses diff-tree --root -r --abbrev=4 initial
213 diff-tree -p initial
214 diff-tree --root -p initial
215 diff-tree --patch-with-stat initial
216 diff-tree --root --patch-with-stat initial
217 diff-tree --patch-with-raw initial
218 diff-tree --root --patch-with-raw initial
220 diff-tree --pretty initial
221 diff-tree --pretty --root initial
222 diff-tree --pretty -p initial
223 diff-tree --pretty --stat initial
224 diff-tree --pretty --summary initial
225 diff-tree --pretty --stat --summary initial
226 diff-tree --pretty --root -p initial
227 diff-tree --pretty --root --stat initial
228 # improved by Timo's patch
229 diff-tree --pretty --root --summary initial
230 # improved by Timo's patch
231 diff-tree --pretty --root --summary -r initial
232 diff-tree --pretty --root --stat --summary initial
233 diff-tree --pretty --patch-with-stat initial
234 diff-tree --pretty --root --patch-with-stat initial
235 diff-tree --pretty --patch-with-raw initial
236 diff-tree --pretty --root --patch-with-raw initial
238 diff-tree --pretty=oneline initial
239 diff-tree --pretty=oneline --root initial
240 diff-tree --pretty=oneline -p initial
241 diff-tree --pretty=oneline --root -p initial
242 diff-tree --pretty=oneline --patch-with-stat initial
243 # improved by Timo's patch
244 diff-tree --pretty=oneline --root --patch-with-stat initial
245 diff-tree --pretty=oneline --patch-with-raw initial
246 diff-tree --pretty=oneline --root --patch-with-raw initial
248 diff-tree --pretty side
249 diff-tree --pretty -p side
250 diff-tree --pretty --patch-with-stat side
252 diff-tree initial mode
253 diff-tree --stat initial mode
254 diff-tree --summary initial mode
256 diff-tree master
257 diff-tree -p master
258 diff-tree -p -m master
259 diff-tree -c master
260 diff-tree -c --abbrev master
261 :noellipses diff-tree -c --abbrev master
262 diff-tree --cc master
263 # stat only should show the diffstat with the first parent
264 diff-tree -c --stat master
265 diff-tree --cc --stat master
266 diff-tree -c --stat --summary master
267 diff-tree --cc --stat --summary master
268 # stat summary should show the diffstat and summary with the first parent
269 diff-tree -c --stat --summary side
270 diff-tree --cc --stat --summary side
271 diff-tree --cc --shortstat master
272 diff-tree --cc --summary REVERSE
273 # improved by Timo's patch
274 diff-tree --cc --patch-with-stat master
275 # improved by Timo's patch
276 diff-tree --cc --patch-with-stat --summary master
277 # this is correct
278 diff-tree --cc --patch-with-stat --summary side
280 log master
281 log -p master
282 log --root master
283 log --root -p master
284 log --patch-with-stat master
285 log --root --patch-with-stat master
286 log --root --patch-with-stat --summary master
287 # improved by Timo's patch
288 log --root -c --patch-with-stat --summary master
289 # improved by Timo's patch
290 log --root --cc --patch-with-stat --summary master
291 log -p --first-parent master
292 log -m -p --first-parent master
293 log -m -p master
294 log -SF master
295 log -S F master
296 log -SF -p master
297 log -SF master --max-count=0
298 log -SF master --max-count=1
299 log -SF master --max-count=2
300 log -GF master
301 log -GF -p master
302 log -GF -p --pickaxe-all master
303 log --decorate --all
304 log --decorate=full --all
306 rev-list --parents HEAD
307 rev-list --children HEAD
309 whatchanged master
310 :noellipses whatchanged master
311 whatchanged -p master
312 whatchanged --root master
313 :noellipses whatchanged --root master
314 whatchanged --root -p master
315 whatchanged --patch-with-stat master
316 whatchanged --root --patch-with-stat master
317 whatchanged --root --patch-with-stat --summary master
318 # improved by Timo's patch
319 whatchanged --root -c --patch-with-stat --summary master
320 # improved by Timo's patch
321 whatchanged --root --cc --patch-with-stat --summary master
322 whatchanged -SF master
323 :noellipses whatchanged -SF master
324 whatchanged -SF -p master
326 log --patch-with-stat master -- dir/
327 whatchanged --patch-with-stat master -- dir/
328 log --patch-with-stat --summary master -- dir/
329 whatchanged --patch-with-stat --summary master -- dir/
331 show initial
332 show --root initial
333 show side
334 show master
335 show -c master
336 show -m master
337 show --first-parent master
338 show --stat side
339 show --stat --summary side
340 show --patch-with-stat side
341 show --patch-with-raw side
342 :noellipses show --patch-with-raw side
343 show --patch-with-stat --summary side
345 format-patch --stdout initial..side
346 format-patch --stdout initial..master^
347 format-patch --stdout initial..master
348 format-patch --stdout --no-numbered initial..master
349 format-patch --stdout --numbered initial..master
350 format-patch --attach --stdout initial..side
351 format-patch --attach --stdout --suffix=.diff initial..side
352 format-patch --attach --stdout initial..master^
353 format-patch --attach --stdout initial..master
354 format-patch --inline --stdout initial..side
355 format-patch --inline --stdout initial..master^
356 format-patch --inline --stdout --numbered-files initial..master
357 format-patch --inline --stdout initial..master
358 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
359 config format.subjectprefix DIFFERENT_PREFIX
360 format-patch --inline --stdout initial..master^^
361 format-patch --stdout --cover-letter -n initial..master^
363 diff --abbrev initial..side
364 diff -U initial..side
365 diff -U1 initial..side
366 diff -r initial..side
367 diff --stat initial..side
368 diff -r --stat initial..side
369 diff initial..side
370 diff --patch-with-stat initial..side
371 diff --patch-with-raw initial..side
372 :noellipses diff --patch-with-raw initial..side
373 diff --patch-with-stat -r initial..side
374 diff --patch-with-raw -r initial..side
375 :noellipses diff --patch-with-raw -r initial..side
376 diff --name-status dir2 dir
377 diff --no-index --name-status dir2 dir
378 diff --no-index --name-status -- dir2 dir
379 diff --no-index dir dir3
380 diff master master^ side
381 # Can't use spaces...
382 diff --line-prefix=abc master master^ side
383 diff --dirstat master~1 master~2
384 diff --dirstat initial rearrange
385 diff --dirstat-by-file initial rearrange
386 diff --dirstat --cc master~1 master
387 # No-index --abbrev and --no-abbrev
388 diff --raw initial
389 :noellipses diff --raw initial
390 diff --raw --abbrev=4 initial
391 :noellipses diff --raw --abbrev=4 initial
392 diff --raw --no-abbrev initial
393 diff --no-index --raw dir2 dir
394 :noellipses diff --no-index --raw dir2 dir
395 diff --no-index --raw --abbrev=4 dir2 dir
396 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
397 diff --no-index --raw --no-abbrev dir2 dir
399 diff-tree --pretty --root --stat --compact-summary initial
400 diff-tree --pretty -R --root --stat --compact-summary initial
401 diff-tree --stat --compact-summary initial mode
402 diff-tree -R --stat --compact-summary initial mode
405 test_expect_success 'log -S requires an argument' '
406 test_must_fail git log -S
409 test_expect_success 'diff --cached on unborn branch' '
410 echo ref: refs/heads/unborn >.git/HEAD &&
411 git diff --cached >result &&
412 process_diffs result >actual &&
413 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
414 test_cmp expected actual
417 test_expect_success 'diff --cached -- file on unborn branch' '
418 git diff --cached -- file0 >result &&
419 process_diffs result >actual &&
420 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
421 test_cmp expected actual
423 test_expect_success 'diff --line-prefix with spaces' '
424 git diff --line-prefix="| | | " --cached -- file0 >result &&
425 process_diffs result >actual &&
426 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
427 test_cmp expected actual
430 test_expect_success 'diff-tree --stdin with log formatting' '
431 cat >expect <<-\EOF &&
432 Side
433 Third
434 Second
436 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
437 test_cmp expect actual
440 test_done