]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4013-diff-various.sh
Merge branch 'dl/checkout-p-merge-base'
[thirdparty/git.git] / t / t4013-diff-various.sh
CommitLineData
3c2f75b5
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Various diff formatting options'
7
8. ./test-lib.sh
296d4a94 9. "$TEST_DIRECTORY"/diff-lib.sh
3c2f75b5
JH
10
11test_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 &&
3cb56738 18 mkdir dir2 &&
3c2f75b5
JH
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 &&
a40d384c 36 git commit -m "Second${LF}${LF}This is the second commit." &&
3c2f75b5
JH
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
d61027b2
MS
75 mkdir dir3 &&
76 cp dir/sub dir3/sub &&
0e496492 77 test-tool chmtime +1 dir3/sub &&
d61027b2 78
e0d10e1c 79 git config log.showroot false &&
8ff99e74 80 git commit --amend &&
204f01a2
JH
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
58aaced4
SB
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
5778b22b
TB
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
04b19fca
JK
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
5404c116
MM
114 git config diff.renames false &&
115
3c2f75b5
JH
116 git show-branch
117'
118
119: <<\EOF
120! [initial] Initial
21531927 121 * [master] Merge branch 'side'
204f01a2
JH
122 ! [rearrange] Rearranged lines in dir/sub
123 ! [side] Side
124----
125 + [rearrange] Rearranged lines in dir/sub
21531927 126 - [master] Merge branch 'side'
204f01a2
JH
127 * + [side] Side
128 * [master^] Third
129 * [master~2] Second
130+*++ [initial] Initial
3c2f75b5
JH
131EOF
132
72f936b1 133process_diffs () {
fc7e73d7 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"
72f936b1 173}
174
4ff03347 175V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
b4c02c30 176while read magic cmd
3c2f75b5 177do
b4c02c30
AR
178 case "$magic" in
179 '' | '#'*)
180 continue ;;
181 :*)
182 magic=${magic#:}
183 label="$magic-$cmd"
184 case "$magic" in
185 noellipses) ;;
186 *)
165293af 187 BUG "unknown magic $magic" ;;
b4c02c30
AR
188 esac ;;
189 *)
190 cmd="$magic $cmd" magic=
191 label="$cmd" ;;
3c2f75b5 192 esac
b4c02c30 193 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
4ff03347 194 pfx=$(printf "%04d" $test_count)
bfdbee98 195 expect="$TEST_DIRECTORY/t4013/diff.$test"
3c2f75b5
JH
196 actual="$pfx-diff.$test"
197
de231e57 198 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
3c2f75b5 199 {
b4c02c30
AR
200 echo "$ git $cmd"
201 case "$magic" in
202 "")
203 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
204 noellipses)
205 git $cmd ;;
206 esac |
6c7f4ceb 207 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
33ee4cfb 208 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
3c2f75b5
JH
209 echo "\$"
210 } >"$actual" &&
211 if test -f "$expect"
212 then
72f936b1 213 process_diffs "$actual" >actual &&
214 process_diffs "$expect" >expect &&
6dd88832
JN
215 case $cmd in
216 *format-patch* | *-stat*)
72f936b1 217 test_i18ncmp expect actual;;
6dd88832 218 *)
72f936b1 219 test_cmp expect actual;;
6dd88832 220 esac &&
72f936b1 221 rm -f "$actual" actual expect
3c2f75b5
JH
222 else
223 # this is to help developing new tests.
224 cp "$actual" "$expect"
225 false
226 fi
227 '
228done <<\EOF
229diff-tree initial
230diff-tree -r initial
231diff-tree -r --abbrev initial
232diff-tree -r --abbrev=4 initial
233diff-tree --root initial
234diff-tree --root --abbrev initial
c2f1d398 235:noellipses diff-tree --root --abbrev initial
3c2f75b5
JH
236diff-tree --root -r initial
237diff-tree --root -r --abbrev initial
c2f1d398 238:noellipses diff-tree --root -r --abbrev initial
3c2f75b5 239diff-tree --root -r --abbrev=4 initial
c2f1d398 240:noellipses diff-tree --root -r --abbrev=4 initial
3c2f75b5
JH
241diff-tree -p initial
242diff-tree --root -p initial
3046c7f6
ĐTCD
243diff-tree --root -p --abbrev=10 initial
244diff-tree --root -p --full-index initial
245diff-tree --root -p --full-index --abbrev=10 initial
3c2f75b5
JH
246diff-tree --patch-with-stat initial
247diff-tree --root --patch-with-stat initial
248diff-tree --patch-with-raw initial
249diff-tree --root --patch-with-raw initial
250
251diff-tree --pretty initial
252diff-tree --pretty --root initial
253diff-tree --pretty -p initial
254diff-tree --pretty --stat initial
255diff-tree --pretty --summary initial
256diff-tree --pretty --stat --summary initial
257diff-tree --pretty --root -p initial
258diff-tree --pretty --root --stat initial
026625e7
JH
259# improved by Timo's patch
260diff-tree --pretty --root --summary initial
261# improved by Timo's patch
262diff-tree --pretty --root --summary -r initial
3c2f75b5
JH
263diff-tree --pretty --root --stat --summary initial
264diff-tree --pretty --patch-with-stat initial
265diff-tree --pretty --root --patch-with-stat initial
266diff-tree --pretty --patch-with-raw initial
267diff-tree --pretty --root --patch-with-raw initial
268
269diff-tree --pretty=oneline initial
270diff-tree --pretty=oneline --root initial
271diff-tree --pretty=oneline -p initial
272diff-tree --pretty=oneline --root -p initial
273diff-tree --pretty=oneline --patch-with-stat initial
026625e7 274# improved by Timo's patch
3c2f75b5
JH
275diff-tree --pretty=oneline --root --patch-with-stat initial
276diff-tree --pretty=oneline --patch-with-raw initial
277diff-tree --pretty=oneline --root --patch-with-raw initial
278
279diff-tree --pretty side
280diff-tree --pretty -p side
281diff-tree --pretty --patch-with-stat side
282
58aaced4
SB
283diff-tree initial mode
284diff-tree --stat initial mode
285diff-tree --summary initial mode
286
3c2f75b5
JH
287diff-tree master
288diff-tree -p master
289diff-tree -p -m master
290diff-tree -c master
291diff-tree -c --abbrev master
c2f1d398 292:noellipses diff-tree -c --abbrev master
3c2f75b5 293diff-tree --cc master
47979d5d
JH
294# stat only should show the diffstat with the first parent
295diff-tree -c --stat master
296diff-tree --cc --stat master
297diff-tree -c --stat --summary master
298diff-tree --cc --stat --summary master
299# stat summary should show the diffstat and summary with the first parent
300diff-tree -c --stat --summary side
301diff-tree --cc --stat --summary side
8290faa0 302diff-tree --cc --shortstat master
04b19fca 303diff-tree --cc --summary REVERSE
026625e7
JH
304# improved by Timo's patch
305diff-tree --cc --patch-with-stat master
306# improved by Timo's patch
47979d5d
JH
307diff-tree --cc --patch-with-stat --summary master
308# this is correct
309diff-tree --cc --patch-with-stat --summary side
3c2f75b5
JH
310
311log master
312log -p master
313log --root master
314log --root -p master
315log --patch-with-stat master
316log --root --patch-with-stat master
47979d5d 317log --root --patch-with-stat --summary master
026625e7 318# improved by Timo's patch
47979d5d 319log --root -c --patch-with-stat --summary master
026625e7 320# improved by Timo's patch
47979d5d 321log --root --cc --patch-with-stat --summary master
6fae74b4 322log --no-diff-merges -p --first-parent master
298889d3
SO
323log --diff-merges=off -p --first-parent master
324log --first-parent --diff-merges=off -p master
126f431a
JH
325log -p --first-parent master
326log -m -p --first-parent master
327log -m -p master
3c2f75b5 328log -SF master
dea007fb 329log -S F master
47979d5d 330log -SF -p master
251df09b
MM
331log -SF master --max-count=0
332log -SF master --max-count=1
333log -SF master --max-count=2
bf1dfc31
JH
334log -GF master
335log -GF -p master
336log -GF -p --pickaxe-all master
296d4a94 337log -IA -IB -I1 -I2 -p master
28fd76bd 338log --decorate --all
33e7018c 339log --decorate=full --all
3c2f75b5 340
fcbc6efc
TR
341rev-list --parents HEAD
342rev-list --children HEAD
3c2f75b5
JH
343
344whatchanged master
c2f1d398 345:noellipses whatchanged master
3c2f75b5
JH
346whatchanged -p master
347whatchanged --root master
c2f1d398 348:noellipses whatchanged --root master
3c2f75b5
JH
349whatchanged --root -p master
350whatchanged --patch-with-stat master
351whatchanged --root --patch-with-stat master
352whatchanged --root --patch-with-stat --summary master
026625e7 353# improved by Timo's patch
47979d5d 354whatchanged --root -c --patch-with-stat --summary master
026625e7 355# improved by Timo's patch
47979d5d 356whatchanged --root --cc --patch-with-stat --summary master
3c2f75b5 357whatchanged -SF master
c2f1d398 358:noellipses whatchanged -SF master
47979d5d 359whatchanged -SF -p master
3c2f75b5
JH
360
361log --patch-with-stat master -- dir/
362whatchanged --patch-with-stat master -- dir/
47979d5d
JH
363log --patch-with-stat --summary master -- dir/
364whatchanged --patch-with-stat --summary master -- dir/
3c2f75b5
JH
365
366show initial
367show --root initial
368show side
369show master
b4490059 370show -c master
2bf65873
JH
371show -m master
372show --first-parent master
3c2f75b5
JH
373show --stat side
374show --stat --summary side
375show --patch-with-stat side
376show --patch-with-raw side
c2f1d398 377:noellipses show --patch-with-raw side
3c2f75b5
JH
378show --patch-with-stat --summary side
379
d410e43b
JH
380format-patch --stdout initial..side
381format-patch --stdout initial..master^
382format-patch --stdout initial..master
a567fdcb
BG
383format-patch --stdout --no-numbered initial..master
384format-patch --stdout --numbered initial..master
d410e43b 385format-patch --attach --stdout initial..side
108dab28 386format-patch --attach --stdout --suffix=.diff initial..side
d410e43b
JH
387format-patch --attach --stdout initial..master^
388format-patch --attach --stdout initial..master
c112f689
JS
389format-patch --inline --stdout initial..side
390format-patch --inline --stdout initial..master^
747e2505 391format-patch --inline --stdout --numbered-files initial..master
a567fdcb 392format-patch --inline --stdout initial..master
171ddd91 393format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
dbd21447
AR
394config format.subjectprefix DIFFERENT_PREFIX
395format-patch --inline --stdout initial..master^^
a5a27c79 396format-patch --stdout --cover-letter -n initial..master^
d410e43b 397
b319b02e 398diff --abbrev initial..side
8ef05193
NTND
399diff -U initial..side
400diff -U1 initial..side
b319b02e
JH
401diff -r initial..side
402diff --stat initial..side
403diff -r --stat initial..side
404diff initial..side
405diff --patch-with-stat initial..side
406diff --patch-with-raw initial..side
c2f1d398 407:noellipses diff --patch-with-raw initial..side
b319b02e
JH
408diff --patch-with-stat -r initial..side
409diff --patch-with-raw -r initial..side
c2f1d398 410:noellipses diff --patch-with-raw -r initial..side
3cb56738 411diff --name-status dir2 dir
0569e9b8 412diff --no-index --name-status dir2 dir
e423ffd8 413diff --no-index --name-status -- dir2 dir
d61027b2 414diff --no-index dir dir3
b75271d9 415diff master master^ side
660e113c
JK
416# Can't use spaces...
417diff --line-prefix=abc master master^ side
f37bfb7a 418diff --dirstat master~1 master~2
204f01a2 419diff --dirstat initial rearrange
0133dab7 420diff --dirstat-by-file initial rearrange
dac03b55 421diff --dirstat --cc master~1 master
43d1948b
JB
422# No-index --abbrev and --no-abbrev
423diff --raw initial
c2f1d398 424:noellipses diff --raw initial
43d1948b 425diff --raw --abbrev=4 initial
c2f1d398 426:noellipses diff --raw --abbrev=4 initial
43d1948b
JB
427diff --raw --no-abbrev initial
428diff --no-index --raw dir2 dir
c2f1d398 429:noellipses diff --no-index --raw dir2 dir
43d1948b 430diff --no-index --raw --abbrev=4 dir2 dir
c2f1d398 431:noellipses diff --no-index --raw --abbrev=4 dir2 dir
43d1948b 432diff --no-index --raw --no-abbrev dir2 dir
ddf88fa6
NTND
433
434diff-tree --pretty --root --stat --compact-summary initial
435diff-tree --pretty -R --root --stat --compact-summary initial
5778b22b
TB
436diff-tree --pretty note
437diff-tree --pretty --notes note
438diff-tree --format=%N note
ddf88fa6
NTND
439diff-tree --stat --compact-summary initial mode
440diff-tree -R --stat --compact-summary initial mode
3c2f75b5
JH
441EOF
442
dea007fb
MM
443test_expect_success 'log -S requires an argument' '
444 test_must_fail git log -S
445'
446
a2b7a3b3
NTND
447test_expect_success 'diff --cached on unborn branch' '
448 echo ref: refs/heads/unborn >.git/HEAD &&
449 git diff --cached >result &&
72f936b1 450 process_diffs result >actual &&
451 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
452 test_cmp expected actual
a2b7a3b3
NTND
453'
454
455test_expect_success 'diff --cached -- file on unborn branch' '
456 git diff --cached -- file0 >result &&
72f936b1 457 process_diffs result >actual &&
458 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
459 test_cmp expected actual
a2b7a3b3 460'
660e113c
JK
461test_expect_success 'diff --line-prefix with spaces' '
462 git diff --line-prefix="| | | " --cached -- file0 >result &&
72f936b1 463 process_diffs result >actual &&
464 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
465 test_cmp expected actual
660e113c 466'
a2b7a3b3 467
d299e9e5
JK
468test_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
296d4a94
MK
478test_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'
485test_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
503test_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
512test_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
3c2f75b5 517test_done