]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4013-diff-various.sh
The third batch
[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
b4c02c30
AR
181 case "$magic" in
182 '' | '#'*)
183 continue ;;
46262691
PS
184 :noellipses)
185 magic=noellipses
b4c02c30 186 label="$magic-$cmd"
46262691
PS
187 ;;
188 :*)
189 BUG "unknown magic $magic"
190 ;;
b4c02c30 191 *)
46262691
PS
192 cmd="$magic $cmd"
193 magic=
194 label="$cmd"
195 ;;
3c2f75b5 196 esac
46262691 197
b4c02c30 198 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
4ff03347 199 pfx=$(printf "%04d" $test_count)
bfdbee98 200 expect="$TEST_DIRECTORY/t4013/diff.$test"
3c2f75b5
JH
201 actual="$pfx-diff.$test"
202
46262691 203 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
3c2f75b5 204 {
b4c02c30
AR
205 echo "$ git $cmd"
206 case "$magic" in
207 "")
208 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
209 noellipses)
210 git $cmd ;;
211 esac |
6c7f4ceb 212 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
33ee4cfb 213 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
3c2f75b5
JH
214 echo "\$"
215 } >"$actual" &&
216 if test -f "$expect"
217 then
72f936b1 218 process_diffs "$actual" >actual &&
219 process_diffs "$expect" >expect &&
6dd88832
JN
220 case $cmd in
221 *format-patch* | *-stat*)
1108cea7 222 test_cmp expect actual;;
6dd88832 223 *)
72f936b1 224 test_cmp expect actual;;
6dd88832 225 esac &&
72f936b1 226 rm -f "$actual" actual expect
3c2f75b5
JH
227 else
228 # this is to help developing new tests.
229 cp "$actual" "$expect"
230 false
231 fi
232 '
233done <<\EOF
234diff-tree initial
235diff-tree -r initial
236diff-tree -r --abbrev initial
237diff-tree -r --abbrev=4 initial
238diff-tree --root initial
239diff-tree --root --abbrev initial
c2f1d398 240:noellipses diff-tree --root --abbrev initial
3c2f75b5
JH
241diff-tree --root -r initial
242diff-tree --root -r --abbrev initial
c2f1d398 243:noellipses diff-tree --root -r --abbrev initial
3c2f75b5 244diff-tree --root -r --abbrev=4 initial
c2f1d398 245:noellipses diff-tree --root -r --abbrev=4 initial
3c2f75b5
JH
246diff-tree -p initial
247diff-tree --root -p initial
3046c7f6
ĐTCD
248diff-tree --root -p --abbrev=10 initial
249diff-tree --root -p --full-index initial
250diff-tree --root -p --full-index --abbrev=10 initial
3c2f75b5
JH
251diff-tree --patch-with-stat initial
252diff-tree --root --patch-with-stat initial
253diff-tree --patch-with-raw initial
254diff-tree --root --patch-with-raw initial
255
256diff-tree --pretty initial
257diff-tree --pretty --root initial
258diff-tree --pretty -p initial
259diff-tree --pretty --stat initial
260diff-tree --pretty --summary initial
261diff-tree --pretty --stat --summary initial
262diff-tree --pretty --root -p initial
263diff-tree --pretty --root --stat initial
026625e7
JH
264# improved by Timo's patch
265diff-tree --pretty --root --summary initial
266# improved by Timo's patch
267diff-tree --pretty --root --summary -r initial
3c2f75b5
JH
268diff-tree --pretty --root --stat --summary initial
269diff-tree --pretty --patch-with-stat initial
270diff-tree --pretty --root --patch-with-stat initial
271diff-tree --pretty --patch-with-raw initial
272diff-tree --pretty --root --patch-with-raw initial
273
274diff-tree --pretty=oneline initial
275diff-tree --pretty=oneline --root initial
276diff-tree --pretty=oneline -p initial
277diff-tree --pretty=oneline --root -p initial
278diff-tree --pretty=oneline --patch-with-stat initial
026625e7 279# improved by Timo's patch
3c2f75b5
JH
280diff-tree --pretty=oneline --root --patch-with-stat initial
281diff-tree --pretty=oneline --patch-with-raw initial
282diff-tree --pretty=oneline --root --patch-with-raw initial
283
284diff-tree --pretty side
285diff-tree --pretty -p side
286diff-tree --pretty --patch-with-stat side
287
58aaced4
SB
288diff-tree initial mode
289diff-tree --stat initial mode
290diff-tree --summary initial mode
291
3c2f75b5 292diff-tree master
3ae7fe2b 293diff-tree -m master
3c2f75b5
JH
294diff-tree -p master
295diff-tree -p -m master
296diff-tree -c master
297diff-tree -c --abbrev master
c2f1d398 298:noellipses diff-tree -c --abbrev master
3c2f75b5 299diff-tree --cc master
47979d5d
JH
300# stat only should show the diffstat with the first parent
301diff-tree -c --stat master
302diff-tree --cc --stat master
303diff-tree -c --stat --summary master
304diff-tree --cc --stat --summary master
305# stat summary should show the diffstat and summary with the first parent
306diff-tree -c --stat --summary side
307diff-tree --cc --stat --summary side
8290faa0 308diff-tree --cc --shortstat master
04b19fca 309diff-tree --cc --summary REVERSE
026625e7
JH
310# improved by Timo's patch
311diff-tree --cc --patch-with-stat master
312# improved by Timo's patch
47979d5d
JH
313diff-tree --cc --patch-with-stat --summary master
314# this is correct
315diff-tree --cc --patch-with-stat --summary side
3c2f75b5
JH
316
317log master
318log -p master
319log --root master
320log --root -p master
321log --patch-with-stat master
322log --root --patch-with-stat master
47979d5d 323log --root --patch-with-stat --summary master
026625e7 324# improved by Timo's patch
47979d5d 325log --root -c --patch-with-stat --summary master
026625e7 326# improved by Timo's patch
47979d5d 327log --root --cc --patch-with-stat --summary master
6fae74b4 328log --no-diff-merges -p --first-parent master
298889d3
SO
329log --diff-merges=off -p --first-parent master
330log --first-parent --diff-merges=off -p master
126f431a 331log -p --first-parent master
af04d8f1
SO
332log -p --diff-merges=first-parent master
333log --diff-merges=first-parent master
126f431a
JH
334log -m -p --first-parent master
335log -m -p master
6fc944d8
SO
336log --cc -m -p master
337log -c -m -p master
48229c19 338log -m --raw master
faf16d4e 339log -m --stat master
3c2f75b5 340log -SF master
dea007fb 341log -S F master
47979d5d 342log -SF -p master
251df09b
MM
343log -SF master --max-count=0
344log -SF master --max-count=1
345log -SF master --max-count=2
bf1dfc31
JH
346log -GF master
347log -GF -p master
348log -GF -p --pickaxe-all master
296d4a94 349log -IA -IB -I1 -I2 -p master
28fd76bd 350log --decorate --all
33e7018c 351log --decorate=full --all
748706d7
DS
352log --decorate --clear-decorations --all
353log --decorate=full --clear-decorations --all
3c2f75b5 354
fcbc6efc
TR
355rev-list --parents HEAD
356rev-list --children HEAD
3c2f75b5
JH
357
358whatchanged master
c2f1d398 359:noellipses whatchanged master
3c2f75b5
JH
360whatchanged -p master
361whatchanged --root master
c2f1d398 362:noellipses whatchanged --root master
3c2f75b5
JH
363whatchanged --root -p master
364whatchanged --patch-with-stat master
365whatchanged --root --patch-with-stat master
366whatchanged --root --patch-with-stat --summary master
026625e7 367# improved by Timo's patch
47979d5d 368whatchanged --root -c --patch-with-stat --summary master
026625e7 369# improved by Timo's patch
47979d5d 370whatchanged --root --cc --patch-with-stat --summary master
3c2f75b5 371whatchanged -SF master
c2f1d398 372:noellipses whatchanged -SF master
47979d5d 373whatchanged -SF -p master
3c2f75b5
JH
374
375log --patch-with-stat master -- dir/
376whatchanged --patch-with-stat master -- dir/
47979d5d
JH
377log --patch-with-stat --summary master -- dir/
378whatchanged --patch-with-stat --summary master -- dir/
3c2f75b5
JH
379
380show initial
381show --root initial
382show side
383show master
b4490059 384show -c master
2bf65873
JH
385show -m master
386show --first-parent master
3c2f75b5
JH
387show --stat side
388show --stat --summary side
389show --patch-with-stat side
390show --patch-with-raw side
c2f1d398 391:noellipses show --patch-with-raw side
3c2f75b5
JH
392show --patch-with-stat --summary side
393
d410e43b
JH
394format-patch --stdout initial..side
395format-patch --stdout initial..master^
396format-patch --stdout initial..master
a567fdcb
BG
397format-patch --stdout --no-numbered initial..master
398format-patch --stdout --numbered initial..master
d410e43b 399format-patch --attach --stdout initial..side
108dab28 400format-patch --attach --stdout --suffix=.diff initial..side
d410e43b
JH
401format-patch --attach --stdout initial..master^
402format-patch --attach --stdout initial..master
c112f689
JS
403format-patch --inline --stdout initial..side
404format-patch --inline --stdout initial..master^
747e2505 405format-patch --inline --stdout --numbered-files initial..master
a567fdcb 406format-patch --inline --stdout initial..master
171ddd91 407format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
dbd21447
AR
408config format.subjectprefix DIFFERENT_PREFIX
409format-patch --inline --stdout initial..master^^
a5a27c79 410format-patch --stdout --cover-letter -n initial..master^
d410e43b 411
b319b02e 412diff --abbrev initial..side
8ef05193
NTND
413diff -U initial..side
414diff -U1 initial..side
b319b02e
JH
415diff -r initial..side
416diff --stat initial..side
417diff -r --stat initial..side
418diff initial..side
419diff --patch-with-stat initial..side
420diff --patch-with-raw initial..side
c2f1d398 421:noellipses diff --patch-with-raw initial..side
b319b02e
JH
422diff --patch-with-stat -r initial..side
423diff --patch-with-raw -r initial..side
c2f1d398 424:noellipses diff --patch-with-raw -r initial..side
3cb56738 425diff --name-status dir2 dir
0569e9b8 426diff --no-index --name-status dir2 dir
e423ffd8 427diff --no-index --name-status -- dir2 dir
d61027b2 428diff --no-index dir dir3
b75271d9 429diff master master^ side
660e113c
JK
430# Can't use spaces...
431diff --line-prefix=abc master master^ side
f37bfb7a 432diff --dirstat master~1 master~2
204f01a2 433diff --dirstat initial rearrange
0133dab7 434diff --dirstat-by-file initial rearrange
dac03b55 435diff --dirstat --cc master~1 master
43d1948b
JB
436# No-index --abbrev and --no-abbrev
437diff --raw initial
c2f1d398 438:noellipses diff --raw initial
43d1948b 439diff --raw --abbrev=4 initial
c2f1d398 440:noellipses diff --raw --abbrev=4 initial
43d1948b
JB
441diff --raw --no-abbrev initial
442diff --no-index --raw dir2 dir
c2f1d398 443:noellipses diff --no-index --raw dir2 dir
43d1948b 444diff --no-index --raw --abbrev=4 dir2 dir
c2f1d398 445:noellipses diff --no-index --raw --abbrev=4 dir2 dir
43d1948b 446diff --no-index --raw --no-abbrev dir2 dir
ddf88fa6
NTND
447
448diff-tree --pretty --root --stat --compact-summary initial
449diff-tree --pretty -R --root --stat --compact-summary initial
5778b22b
TB
450diff-tree --pretty note
451diff-tree --pretty --notes note
452diff-tree --format=%N note
ddf88fa6
NTND
453diff-tree --stat --compact-summary initial mode
454diff-tree -R --stat --compact-summary initial mode
3c2f75b5
JH
455EOF
456
6a38e333
JN
457test_expect_success 'log -m matches pure log' '
458 git log master >result &&
7a55fa0e
SO
459 process_diffs result >expected &&
460 git log -m >result &&
461 process_diffs result >actual &&
462 test_cmp expected actual
463'
464
4320815e
SO
465test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
466 git log -p --diff-merges=separate master >result &&
467 process_diffs result >expected &&
468 git log -p --diff-merges=on master >result &&
469 process_diffs result >actual &&
17c13e60
SO
470 test_cmp expected actual
471'
472
c8e5cb06
SO
473test_expect_success 'log --dd matches --diff-merges=1 -p' '
474 git log --diff-merges=1 -p master >result &&
475 process_diffs result >expected &&
476 git log --dd master >result &&
477 process_diffs result >actual &&
478 test_cmp expected actual
479'
480
17c13e60
SO
481test_expect_success 'deny wrong log.diffMerges config' '
482 test_config log.diffMerges wrong-value &&
483 test_expect_code 128 git log
484'
485
486test_expect_success 'git config log.diffMerges first-parent' '
487 git log -p --diff-merges=first-parent master >result &&
488 process_diffs result >expected &&
489 test_config log.diffMerges first-parent &&
490 git log -p --diff-merges=on master >result &&
491 process_diffs result >actual &&
492 test_cmp expected actual
493'
494
495test_expect_success 'git config log.diffMerges first-parent vs -m' '
496 git log -p --diff-merges=first-parent master >result &&
497 process_diffs result >expected &&
498 test_config log.diffMerges first-parent &&
499 git log -p -m master >result &&
500 process_diffs result >actual &&
4320815e
SO
501 test_cmp expected actual
502'
503
e0b16421
SO
504# -m in "git diff-index" means "match missing", that differs
505# from its meaning in "git diff". Let's check it in diff-index.
506# The line in the output for removed file should disappear when
507# we provide -m in diff-index.
508test_expect_success 'git diff-index -m' '
509 rm -f file1 &&
510 git diff-index HEAD >without-m &&
511 lines_count=$(wc -l <without-m) &&
512 git diff-index -m HEAD >with-m &&
513 git restore file1 &&
514 test_line_count = $((lines_count - 1)) with-m
515'
516
dea007fb
MM
517test_expect_success 'log -S requires an argument' '
518 test_must_fail git log -S
519'
520
a2b7a3b3 521test_expect_success 'diff --cached on unborn branch' '
23937116 522 git symbolic-ref HEAD refs/heads/unborn &&
a2b7a3b3 523 git diff --cached >result &&
72f936b1 524 process_diffs result >actual &&
525 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
526 test_cmp expected actual
a2b7a3b3
NTND
527'
528
529test_expect_success 'diff --cached -- file on unborn branch' '
530 git diff --cached -- file0 >result &&
72f936b1 531 process_diffs result >actual &&
532 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
533 test_cmp expected actual
a2b7a3b3 534'
660e113c
JK
535test_expect_success 'diff --line-prefix with spaces' '
536 git diff --line-prefix="| | | " --cached -- file0 >result &&
72f936b1 537 process_diffs result >actual &&
538 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
539 test_cmp expected actual
660e113c 540'
a2b7a3b3 541
d299e9e5
JK
542test_expect_success 'diff-tree --stdin with log formatting' '
543 cat >expect <<-\EOF &&
544 Side
545 Third
546 Second
547 EOF
548 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
549 test_cmp expect actual
550'
551
f8781bfd
JH
552test_expect_success 'diff-tree --stdin with pathspec' '
553 cat >expect <<-EOF &&
554 Third
555
556 dir/sub
557 Second
558
559 dir/sub
560 EOF
561 git rev-list master^ |
562 git diff-tree -r --stdin --name-only --format=%s dir >actual &&
563 test_cmp expect actual
564'
565
5cdb3845
JH
566test_expect_success 'show A B ... -- <pathspec>' '
567 # side touches dir/sub, file0, and file3
568 # master^ touches dir/sub, and file1
569 # master^^ touches dir/sub, file0, and file2
570 git show --name-only --format="<%s>" side master^ master^^ -- dir >actual &&
571 cat >expect <<-\EOF &&
572 <Side>
573
574 dir/sub
575 <Third>
576
577 dir/sub
578 <Second>
579
580 dir/sub
581 EOF
582 test_cmp expect actual
583'
584
296d4a94
MK
585test_expect_success 'diff -I<regex>: setup' '
586 git checkout master &&
587 test_seq 50 >file0 &&
588 git commit -m "Set up -I<regex> test file" file0 &&
589 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
590 echo >>file0
591'
592test_expect_success 'diff -I<regex>' '
593 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
594 cat >expect <<-\EOF &&
595 diff --git a/file0 b/file0
596 --- a/file0
597 +++ b/file0
598 @@ -34,7 +31,6 @@
599 34
600 35
601 36
602 -37
603 38
604 39
605 40
606 EOF
607 compare_diff_patch expect actual
608'
609
610test_expect_success 'diff -I<regex> --stat' '
611 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
612 cat >expect <<-\EOF &&
613 file0 | 1 -
614 1 file changed, 1 deletion(-)
615 EOF
616 test_cmp expect actual
617'
618
619test_expect_success 'diff -I<regex>: detect malformed regex' '
620 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
6789275d 621 test_grep "invalid regex given to -I: " error
296d4a94
MK
622'
623
7c03d0db
JK
624# check_prefix <patch> <src> <dst>
625# check only lines with paths to avoid dependency on exact oid/contents
626check_prefix () {
627 grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths &&
628 cat >expect <<-EOF &&
629 diff --git $2 $3
630 --- $2
631 +++ $3
632 EOF
633 test_cmp expect actual.paths
634}
635
178401dc
JH
636test_expect_success 'diff-files does not respect diff.noPrefix' '
637 git -c diff.noPrefix diff-files -p >actual &&
7c03d0db
JK
638 check_prefix actual a/file0 b/file0
639'
640
641test_expect_success 'diff-files respects --no-prefix' '
642 git diff-files -p --no-prefix >actual &&
643 check_prefix actual file0 file0
644'
645
178401dc
JH
646test_expect_success 'diff respects diff.noPrefix' '
647 git -c diff.noPrefix diff >actual &&
7c03d0db
JK
648 check_prefix actual file0 file0
649'
650
178401dc
JH
651test_expect_success 'diff --default-prefix overrides diff.noPrefix' '
652 git -c diff.noPrefix diff --default-prefix >actual &&
b39a5697
JK
653 check_prefix actual a/file0 b/file0
654'
655
178401dc
JH
656test_expect_success 'diff respects diff.mnemonicPrefix' '
657 git -c diff.mnemonicPrefix diff >actual &&
7c03d0db
JK
658 check_prefix actual i/file0 w/file0
659'
660
178401dc
JH
661test_expect_success 'diff --default-prefix overrides diff.mnemonicPrefix' '
662 git -c diff.mnemonicPrefix diff --default-prefix >actual &&
b39a5697
JK
663 check_prefix actual a/file0 b/file0
664'
665
178401dc
JH
666test_expect_success 'diff respects diff.srcPrefix' '
667 git -c diff.srcPrefix=x/ diff >actual &&
7fdc2656
PH
668 check_prefix actual x/file0 b/file0
669'
670
178401dc
JH
671test_expect_success 'diff respects diff.dstPrefix' '
672 git -c diff.dstPrefix=y/ diff >actual &&
7fdc2656
PH
673 check_prefix actual a/file0 y/file0
674'
675
178401dc
JH
676test_expect_success 'diff --src-prefix overrides diff.srcPrefix' '
677 git -c diff.srcPrefix=y/ diff --src-prefix=z/ >actual &&
7fdc2656
PH
678 check_prefix actual z/file0 b/file0
679'
680
178401dc
JH
681test_expect_success 'diff --dst-prefix overrides diff.dstPrefix' '
682 git -c diff.dstPrefix=y/ diff --dst-prefix=z/ >actual &&
7fdc2656
PH
683 check_prefix actual a/file0 z/file0
684'
685
178401dc
JH
686test_expect_success 'diff.{src,dst}Prefix ignored with diff.noPrefix' '
687 git -c diff.dstPrefix=y/ -c diff.srcPrefix=x/ -c diff.noPrefix diff >actual &&
7fdc2656
PH
688 check_prefix actual file0 file0
689'
690
178401dc
JH
691test_expect_success 'diff.{src,dst}Prefix ignored with diff.mnemonicPrefix' '
692 git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ -c diff.mnemonicPrefix diff >actual &&
7fdc2656
PH
693 check_prefix actual i/file0 w/file0
694'
695
178401dc
JH
696test_expect_success 'diff.{src,dst}Prefix ignored with --default-prefix' '
697 git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ diff --default-prefix >actual &&
7fdc2656
PH
698 check_prefix actual a/file0 b/file0
699'
700
5825268d
RS
701test_expect_success 'diff --no-renames cannot be abbreviated' '
702 test_expect_code 129 git diff --no-rename >actual 2>error &&
703 test_must_be_empty actual &&
704 grep "invalid option: --no-rename" error
705'
706
3c2f75b5 707test_done