interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4013-diff-various.sh

784 lines · 21929 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Various diff formatting options'
7
8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11. ./test-lib.sh
12. "$TEST_DIRECTORY"/lib-diff.sh
13
14if ! test_have_prereq PERL_TEST_HELPERS
15then
16 skip_all='skipping diff various tests; Perl not available'
17 test_done
18fi
19
20test_expect_success setup '
21
22 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
23 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
24 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
25
26 mkdir dir &&
27 mkdir dir2 &&
28 test_write_lines 1 2 3 >file0 &&
29 test_write_lines A B >dir/sub &&
30 cat file0 >file2 &&
31 git add file0 file2 dir/sub &&
32 git commit -m Initial &&
33
34 git branch initial &&
35 git branch side &&
36
37 GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
38 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
39 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
40
41 test_write_lines 4 5 6 >>file0 &&
42 test_write_lines C D >>dir/sub &&
43 rm -f file2 &&
44 git update-index --remove file0 file2 dir/sub &&
45 git commit -m "Second${LF}${LF}This is the second commit." &&
46
47 GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
48 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
49 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
50
51 test_write_lines A B C >file1 &&
52 git add file1 &&
53 test_write_lines E F >>dir/sub &&
54 git update-index dir/sub &&
55 git commit -m Third &&
56
57 GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
58 GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
59 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
60
61 git checkout side &&
62 test_write_lines A B C >>file0 &&
63 test_write_lines 1 2 >>dir/sub &&
64 cat dir/sub >file3 &&
65 git add file3 &&
66 git update-index file0 dir/sub &&
67 git commit -m Side &&
68
69 GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
70 GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
71 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
72
73 git checkout main &&
74 git pull -s ours --no-rebase . side &&
75
76 GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
77 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
78 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
79
80 test_write_lines A B C >>file0 &&
81 test_write_lines 1 2 >>dir/sub &&
82 git update-index file0 dir/sub &&
83
84 mkdir dir3 &&
85 cp dir/sub dir3/sub &&
86 test-tool chmtime +1 dir3/sub &&
87
88 git config log.showroot false &&
89 git commit --amend &&
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 rearrange initial &&
95 test_write_lines B A >dir/sub &&
96 git add dir/sub &&
97 git commit -m "Rearranged lines in dir/sub" &&
98 git checkout main &&
99
100 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
101 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
102 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
103 git checkout -b mode initial &&
104 git update-index --chmod=+x file0 &&
105 git commit -m "update mode" &&
106 git checkout -f main &&
107
108 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
109 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
110 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
111 git checkout -b note initial &&
112 git update-index --chmod=+x file2 &&
113 git commit -m "update mode (file2)" &&
114 git notes add -m "note" &&
115 git checkout -f main &&
116
117 # Same merge as main, but with parents reversed. Hide it in a
118 # pseudo-ref to avoid impacting tests with --all.
119 commit=$(echo reverse |
120 git commit-tree -p main^2 -p main^1 main^{tree}) &&
121 git update-ref REVERSE $commit &&
122
123 git config diff.renames false &&
124
125 git show-branch
126'
127
128: <<\EOF
129! [initial] Initial
130 * [main] Merge branch 'side'
131 ! [rearrange] Rearranged lines in dir/sub
132 ! [side] Side
133----
134 + [rearrange] Rearranged lines in dir/sub
135 - [main] Merge branch 'side'
136 * + [side] Side
137 * [main^] Third
138 * [main~2] Second
139+*++ [initial] Initial
140EOF
141
142process_diffs () {
143 perl -e '
144 my $oid_length = length($ARGV[0]);
145 my $x40 = "[0-9a-f]{40}";
146 my $xab = "[0-9a-f]{4,16}";
147 my $orx = "[0-9a-f]" x $oid_length;
148
149 sub munge_oid {
150 my ($oid) = @_;
151 my $x;
152
153 return "" unless length $oid;
154
155 if ($oid =~ /^(100644|100755|120000)$/) {
156 return $oid;
157 }
158
159 if ($oid =~ /^0*$/) {
160 $x = "0";
161 } else {
162 $x = "f";
163 }
164
165 if (length($oid) == 40) {
166 return $x x $oid_length;
167 } else {
168 return $x x length($oid);
169 }
170 }
171
172 while (<STDIN>) {
173 s/($orx)/munge_oid($1)/ge;
174 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
175 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
176 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
177 s/^($x40)($| )/munge_oid($1) . $2/e;
178 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
179 print;
180 }
181 ' "$ZERO_OID" <"$1"
182}
183
184V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
185while read magic cmd
186do
187 case "$magic" in
188 '' | '#'*)
189 continue ;;
190 :noellipses)
191 magic=noellipses
192 label="$magic-$cmd"
193 ;;
194 :*)
195 BUG "unknown magic $magic"
196 ;;
197 *)
198 cmd="$magic $cmd"
199 magic=
200 label="$cmd"
201 ;;
202 esac
203
204 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
205 pfx=$(printf "%04d" $test_count)
206 expect="$TEST_DIRECTORY/t4013/diff.$test"
207 actual="$pfx-diff.$test"
208
209 case "$cmd" in
210 whatchanged | whatchanged" "*)
211 prereq=!WITH_BREAKING_CHANGES
212 ;;
213 *)
214 prereq=;;
215 esac
216
217 test_expect_success $prereq "git $cmd # magic is ${magic:-(not used)}" '
218 {
219 echo "$ git $cmd"
220
221 case "$cmd" in
222 whatchanged | whatchanged" "*)
223 run="whatchanged --i-still-use-this"
224 run="$run ${cmd#whatchanged}" ;;
225 *)
226 run=$cmd ;;
227 esac &&
228 case "$magic" in
229 "")
230 GIT_PRINT_SHA1_ELLIPSIS=yes git $run ;;
231 noellipses)
232 git $run ;;
233 esac |
234 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
235 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
236 echo "\$"
237 } >"$actual" &&
238 if test -f "$expect"
239 then
240 process_diffs "$actual" >actual &&
241 process_diffs "$expect" >expect &&
242 case $cmd in
243 *format-patch* | *-stat*)
244 test_cmp expect actual;;
245 *)
246 test_cmp expect actual;;
247 esac &&
248 rm -f "$actual" actual expect
249 else
250 # this is to help developing new tests.
251 cp "$actual" "$expect"
252 false
253 fi
254 '
255done <<\EOF
256diff-tree initial
257diff-tree -r initial
258diff-tree -r --abbrev initial
259diff-tree -r --abbrev=4 initial
260diff-tree --root initial
261diff-tree --root --abbrev initial
262:noellipses diff-tree --root --abbrev initial
263diff-tree --root -r initial
264diff-tree --root -r --abbrev initial
265:noellipses diff-tree --root -r --abbrev initial
266diff-tree --root -r --abbrev=4 initial
267:noellipses diff-tree --root -r --abbrev=4 initial
268diff-tree -p initial
269diff-tree --root -p initial
270diff-tree --root -p --abbrev=10 initial
271diff-tree --root -p --full-index initial
272diff-tree --root -p --full-index --abbrev=10 initial
273diff-tree --patch-with-stat initial
274diff-tree --root --patch-with-stat initial
275diff-tree --patch-with-raw initial
276diff-tree --root --patch-with-raw initial
277
278diff-tree --pretty initial
279diff-tree --pretty --root initial
280diff-tree --pretty -p initial
281diff-tree --pretty --stat initial
282diff-tree --pretty --summary initial
283diff-tree --pretty --stat --summary initial
284diff-tree --pretty --root -p initial
285diff-tree --pretty --root --stat initial
286# improved by Timo's patch
287diff-tree --pretty --root --summary initial
288# improved by Timo's patch
289diff-tree --pretty --root --summary -r initial
290diff-tree --pretty --root --stat --summary initial
291diff-tree --pretty --patch-with-stat initial
292diff-tree --pretty --root --patch-with-stat initial
293diff-tree --pretty --patch-with-raw initial
294diff-tree --pretty --root --patch-with-raw initial
295
296diff-tree --pretty=oneline initial
297diff-tree --pretty=oneline --root initial
298diff-tree --pretty=oneline -p initial
299diff-tree --pretty=oneline --root -p initial
300diff-tree --pretty=oneline --patch-with-stat initial
301# improved by Timo's patch
302diff-tree --pretty=oneline --root --patch-with-stat initial
303diff-tree --pretty=oneline --patch-with-raw initial
304diff-tree --pretty=oneline --root --patch-with-raw initial
305
306diff-tree --pretty side
307diff-tree --pretty -p side
308diff-tree --pretty --patch-with-stat side
309
310diff-tree initial mode
311diff-tree --stat initial mode
312diff-tree --summary initial mode
313
314diff-tree main
315diff-tree -m main
316diff-tree -p main
317diff-tree -p -m main
318diff-tree -c main
319diff-tree -c --abbrev main
320:noellipses diff-tree -c --abbrev main
321diff-tree --cc main
322# stat only should show the diffstat with the first parent
323diff-tree -c --stat main
324diff-tree --cc --stat main
325diff-tree -c --stat --summary main
326diff-tree --cc --stat --summary main
327# stat summary should show the diffstat and summary with the first parent
328diff-tree -c --stat --summary side
329diff-tree --cc --stat --summary side
330diff-tree --cc --shortstat main
331diff-tree --cc --summary REVERSE
332# improved by Timo's patch
333diff-tree --cc --patch-with-stat main
334# improved by Timo's patch
335diff-tree --cc --patch-with-stat --summary main
336# this is correct
337diff-tree --cc --patch-with-stat --summary side
338
339log main
340log -p main
341log --root main
342log --root -p main
343log --patch-with-stat main
344log --root --patch-with-stat main
345log --root --patch-with-stat --summary main
346# improved by Timo's patch
347log --root -c --patch-with-stat --summary main
348# improved by Timo's patch
349log --root --cc --patch-with-stat --summary main
350log --no-diff-merges -p --first-parent main
351log --diff-merges=off -p --first-parent main
352log --first-parent --diff-merges=off -p main
353log -p --first-parent main
354log -p --diff-merges=first-parent main
355log --diff-merges=first-parent main
356log -m -p --first-parent main
357log -m -p main
358log --cc -m -p main
359log -c -m -p main
360log -m --raw main
361log -m --stat main
362log -SF main
363log -S F main
364log -SF -p main
365log -SF main --max-count=0
366log -SF main --max-count=1
367log -SF main --max-count=2
368log -GF main
369log -GF -p main
370log -GF -p --pickaxe-all main
371log -IA -IB -I1 -I2 -p main
372log --decorate --all
373log --decorate=full --all
374log --decorate --clear-decorations --all
375log --decorate=full --clear-decorations --all
376
377rev-list --parents HEAD
378rev-list --children HEAD
379
380whatchanged main
381:noellipses whatchanged main
382whatchanged -p main
383whatchanged --root main
384:noellipses whatchanged --root main
385whatchanged --root -p main
386whatchanged --patch-with-stat main
387whatchanged --root --patch-with-stat main
388whatchanged --root --patch-with-stat --summary main
389# improved by Timo's patch
390whatchanged --root -c --patch-with-stat --summary main
391# improved by Timo's patch
392whatchanged --root --cc --patch-with-stat --summary main
393whatchanged -SF main
394:noellipses whatchanged -SF main
395whatchanged -SF -p main
396
397log --patch-with-stat main -- dir/
398whatchanged --patch-with-stat main -- dir/
399log --patch-with-stat --summary main -- dir/
400whatchanged --patch-with-stat --summary main -- dir/
401
402show initial
403show --root initial
404show side
405show main
406show -c main
407show -m main
408show --first-parent main
409show --stat side
410show --stat --summary side
411show --patch-with-stat side
412show --patch-with-raw side
413:noellipses show --patch-with-raw side
414show --patch-with-stat --summary side
415
416format-patch --stdout initial..side
417format-patch --stdout initial..main^
418format-patch --stdout initial..main
419format-patch --stdout --no-numbered initial..main
420format-patch --stdout --numbered initial..main
421format-patch --attach --stdout initial..side
422format-patch --attach --stdout --suffix=.diff initial..side
423format-patch --attach --stdout initial..main^
424format-patch --attach --stdout initial..main
425format-patch --inline --stdout initial..side
426format-patch --inline --stdout initial..main^
427format-patch --inline --stdout --numbered-files initial..main
428format-patch --inline --stdout initial..main
429format-patch --inline --stdout --subject-prefix=TESTCASE initial..main
430config format.subjectprefix DIFFERENT_PREFIX
431format-patch --inline --stdout initial..main^^
432format-patch --stdout --cover-letter -n initial..main^
433
434diff --abbrev initial..side
435diff -U initial..side
436diff -U1 initial..side
437diff -r initial..side
438diff --stat initial..side
439diff -r --stat initial..side
440diff initial..side
441diff --patch-with-stat initial..side
442diff --patch-with-raw initial..side
443:noellipses diff --patch-with-raw initial..side
444diff --patch-with-stat -r initial..side
445diff --patch-with-raw -r initial..side
446:noellipses diff --patch-with-raw -r initial..side
447diff --name-status dir2 dir
448diff --no-index --name-status dir2 dir
449diff --no-index --name-status -- dir2 dir
450diff --no-index dir dir3
451diff main main^ side
452# Can't use spaces...
453diff --line-prefix=abc main main^ side
454diff --dirstat main~1 main~2
455diff --dirstat initial rearrange
456diff --dirstat-by-file initial rearrange
457diff --dirstat --cc main~1 main
458# No-index --abbrev and --no-abbrev
459diff --raw initial
460:noellipses diff --raw initial
461diff --raw --abbrev=4 initial
462:noellipses diff --raw --abbrev=4 initial
463diff --raw --no-abbrev initial
464diff --no-index --raw dir2 dir
465:noellipses diff --no-index --raw dir2 dir
466diff --no-index --raw --abbrev=4 dir2 dir
467:noellipses diff --no-index --raw --abbrev=4 dir2 dir
468diff --no-index --raw --no-abbrev dir2 dir
469
470diff-tree --pretty --root --stat --compact-summary initial
471diff-tree --pretty -R --root --stat --compact-summary initial
472diff-tree --pretty note
473diff-tree --pretty --notes note
474diff-tree --format=%N note
475diff-tree --stat --compact-summary initial mode
476diff-tree -R --stat --compact-summary initial mode
477EOF
478
479test_expect_success !WITH_BREAKING_CHANGES 'whatchanged needs --i-still-use-this' '
480 test_must_fail git whatchanged >message 2>&1 &&
481 test_grep "will be removed soon" message
482'
483
484test_expect_success 'log -m matches pure log' '
485 git log main >result &&
486 process_diffs result >expected &&
487 git log -m >result &&
488 process_diffs result >actual &&
489 test_cmp expected actual
490'
491
492test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
493 git log -p --diff-merges=separate main >result &&
494 process_diffs result >expected &&
495 git log -p --diff-merges=on main >result &&
496 process_diffs result >actual &&
497 test_cmp expected actual
498'
499
500test_expect_success 'log --dd matches --diff-merges=1 -p' '
501 git log --diff-merges=1 -p main >result &&
502 process_diffs result >expected &&
503 git log --dd main >result &&
504 process_diffs result >actual &&
505 test_cmp expected actual
506'
507
508test_expect_success 'deny wrong log.diffMerges config' '
509 test_config log.diffMerges wrong-value &&
510 test_expect_code 128 git log
511'
512
513test_expect_success 'git config log.diffMerges first-parent' '
514 git log -p --diff-merges=first-parent main >result &&
515 process_diffs result >expected &&
516 test_config log.diffMerges first-parent &&
517 git log -p --diff-merges=on main >result &&
518 process_diffs result >actual &&
519 test_cmp expected actual
520'
521
522test_expect_success 'git config log.diffMerges first-parent vs -m' '
523 git log -p --diff-merges=first-parent main >result &&
524 process_diffs result >expected &&
525 test_config log.diffMerges first-parent &&
526 git log -p -m main >result &&
527 process_diffs result >actual &&
528 test_cmp expected actual
529'
530
531# -m in "git diff-index" means "match missing", that differs
532# from its meaning in "git diff". Let's check it in diff-index.
533# The line in the output for removed file should disappear when
534# we provide -m in diff-index.
535test_expect_success 'git diff-index -m' '
536 rm -f file1 &&
537 git diff-index HEAD >without-m &&
538 lines_count=$(wc -l <without-m) &&
539 git diff-index -m HEAD >with-m &&
540 git restore file1 &&
541 test_line_count = $((lines_count - 1)) with-m
542'
543
544test_expect_success 'log -S requires an argument' '
545 test_must_fail git log -S
546'
547
548test_expect_success 'diff --cached on unborn branch' '
549 git symbolic-ref HEAD refs/heads/unborn &&
550 git diff --cached >result &&
551 process_diffs result >actual &&
552 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
553 test_cmp expected actual
554'
555
556test_expect_success 'diff --cached -- file on unborn branch' '
557 git diff --cached -- file0 >result &&
558 process_diffs result >actual &&
559 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
560 test_cmp expected actual
561'
562test_expect_success 'diff --line-prefix with spaces' '
563 git diff --line-prefix="| | | " --cached -- file0 >result &&
564 process_diffs result >actual &&
565 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
566 test_cmp expected actual
567'
568
569test_expect_success 'diff-tree --stdin with log formatting' '
570 cat >expect <<-\EOF &&
571 Side
572 Third
573 Second
574 EOF
575 git rev-list main | git diff-tree --stdin --format=%s -s >actual &&
576 test_cmp expect actual
577'
578
579test_expect_success 'diff-tree --stdin with pathspec' '
580 cat >expect <<-EOF &&
581 Third
582
583 dir/sub
584 Second
585
586 dir/sub
587 EOF
588 git rev-list main^ |
589 git diff-tree -r --stdin --name-only --format=%s dir >actual &&
590 test_cmp expect actual
591'
592
593test_expect_success 'show A B ... -- <pathspec>' '
594 # side touches dir/sub, file0, and file3
595 # main^ touches dir/sub, and file1
596 # main^^ touches dir/sub, file0, and file2
597 git show --name-only --format="<%s>" side main^ main^^ -- dir >actual &&
598 cat >expect <<-\EOF &&
599 <Side>
600
601 dir/sub
602 <Third>
603
604 dir/sub
605 <Second>
606
607 dir/sub
608 EOF
609 test_cmp expect actual
610'
611
612test_expect_success 'diff -I<regex>: setup' '
613 git checkout main &&
614 test_seq 50 >file0 &&
615 git commit -m "Set up -I<regex> test file" file0 &&
616 test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
617 echo >>file0
618'
619test_expect_success 'diff -I<regex>' '
620 git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
621 cat >expect <<-\EOF &&
622 diff --git a/file0 b/file0
623 --- a/file0
624 +++ b/file0
625 @@ -34,7 +31,6 @@
626 34
627 35
628 36
629 -37
630 38
631 39
632 40
633 EOF
634 compare_diff_patch expect actual
635'
636
637test_expect_success 'diff -I<regex> --stat' '
638 git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
639 cat >expect <<-\EOF &&
640 file0 | 1 -
641 1 file changed, 1 deletion(-)
642 EOF
643 test_cmp expect actual
644'
645
646test_expect_success 'diff -I<regex>: detect malformed regex' '
647 test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
648 test_grep "invalid regex given to -I: " error
649'
650
651test_expect_success 'diff -I<regex>: ignore matching file' '
652 test_when_finished "git rm -f file1" &&
653 test_seq 50 >file1 &&
654 git add file1 &&
655 test_seq 50 | sed -e "s/13/ten and three/" -e "s/^[124-9].*/& /" >file1 &&
656
657 : >actual &&
658 git diff --raw --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
659 git diff --name-only --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
660 git diff --name-status --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
661 test_grep ! "file1" actual
662'
663
664test_expect_success 'diff -I<regex>: ignore all content changes' '
665 test_when_finished "git rm -f file1 file2 file3" &&
666 : >file1 &&
667 git add file1 &&
668 : >file2 &&
669 git add file2 &&
670 : >file3 &&
671 git add file3 &&
672
673 rm -f file1 file2 &&
674 mkdir file2 &&
675 echo "A" >file3 &&
676 A_hash=$(git hash-object -w file3) &&
677 echo "B" >file3 &&
678 B_hash=$(git hash-object -w file3) &&
679 cat <<-EOF | git update-index --index-info &&
680 100644 $A_hash 1 file3
681 100644 $B_hash 2 file3
682 EOF
683
684 test_diff_no_content_changes () {
685 git diff $1 --ignore-blank-lines -I".*" >actual &&
686 test_line_count = 3 actual &&
687 test_grep "file1" actual &&
688 test_grep "file2" actual &&
689 test_grep "file3" actual &&
690 test_grep ! "diff --git" actual
691 } &&
692 test_diff_no_content_changes "--raw" &&
693 test_diff_no_content_changes "--name-only" &&
694 test_diff_no_content_changes "--name-status" &&
695
696 : >actual &&
697 test_must_fail git diff --quiet -I".*" >actual &&
698 test_must_be_empty actual
699'
700
701# check_prefix <patch> <src> <dst>
702# check only lines with paths to avoid dependency on exact oid/contents
703check_prefix () {
704 grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths &&
705 cat >expect <<-EOF &&
706 diff --git $2 $3
707 --- $2
708 +++ $3
709 EOF
710 test_cmp expect actual.paths
711}
712
713test_expect_success 'diff-files does not respect diff.noPrefix' '
714 git -c diff.noPrefix diff-files -p >actual &&
715 check_prefix actual a/file0 b/file0
716'
717
718test_expect_success 'diff-files respects --no-prefix' '
719 git diff-files -p --no-prefix >actual &&
720 check_prefix actual file0 file0
721'
722
723test_expect_success 'diff respects diff.noPrefix' '
724 git -c diff.noPrefix diff >actual &&
725 check_prefix actual file0 file0
726'
727
728test_expect_success 'diff --default-prefix overrides diff.noPrefix' '
729 git -c diff.noPrefix diff --default-prefix >actual &&
730 check_prefix actual a/file0 b/file0
731'
732
733test_expect_success 'diff respects diff.mnemonicPrefix' '
734 git -c diff.mnemonicPrefix diff >actual &&
735 check_prefix actual i/file0 w/file0
736'
737
738test_expect_success 'diff --default-prefix overrides diff.mnemonicPrefix' '
739 git -c diff.mnemonicPrefix diff --default-prefix >actual &&
740 check_prefix actual a/file0 b/file0
741'
742
743test_expect_success 'diff respects diff.srcPrefix' '
744 git -c diff.srcPrefix=x/ diff >actual &&
745 check_prefix actual x/file0 b/file0
746'
747
748test_expect_success 'diff respects diff.dstPrefix' '
749 git -c diff.dstPrefix=y/ diff >actual &&
750 check_prefix actual a/file0 y/file0
751'
752
753test_expect_success 'diff --src-prefix overrides diff.srcPrefix' '
754 git -c diff.srcPrefix=y/ diff --src-prefix=z/ >actual &&
755 check_prefix actual z/file0 b/file0
756'
757
758test_expect_success 'diff --dst-prefix overrides diff.dstPrefix' '
759 git -c diff.dstPrefix=y/ diff --dst-prefix=z/ >actual &&
760 check_prefix actual a/file0 z/file0
761'
762
763test_expect_success 'diff.{src,dst}Prefix ignored with diff.noPrefix' '
764 git -c diff.dstPrefix=y/ -c diff.srcPrefix=x/ -c diff.noPrefix diff >actual &&
765 check_prefix actual file0 file0
766'
767
768test_expect_success 'diff.{src,dst}Prefix ignored with diff.mnemonicPrefix' '
769 git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ -c diff.mnemonicPrefix diff >actual &&
770 check_prefix actual i/file0 w/file0
771'
772
773test_expect_success 'diff.{src,dst}Prefix ignored with --default-prefix' '
774 git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ diff --default-prefix >actual &&
775 check_prefix actual a/file0 b/file0
776'
777
778test_expect_success 'diff --no-renames cannot be abbreviated' '
779 test_expect_code 129 git diff --no-rename >actual 2>error &&
780 test_must_be_empty actual &&
781 test_grep "invalid option: --no-rename" error
782'
783
784test_done