]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4013-diff-various.sh
Merge branch 'pb/doc-modules-git-work-tree-typofix' into maint
[thirdparty/git.git] / t / t4013-diff-various.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='Various diff formatting options'
7
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/diff-lib.sh
10
11 test_expect_success setup '
12
13 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
14 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
15 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
16
17 mkdir dir &&
18 mkdir dir2 &&
19 for i in 1 2 3; do echo $i; done >file0 &&
20 for i in A B; do echo $i; done >dir/sub &&
21 cat file0 >file2 &&
22 git add file0 file2 dir/sub &&
23 git commit -m Initial &&
24
25 git branch initial &&
26 git branch side &&
27
28 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
29 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
30 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
31
32 for i in 4 5 6; do echo $i; done >>file0 &&
33 for i in C D; do echo $i; done >>dir/sub &&
34 rm -f file2 &&
35 git update-index --remove file0 file2 dir/sub &&
36 git commit -m "Second${LF}${LF}This is the second commit." &&
37
38 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
39 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
40 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
41
42 for i in A B C; do echo $i; done >file1 &&
43 git add file1 &&
44 for i in E F; do echo $i; done >>dir/sub &&
45 git update-index dir/sub &&
46 git commit -m Third &&
47
48 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
49 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
50 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
51
52 git checkout side &&
53 for i in A B C; do echo $i; done >>file0 &&
54 for i in 1 2; do echo $i; done >>dir/sub &&
55 cat dir/sub >file3 &&
56 git add file3 &&
57 git update-index file0 dir/sub &&
58 git commit -m Side &&
59
60 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
61 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
62 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
63
64 git checkout master &&
65 git pull -s ours . side &&
66
67 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
68 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
69 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
70
71 for i in A B C; do echo $i; done >>file0 &&
72 for i in 1 2; do echo $i; done >>dir/sub &&
73 git update-index file0 dir/sub &&
74
75 mkdir dir3 &&
76 cp dir/sub dir3/sub &&
77 test-tool chmtime +1 dir3/sub &&
78
79 git config log.showroot false &&
80 git commit --amend &&
81
82 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
83 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
84 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
85 git checkout -b rearrange initial &&
86 for i in B A; do echo $i; done >dir/sub &&
87 git add dir/sub &&
88 git commit -m "Rearranged lines in dir/sub" &&
89 git checkout master &&
90
91 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
92 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
93 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
94 git checkout -b mode initial &&
95 git update-index --chmod=+x file0 &&
96 git commit -m "update mode" &&
97 git checkout -f master &&
98
99 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
100 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
101 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
102 git checkout -b note initial &&
103 git update-index --chmod=+x file2 &&
104 git commit -m "update mode (file2)" &&
105 git notes add -m "note" &&
106 git checkout -f master &&
107
108 # Same merge as master, but with parents reversed. Hide it in a
109 # pseudo-ref to avoid impacting tests with --all.
110 commit=$(echo reverse |
111 git commit-tree -p master^2 -p master^1 master^{tree}) &&
112 git update-ref REVERSE $commit &&
113
114 git config diff.renames false &&
115
116 git show-branch
117 '
118
119 : <<\EOF
120 ! [initial] Initial
121 * [master] Merge branch 'side'
122 ! [rearrange] Rearranged lines in dir/sub
123 ! [side] Side
124 ----
125 + [rearrange] Rearranged lines in dir/sub
126 - [master] Merge branch 'side'
127 * + [side] Side
128 * [master^] Third
129 * [master~2] Second
130 +*++ [initial] Initial
131 EOF
132
133 process_diffs () {
134 perl -e '
135 my $oid_length = length($ARGV[0]);
136 my $x40 = "[0-9a-f]{40}";
137 my $xab = "[0-9a-f]{4,16}";
138 my $orx = "[0-9a-f]" x $oid_length;
139
140 sub munge_oid {
141 my ($oid) = @_;
142 my $x;
143
144 return "" unless length $oid;
145
146 if ($oid =~ /^(100644|100755|120000)$/) {
147 return $oid;
148 }
149
150 if ($oid =~ /^0*$/) {
151 $x = "0";
152 } else {
153 $x = "f";
154 }
155
156 if (length($oid) == 40) {
157 return $x x $oid_length;
158 } else {
159 return $x x length($oid);
160 }
161 }
162
163 while (<STDIN>) {
164 s/($orx)/munge_oid($1)/ge;
165 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
166 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
167 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
168 s/^($x40)($| )/munge_oid($1) . $2/e;
169 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
170 print;
171 }
172 ' "$ZERO_OID" <"$1"
173 }
174
175 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
176 while read magic cmd
177 do
178 case "$magic" in
179 '' | '#'*)
180 continue ;;
181 :*)
182 magic=${magic#:}
183 label="$magic-$cmd"
184 case "$magic" in
185 noellipses) ;;
186 *)
187 BUG "unknown magic $magic" ;;
188 esac ;;
189 *)
190 cmd="$magic $cmd" magic=
191 label="$cmd" ;;
192 esac
193 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
194 pfx=$(printf "%04d" $test_count)
195 expect="$TEST_DIRECTORY/t4013/diff.$test"
196 actual="$pfx-diff.$test"
197
198 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
199 {
200 echo "$ git $cmd"
201 case "$magic" in
202 "")
203 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
204 noellipses)
205 git $cmd ;;
206 esac |
207 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
208 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
209 echo "\$"
210 } >"$actual" &&
211 if test -f "$expect"
212 then
213 process_diffs "$actual" >actual &&
214 process_diffs "$expect" >expect &&
215 case $cmd in
216 *format-patch* | *-stat*)
217 test_i18ncmp expect actual;;
218 *)
219 test_cmp expect actual;;
220 esac &&
221 rm -f "$actual" actual expect
222 else
223 # this is to help developing new tests.
224 cp "$actual" "$expect"
225 false
226 fi
227 '
228 done <<\EOF
229 diff-tree initial
230 diff-tree -r initial
231 diff-tree -r --abbrev initial
232 diff-tree -r --abbrev=4 initial
233 diff-tree --root initial
234 diff-tree --root --abbrev initial
235 :noellipses diff-tree --root --abbrev initial
236 diff-tree --root -r initial
237 diff-tree --root -r --abbrev initial
238 :noellipses diff-tree --root -r --abbrev initial
239 diff-tree --root -r --abbrev=4 initial
240 :noellipses diff-tree --root -r --abbrev=4 initial
241 diff-tree -p initial
242 diff-tree --root -p initial
243 diff-tree --root -p --abbrev=10 initial
244 diff-tree --root -p --full-index initial
245 diff-tree --root -p --full-index --abbrev=10 initial
246 diff-tree --patch-with-stat initial
247 diff-tree --root --patch-with-stat initial
248 diff-tree --patch-with-raw initial
249 diff-tree --root --patch-with-raw initial
250
251 diff-tree --pretty initial
252 diff-tree --pretty --root initial
253 diff-tree --pretty -p initial
254 diff-tree --pretty --stat initial
255 diff-tree --pretty --summary initial
256 diff-tree --pretty --stat --summary initial
257 diff-tree --pretty --root -p initial
258 diff-tree --pretty --root --stat initial
259 # improved by Timo's patch
260 diff-tree --pretty --root --summary initial
261 # improved by Timo's patch
262 diff-tree --pretty --root --summary -r initial
263 diff-tree --pretty --root --stat --summary initial
264 diff-tree --pretty --patch-with-stat initial
265 diff-tree --pretty --root --patch-with-stat initial
266 diff-tree --pretty --patch-with-raw initial
267 diff-tree --pretty --root --patch-with-raw initial
268
269 diff-tree --pretty=oneline initial
270 diff-tree --pretty=oneline --root initial
271 diff-tree --pretty=oneline -p initial
272 diff-tree --pretty=oneline --root -p initial
273 diff-tree --pretty=oneline --patch-with-stat initial
274 # improved by Timo's patch
275 diff-tree --pretty=oneline --root --patch-with-stat initial
276 diff-tree --pretty=oneline --patch-with-raw initial
277 diff-tree --pretty=oneline --root --patch-with-raw initial
278
279 diff-tree --pretty side
280 diff-tree --pretty -p side
281 diff-tree --pretty --patch-with-stat side
282
283 diff-tree initial mode
284 diff-tree --stat initial mode
285 diff-tree --summary initial mode
286
287 diff-tree master
288 diff-tree -p master
289 diff-tree -p -m master
290 diff-tree -c master
291 diff-tree -c --abbrev master
292 :noellipses diff-tree -c --abbrev master
293 diff-tree --cc master
294 # stat only should show the diffstat with the first parent
295 diff-tree -c --stat master
296 diff-tree --cc --stat master
297 diff-tree -c --stat --summary master
298 diff-tree --cc --stat --summary master
299 # stat summary should show the diffstat and summary with the first parent
300 diff-tree -c --stat --summary side
301 diff-tree --cc --stat --summary side
302 diff-tree --cc --shortstat master
303 diff-tree --cc --summary REVERSE
304 # improved by Timo's patch
305 diff-tree --cc --patch-with-stat master
306 # improved by Timo's patch
307 diff-tree --cc --patch-with-stat --summary master
308 # this is correct
309 diff-tree --cc --patch-with-stat --summary side
310
311 log master
312 log -p master
313 log --root master
314 log --root -p master
315 log --patch-with-stat master
316 log --root --patch-with-stat master
317 log --root --patch-with-stat --summary master
318 # improved by Timo's patch
319 log --root -c --patch-with-stat --summary master
320 # improved by Timo's patch
321 log --root --cc --patch-with-stat --summary master
322 log --no-diff-merges -p --first-parent master
323 log --diff-merges=off -p --first-parent master
324 log --first-parent --diff-merges=off -p master
325 log -p --first-parent master
326 log -m -p --first-parent master
327 log -m -p master
328 log -SF master
329 log -S F master
330 log -SF -p master
331 log -SF master --max-count=0
332 log -SF master --max-count=1
333 log -SF master --max-count=2
334 log -GF master
335 log -GF -p master
336 log -GF -p --pickaxe-all master
337 log -IA -IB -I1 -I2 -p master
338 log --decorate --all
339 log --decorate=full --all
340
341 rev-list --parents HEAD
342 rev-list --children HEAD
343
344 whatchanged master
345 :noellipses whatchanged master
346 whatchanged -p master
347 whatchanged --root master
348 :noellipses whatchanged --root master
349 whatchanged --root -p master
350 whatchanged --patch-with-stat master
351 whatchanged --root --patch-with-stat master
352 whatchanged --root --patch-with-stat --summary master
353 # improved by Timo's patch
354 whatchanged --root -c --patch-with-stat --summary master
355 # improved by Timo's patch
356 whatchanged --root --cc --patch-with-stat --summary master
357 whatchanged -SF master
358 :noellipses whatchanged -SF master
359 whatchanged -SF -p master
360
361 log --patch-with-stat master -- dir/
362 whatchanged --patch-with-stat master -- dir/
363 log --patch-with-stat --summary master -- dir/
364 whatchanged --patch-with-stat --summary master -- dir/
365
366 show initial
367 show --root initial
368 show side
369 show master
370 show -c master
371 show -m master
372 show --first-parent master
373 show --stat side
374 show --stat --summary side
375 show --patch-with-stat side
376 show --patch-with-raw side
377 :noellipses show --patch-with-raw side
378 show --patch-with-stat --summary side
379
380 format-patch --stdout initial..side
381 format-patch --stdout initial..master^
382 format-patch --stdout initial..master
383 format-patch --stdout --no-numbered initial..master
384 format-patch --stdout --numbered initial..master
385 format-patch --attach --stdout initial..side
386 format-patch --attach --stdout --suffix=.diff initial..side
387 format-patch --attach --stdout initial..master^
388 format-patch --attach --stdout initial..master
389 format-patch --inline --stdout initial..side
390 format-patch --inline --stdout initial..master^
391 format-patch --inline --stdout --numbered-files initial..master
392 format-patch --inline --stdout initial..master
393 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
394 config format.subjectprefix DIFFERENT_PREFIX
395 format-patch --inline --stdout initial..master^^
396 format-patch --stdout --cover-letter -n initial..master^
397
398 diff --abbrev initial..side
399 diff -U initial..side
400 diff -U1 initial..side
401 diff -r initial..side
402 diff --stat initial..side
403 diff -r --stat initial..side
404 diff initial..side
405 diff --patch-with-stat initial..side
406 diff --patch-with-raw initial..side
407 :noellipses diff --patch-with-raw initial..side
408 diff --patch-with-stat -r initial..side
409 diff --patch-with-raw -r initial..side
410 :noellipses diff --patch-with-raw -r initial..side
411 diff --name-status dir2 dir
412 diff --no-index --name-status dir2 dir
413 diff --no-index --name-status -- dir2 dir
414 diff --no-index dir dir3
415 diff master master^ side
416 # Can't use spaces...
417 diff --line-prefix=abc master master^ side
418 diff --dirstat master~1 master~2
419 diff --dirstat initial rearrange
420 diff --dirstat-by-file initial rearrange
421 diff --dirstat --cc master~1 master
422 # No-index --abbrev and --no-abbrev
423 diff --raw initial
424 :noellipses diff --raw initial
425 diff --raw --abbrev=4 initial
426 :noellipses diff --raw --abbrev=4 initial
427 diff --raw --no-abbrev initial
428 diff --no-index --raw dir2 dir
429 :noellipses diff --no-index --raw dir2 dir
430 diff --no-index --raw --abbrev=4 dir2 dir
431 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
432 diff --no-index --raw --no-abbrev dir2 dir
433
434 diff-tree --pretty --root --stat --compact-summary initial
435 diff-tree --pretty -R --root --stat --compact-summary initial
436 diff-tree --pretty note
437 diff-tree --pretty --notes note
438 diff-tree --format=%N note
439 diff-tree --stat --compact-summary initial mode
440 diff-tree -R --stat --compact-summary initial mode
441 EOF
442
443 test_expect_success 'log -S requires an argument' '
444 test_must_fail git log -S
445 '
446
447 test_expect_success 'diff --cached on unborn branch' '
448 echo ref: refs/heads/unborn >.git/HEAD &&
449 git diff --cached >result &&
450 process_diffs result >actual &&
451 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
452 test_cmp expected actual
453 '
454
455 test_expect_success 'diff --cached -- file on unborn branch' '
456 git diff --cached -- file0 >result &&
457 process_diffs result >actual &&
458 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
459 test_cmp expected actual
460 '
461 test_expect_success 'diff --line-prefix with spaces' '
462 git diff --line-prefix="| | | " --cached -- file0 >result &&
463 process_diffs result >actual &&
464 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
465 test_cmp expected actual
466 '
467
468 test_expect_success 'diff-tree --stdin with log formatting' '
469 cat >expect <<-\EOF &&
470 Side
471 Third
472 Second
473 EOF
474 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
475 test_cmp expect actual
476 '
477
478 test_expect_success 'diff -I<regex>: setup' '
479 git checkout master &&
480 test_seq 50 >file0 &&
481 git commit -m "Set up -I<regex> test file" file0 &&
482 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
483 echo >>file0
484 '
485 test_expect_success 'diff -I<regex>' '
486 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
487 cat >expect <<-\EOF &&
488 diff --git a/file0 b/file0
489 --- a/file0
490 +++ b/file0
491 @@ -34,7 +31,6 @@
492 34
493 35
494 36
495 -37
496 38
497 39
498 40
499 EOF
500 compare_diff_patch expect actual
501 '
502
503 test_expect_success 'diff -I<regex> --stat' '
504 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
505 cat >expect <<-\EOF &&
506 file0 | 1 -
507 1 file changed, 1 deletion(-)
508 EOF
509 test_cmp expect actual
510 '
511
512 test_expect_success 'diff -I<regex>: detect malformed regex' '
513 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
514 test_i18ngrep "invalid regex given to -I: " error
515 '
516
517 test_done