]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4013-diff-various.sh
Merge branch 'js/t5563-portability-fix'
[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
334afbc7
JS
8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
3c2f75b5 11. ./test-lib.sh
ebd73f50 12. "$TEST_DIRECTORY"/lib-diff.sh
3c2f75b5
JH
13
14test_expect_success setup '
15
16 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
17 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
18 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
19
20 mkdir dir &&
3cb56738 21 mkdir dir2 &&
08495412
ES
22 test_write_lines 1 2 3 >file0 &&
23 test_write_lines A B >dir/sub &&
3c2f75b5
JH
24 cat file0 >file2 &&
25 git add file0 file2 dir/sub &&
26 git commit -m Initial &&
27
28 git branch initial &&
29 git branch side &&
30
31 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
32 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
33 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
34
08495412
ES
35 test_write_lines 4 5 6 >>file0 &&
36 test_write_lines C D >>dir/sub &&
3c2f75b5
JH
37 rm -f file2 &&
38 git update-index --remove file0 file2 dir/sub &&
a40d384c 39 git commit -m "Second${LF}${LF}This is the second commit." &&
3c2f75b5
JH
40
41 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
42 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
43 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
44
08495412 45 test_write_lines A B C >file1 &&
3c2f75b5 46 git add file1 &&
08495412 47 test_write_lines E F >>dir/sub &&
3c2f75b5
JH
48 git update-index dir/sub &&
49 git commit -m Third &&
50
51 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
52 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
53 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
54
55 git checkout side &&
08495412
ES
56 test_write_lines A B C >>file0 &&
57 test_write_lines 1 2 >>dir/sub &&
3c2f75b5
JH
58 cat dir/sub >file3 &&
59 git add file3 &&
60 git update-index file0 dir/sub &&
61 git commit -m Side &&
62
63 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
64 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
65 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
66
67 git checkout master &&
031e2f7a 68 git pull -s ours --no-rebase . side &&
3c2f75b5
JH
69
70 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
71 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
72 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
73
08495412
ES
74 test_write_lines A B C >>file0 &&
75 test_write_lines 1 2 >>dir/sub &&
3c2f75b5
JH
76 git update-index file0 dir/sub &&
77
d61027b2
MS
78 mkdir dir3 &&
79 cp dir/sub dir3/sub &&
0e496492 80 test-tool chmtime +1 dir3/sub &&
d61027b2 81
e0d10e1c 82 git config log.showroot false &&
8ff99e74 83 git commit --amend &&
204f01a2
JH
84
85 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
86 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
87 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
88 git checkout -b rearrange initial &&
08495412 89 test_write_lines B A >dir/sub &&
204f01a2
JH
90 git add dir/sub &&
91 git commit -m "Rearranged lines in dir/sub" &&
92 git checkout master &&
93
58aaced4
SB
94 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
95 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
96 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
97 git checkout -b mode initial &&
98 git update-index --chmod=+x file0 &&
99 git commit -m "update mode" &&
100 git checkout -f master &&
101
5778b22b
TB
102 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
103 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
104 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
105 git checkout -b note initial &&
106 git update-index --chmod=+x file2 &&
107 git commit -m "update mode (file2)" &&
108 git notes add -m "note" &&
109 git checkout -f master &&
110
04b19fca
JK
111 # Same merge as master, but with parents reversed. Hide it in a
112 # pseudo-ref to avoid impacting tests with --all.
113 commit=$(echo reverse |
114 git commit-tree -p master^2 -p master^1 master^{tree}) &&
115 git update-ref REVERSE $commit &&
116
5404c116
MM
117 git config diff.renames false &&
118
3c2f75b5
JH
119 git show-branch
120'
121
122: <<\EOF
123! [initial] Initial
21531927 124 * [master] Merge branch 'side'
204f01a2
JH
125 ! [rearrange] Rearranged lines in dir/sub
126 ! [side] Side
127----
128 + [rearrange] Rearranged lines in dir/sub
21531927 129 - [master] Merge branch 'side'
204f01a2
JH
130 * + [side] Side
131 * [master^] Third
132 * [master~2] Second
133+*++ [initial] Initial
3c2f75b5
JH
134EOF
135
72f936b1 136process_diffs () {
fc7e73d7 137 perl -e '
138 my $oid_length = length($ARGV[0]);
139 my $x40 = "[0-9a-f]{40}";
140 my $xab = "[0-9a-f]{4,16}";
141 my $orx = "[0-9a-f]" x $oid_length;
142
143 sub munge_oid {
144 my ($oid) = @_;
145 my $x;
146
147 return "" unless length $oid;
148
149 if ($oid =~ /^(100644|100755|120000)$/) {
150 return $oid;
151 }
152
153 if ($oid =~ /^0*$/) {
154 $x = "0";
155 } else {
156 $x = "f";
157 }
158
159 if (length($oid) == 40) {
160 return $x x $oid_length;
161 } else {
162 return $x x length($oid);
163 }
164 }
165
166 while (<STDIN>) {
167 s/($orx)/munge_oid($1)/ge;
168 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
169 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
170 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
171 s/^($x40)($| )/munge_oid($1) . $2/e;
172 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
173 print;
174 }
175 ' "$ZERO_OID" <"$1"
72f936b1 176}
177
4ff03347 178V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
b4c02c30 179while read magic cmd
3c2f75b5 180do
14c14b44 181 status=success
b4c02c30
AR
182 case "$magic" in
183 '' | '#'*)
184 continue ;;
185 :*)
186 magic=${magic#:}
187 label="$magic-$cmd"
188 case "$magic" in
189 noellipses) ;;
14c14b44
SO
190 failure)
191 status=failure
192 magic=
193 label="$cmd" ;;
b4c02c30 194 *)
165293af 195 BUG "unknown magic $magic" ;;
b4c02c30
AR
196 esac ;;
197 *)
198 cmd="$magic $cmd" magic=
199 label="$cmd" ;;
3c2f75b5 200 esac
b4c02c30 201 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
4ff03347 202 pfx=$(printf "%04d" $test_count)
bfdbee98 203 expect="$TEST_DIRECTORY/t4013/diff.$test"
3c2f75b5
JH
204 actual="$pfx-diff.$test"
205
14c14b44 206 test_expect_$status "git $cmd # magic is ${magic:-(not used)}" '
3c2f75b5 207 {
b4c02c30
AR
208 echo "$ git $cmd"
209 case "$magic" in
210 "")
211 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
212 noellipses)
213 git $cmd ;;
214 esac |
6c7f4ceb 215 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
33ee4cfb 216 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
3c2f75b5
JH
217 echo "\$"
218 } >"$actual" &&
219 if test -f "$expect"
220 then
72f936b1 221 process_diffs "$actual" >actual &&
222 process_diffs "$expect" >expect &&
6dd88832
JN
223 case $cmd in
224 *format-patch* | *-stat*)
1108cea7 225 test_cmp expect actual;;
6dd88832 226 *)
72f936b1 227 test_cmp expect actual;;
6dd88832 228 esac &&
72f936b1 229 rm -f "$actual" actual expect
3c2f75b5
JH
230 else
231 # this is to help developing new tests.
232 cp "$actual" "$expect"
233 false
234 fi
235 '
236done <<\EOF
237diff-tree initial
238diff-tree -r initial
239diff-tree -r --abbrev initial
240diff-tree -r --abbrev=4 initial
241diff-tree --root initial
242diff-tree --root --abbrev initial
c2f1d398 243:noellipses diff-tree --root --abbrev initial
3c2f75b5
JH
244diff-tree --root -r initial
245diff-tree --root -r --abbrev initial
c2f1d398 246:noellipses diff-tree --root -r --abbrev initial
3c2f75b5 247diff-tree --root -r --abbrev=4 initial
c2f1d398 248:noellipses diff-tree --root -r --abbrev=4 initial
3c2f75b5
JH
249diff-tree -p initial
250diff-tree --root -p initial
3046c7f6
ĐTCD
251diff-tree --root -p --abbrev=10 initial
252diff-tree --root -p --full-index initial
253diff-tree --root -p --full-index --abbrev=10 initial
3c2f75b5
JH
254diff-tree --patch-with-stat initial
255diff-tree --root --patch-with-stat initial
256diff-tree --patch-with-raw initial
257diff-tree --root --patch-with-raw initial
258
259diff-tree --pretty initial
260diff-tree --pretty --root initial
261diff-tree --pretty -p initial
262diff-tree --pretty --stat initial
263diff-tree --pretty --summary initial
264diff-tree --pretty --stat --summary initial
265diff-tree --pretty --root -p initial
266diff-tree --pretty --root --stat initial
026625e7
JH
267# improved by Timo's patch
268diff-tree --pretty --root --summary initial
269# improved by Timo's patch
270diff-tree --pretty --root --summary -r initial
3c2f75b5
JH
271diff-tree --pretty --root --stat --summary initial
272diff-tree --pretty --patch-with-stat initial
273diff-tree --pretty --root --patch-with-stat initial
274diff-tree --pretty --patch-with-raw initial
275diff-tree --pretty --root --patch-with-raw initial
276
277diff-tree --pretty=oneline initial
278diff-tree --pretty=oneline --root initial
279diff-tree --pretty=oneline -p initial
280diff-tree --pretty=oneline --root -p initial
281diff-tree --pretty=oneline --patch-with-stat initial
026625e7 282# improved by Timo's patch
3c2f75b5
JH
283diff-tree --pretty=oneline --root --patch-with-stat initial
284diff-tree --pretty=oneline --patch-with-raw initial
285diff-tree --pretty=oneline --root --patch-with-raw initial
286
287diff-tree --pretty side
288diff-tree --pretty -p side
289diff-tree --pretty --patch-with-stat side
290
58aaced4
SB
291diff-tree initial mode
292diff-tree --stat initial mode
293diff-tree --summary initial mode
294
3c2f75b5 295diff-tree master
3ae7fe2b 296diff-tree -m master
3c2f75b5
JH
297diff-tree -p master
298diff-tree -p -m master
299diff-tree -c master
300diff-tree -c --abbrev master
c2f1d398 301:noellipses diff-tree -c --abbrev master
3c2f75b5 302diff-tree --cc master
47979d5d
JH
303# stat only should show the diffstat with the first parent
304diff-tree -c --stat master
305diff-tree --cc --stat master
306diff-tree -c --stat --summary master
307diff-tree --cc --stat --summary master
308# stat summary should show the diffstat and summary with the first parent
309diff-tree -c --stat --summary side
310diff-tree --cc --stat --summary side
8290faa0 311diff-tree --cc --shortstat master
04b19fca 312diff-tree --cc --summary REVERSE
026625e7
JH
313# improved by Timo's patch
314diff-tree --cc --patch-with-stat master
315# improved by Timo's patch
47979d5d
JH
316diff-tree --cc --patch-with-stat --summary master
317# this is correct
318diff-tree --cc --patch-with-stat --summary side
3c2f75b5
JH
319
320log master
321log -p master
322log --root master
323log --root -p master
324log --patch-with-stat master
325log --root --patch-with-stat master
47979d5d 326log --root --patch-with-stat --summary master
026625e7 327# improved by Timo's patch
47979d5d 328log --root -c --patch-with-stat --summary master
026625e7 329# improved by Timo's patch
47979d5d 330log --root --cc --patch-with-stat --summary master
6fae74b4 331log --no-diff-merges -p --first-parent master
298889d3
SO
332log --diff-merges=off -p --first-parent master
333log --first-parent --diff-merges=off -p master
126f431a 334log -p --first-parent master
af04d8f1
SO
335log -p --diff-merges=first-parent master
336log --diff-merges=first-parent master
126f431a
JH
337log -m -p --first-parent master
338log -m -p master
6fc944d8
SO
339log --cc -m -p master
340log -c -m -p master
48229c19 341log -m --raw master
faf16d4e 342log -m --stat master
3c2f75b5 343log -SF master
dea007fb 344log -S F master
47979d5d 345log -SF -p master
251df09b
MM
346log -SF master --max-count=0
347log -SF master --max-count=1
348log -SF master --max-count=2
bf1dfc31
JH
349log -GF master
350log -GF -p master
351log -GF -p --pickaxe-all master
296d4a94 352log -IA -IB -I1 -I2 -p master
28fd76bd 353log --decorate --all
33e7018c 354log --decorate=full --all
748706d7
DS
355log --decorate --clear-decorations --all
356log --decorate=full --clear-decorations --all
3c2f75b5 357
fcbc6efc
TR
358rev-list --parents HEAD
359rev-list --children HEAD
3c2f75b5
JH
360
361whatchanged master
c2f1d398 362:noellipses whatchanged master
3c2f75b5
JH
363whatchanged -p master
364whatchanged --root master
c2f1d398 365:noellipses whatchanged --root master
3c2f75b5
JH
366whatchanged --root -p master
367whatchanged --patch-with-stat master
368whatchanged --root --patch-with-stat master
369whatchanged --root --patch-with-stat --summary master
026625e7 370# improved by Timo's patch
47979d5d 371whatchanged --root -c --patch-with-stat --summary master
026625e7 372# improved by Timo's patch
47979d5d 373whatchanged --root --cc --patch-with-stat --summary master
3c2f75b5 374whatchanged -SF master
c2f1d398 375:noellipses whatchanged -SF master
47979d5d 376whatchanged -SF -p master
3c2f75b5
JH
377
378log --patch-with-stat master -- dir/
379whatchanged --patch-with-stat master -- dir/
47979d5d
JH
380log --patch-with-stat --summary master -- dir/
381whatchanged --patch-with-stat --summary master -- dir/
3c2f75b5
JH
382
383show initial
384show --root initial
385show side
386show master
b4490059 387show -c master
2bf65873
JH
388show -m master
389show --first-parent master
3c2f75b5
JH
390show --stat side
391show --stat --summary side
392show --patch-with-stat side
393show --patch-with-raw side
c2f1d398 394:noellipses show --patch-with-raw side
3c2f75b5
JH
395show --patch-with-stat --summary side
396
d410e43b
JH
397format-patch --stdout initial..side
398format-patch --stdout initial..master^
399format-patch --stdout initial..master
a567fdcb
BG
400format-patch --stdout --no-numbered initial..master
401format-patch --stdout --numbered initial..master
d410e43b 402format-patch --attach --stdout initial..side
108dab28 403format-patch --attach --stdout --suffix=.diff initial..side
d410e43b
JH
404format-patch --attach --stdout initial..master^
405format-patch --attach --stdout initial..master
c112f689
JS
406format-patch --inline --stdout initial..side
407format-patch --inline --stdout initial..master^
747e2505 408format-patch --inline --stdout --numbered-files initial..master
a567fdcb 409format-patch --inline --stdout initial..master
171ddd91 410format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
dbd21447
AR
411config format.subjectprefix DIFFERENT_PREFIX
412format-patch --inline --stdout initial..master^^
a5a27c79 413format-patch --stdout --cover-letter -n initial..master^
d410e43b 414
b319b02e 415diff --abbrev initial..side
8ef05193
NTND
416diff -U initial..side
417diff -U1 initial..side
b319b02e
JH
418diff -r initial..side
419diff --stat initial..side
420diff -r --stat initial..side
421diff initial..side
422diff --patch-with-stat initial..side
423diff --patch-with-raw initial..side
c2f1d398 424:noellipses diff --patch-with-raw initial..side
b319b02e
JH
425diff --patch-with-stat -r initial..side
426diff --patch-with-raw -r initial..side
c2f1d398 427:noellipses diff --patch-with-raw -r initial..side
3cb56738 428diff --name-status dir2 dir
0569e9b8 429diff --no-index --name-status dir2 dir
e423ffd8 430diff --no-index --name-status -- dir2 dir
d61027b2 431diff --no-index dir dir3
b75271d9 432diff master master^ side
660e113c
JK
433# Can't use spaces...
434diff --line-prefix=abc master master^ side
f37bfb7a 435diff --dirstat master~1 master~2
204f01a2 436diff --dirstat initial rearrange
0133dab7 437diff --dirstat-by-file initial rearrange
dac03b55 438diff --dirstat --cc master~1 master
43d1948b
JB
439# No-index --abbrev and --no-abbrev
440diff --raw initial
c2f1d398 441:noellipses diff --raw initial
43d1948b 442diff --raw --abbrev=4 initial
c2f1d398 443:noellipses diff --raw --abbrev=4 initial
43d1948b
JB
444diff --raw --no-abbrev initial
445diff --no-index --raw dir2 dir
c2f1d398 446:noellipses diff --no-index --raw dir2 dir
43d1948b 447diff --no-index --raw --abbrev=4 dir2 dir
c2f1d398 448:noellipses diff --no-index --raw --abbrev=4 dir2 dir
43d1948b 449diff --no-index --raw --no-abbrev dir2 dir
ddf88fa6
NTND
450
451diff-tree --pretty --root --stat --compact-summary initial
452diff-tree --pretty -R --root --stat --compact-summary initial
5778b22b
TB
453diff-tree --pretty note
454diff-tree --pretty --notes note
455diff-tree --format=%N note
ddf88fa6
NTND
456diff-tree --stat --compact-summary initial mode
457diff-tree -R --stat --compact-summary initial mode
3c2f75b5
JH
458EOF
459
6a38e333
JN
460test_expect_success 'log -m matches pure log' '
461 git log master >result &&
7a55fa0e
SO
462 process_diffs result >expected &&
463 git log -m >result &&
464 process_diffs result >actual &&
465 test_cmp expected actual
466'
467
4320815e
SO
468test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
469 git log -p --diff-merges=separate master >result &&
470 process_diffs result >expected &&
471 git log -p --diff-merges=on master >result &&
472 process_diffs result >actual &&
17c13e60
SO
473 test_cmp expected actual
474'
475
476test_expect_success 'deny wrong log.diffMerges config' '
477 test_config log.diffMerges wrong-value &&
478 test_expect_code 128 git log
479'
480
481test_expect_success 'git config log.diffMerges first-parent' '
482 git log -p --diff-merges=first-parent master >result &&
483 process_diffs result >expected &&
484 test_config log.diffMerges first-parent &&
485 git log -p --diff-merges=on master >result &&
486 process_diffs result >actual &&
487 test_cmp expected actual
488'
489
490test_expect_success 'git config log.diffMerges first-parent vs -m' '
491 git log -p --diff-merges=first-parent master >result &&
492 process_diffs result >expected &&
493 test_config log.diffMerges first-parent &&
494 git log -p -m master >result &&
495 process_diffs result >actual &&
4320815e
SO
496 test_cmp expected actual
497'
498
e0b16421
SO
499# -m in "git diff-index" means "match missing", that differs
500# from its meaning in "git diff". Let's check it in diff-index.
501# The line in the output for removed file should disappear when
502# we provide -m in diff-index.
503test_expect_success 'git diff-index -m' '
504 rm -f file1 &&
505 git diff-index HEAD >without-m &&
506 lines_count=$(wc -l <without-m) &&
507 git diff-index -m HEAD >with-m &&
508 git restore file1 &&
509 test_line_count = $((lines_count - 1)) with-m
510'
511
dea007fb
MM
512test_expect_success 'log -S requires an argument' '
513 test_must_fail git log -S
514'
515
a2b7a3b3
NTND
516test_expect_success 'diff --cached on unborn branch' '
517 echo ref: refs/heads/unborn >.git/HEAD &&
518 git diff --cached >result &&
72f936b1 519 process_diffs result >actual &&
520 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
521 test_cmp expected actual
a2b7a3b3
NTND
522'
523
524test_expect_success 'diff --cached -- file on unborn branch' '
525 git diff --cached -- file0 >result &&
72f936b1 526 process_diffs result >actual &&
527 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
528 test_cmp expected actual
a2b7a3b3 529'
660e113c
JK
530test_expect_success 'diff --line-prefix with spaces' '
531 git diff --line-prefix="| | | " --cached -- file0 >result &&
72f936b1 532 process_diffs result >actual &&
533 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
534 test_cmp expected actual
660e113c 535'
a2b7a3b3 536
d299e9e5
JK
537test_expect_success 'diff-tree --stdin with log formatting' '
538 cat >expect <<-\EOF &&
539 Side
540 Third
541 Second
542 EOF
543 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
544 test_cmp expect actual
545'
546
f8781bfd
JH
547test_expect_success 'diff-tree --stdin with pathspec' '
548 cat >expect <<-EOF &&
549 Third
550
551 dir/sub
552 Second
553
554 dir/sub
555 EOF
556 git rev-list master^ |
557 git diff-tree -r --stdin --name-only --format=%s dir >actual &&
558 test_cmp expect actual
559'
560
5cdb3845
JH
561test_expect_success 'show A B ... -- <pathspec>' '
562 # side touches dir/sub, file0, and file3
563 # master^ touches dir/sub, and file1
564 # master^^ touches dir/sub, file0, and file2
565 git show --name-only --format="<%s>" side master^ master^^ -- dir >actual &&
566 cat >expect <<-\EOF &&
567 <Side>
568
569 dir/sub
570 <Third>
571
572 dir/sub
573 <Second>
574
575 dir/sub
576 EOF
577 test_cmp expect actual
578'
579
296d4a94
MK
580test_expect_success 'diff -I<regex>: setup' '
581 git checkout master &&
582 test_seq 50 >file0 &&
583 git commit -m "Set up -I<regex> test file" file0 &&
584 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
585 echo >>file0
586'
587test_expect_success 'diff -I<regex>' '
588 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
589 cat >expect <<-\EOF &&
590 diff --git a/file0 b/file0
591 --- a/file0
592 +++ b/file0
593 @@ -34,7 +31,6 @@
594 34
595 35
596 36
597 -37
598 38
599 39
600 40
601 EOF
602 compare_diff_patch expect actual
603'
604
605test_expect_success 'diff -I<regex> --stat' '
606 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
607 cat >expect <<-\EOF &&
608 file0 | 1 -
609 1 file changed, 1 deletion(-)
610 EOF
611 test_cmp expect actual
612'
613
614test_expect_success 'diff -I<regex>: detect malformed regex' '
615 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
616 test_i18ngrep "invalid regex given to -I: " error
617'
618
7c03d0db
JK
619# check_prefix <patch> <src> <dst>
620# check only lines with paths to avoid dependency on exact oid/contents
621check_prefix () {
622 grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths &&
623 cat >expect <<-EOF &&
624 diff --git $2 $3
625 --- $2
626 +++ $3
627 EOF
628 test_cmp expect actual.paths
629}
630
631test_expect_success 'diff-files does not respect diff.noprefix' '
632 git -c diff.noprefix diff-files -p >actual &&
633 check_prefix actual a/file0 b/file0
634'
635
636test_expect_success 'diff-files respects --no-prefix' '
637 git diff-files -p --no-prefix >actual &&
638 check_prefix actual file0 file0
639'
640
641test_expect_success 'diff respects diff.noprefix' '
642 git -c diff.noprefix diff >actual &&
643 check_prefix actual file0 file0
644'
645
b39a5697
JK
646test_expect_success 'diff --default-prefix overrides diff.noprefix' '
647 git -c diff.noprefix diff --default-prefix >actual &&
648 check_prefix actual a/file0 b/file0
649'
650
7c03d0db
JK
651test_expect_success 'diff respects diff.mnemonicprefix' '
652 git -c diff.mnemonicprefix diff >actual &&
653 check_prefix actual i/file0 w/file0
654'
655
b39a5697
JK
656test_expect_success 'diff --default-prefix overrides diff.mnemonicprefix' '
657 git -c diff.mnemonicprefix diff --default-prefix >actual &&
658 check_prefix actual a/file0 b/file0
659'
660
3c2f75b5 661test_done