]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t4015-diff-whitespace.sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description
='Test special whitespace in diff engine.
10 .
"$TEST_DIRECTORY"/diff-lib.sh
12 test_expect_success
"Ray Lehtiniemi's example" '
18 git update-index --add x &&
28 cat <<-\EOF >expect &&
30 index adf3937..6edc172 100644
44 test_cmp expect out &&
47 test_cmp expect out &&
53 test_expect_success
'another test, without options' '
54 tr Q "\015" <<-\EOF >x &&
55 whitespace at beginning
57 whitespace in the middle
65 tr "_" " " <<-\EOF >x &&
66 _ whitespace at beginning
68 white space in the middle
74 tr "Q_" "\015 " <<-\EOF >expect &&
76 index d99af23..22d9f73 100644
80 -whitespace at beginning
82 -whitespace in the middle
84 + whitespace at beginning
86 +white space in the middle
94 test_cmp expect out &&
97 test_must_be_empty out &&
99 git diff -w -b >out &&
100 test_must_be_empty out &&
102 git diff -w --ignore-space-at-eol >out &&
103 test_must_be_empty out &&
105 git diff -w -b --ignore-space-at-eol >out &&
106 test_must_be_empty out &&
108 git diff -w --ignore-cr-at-eol >out &&
109 test_must_be_empty out &&
111 tr "Q_" "\015 " <<-\EOF >expect &&
113 index d99af23..22d9f73 100644
117 -whitespace at beginning
118 +_ whitespace at beginning
120 -whitespace in the middle
121 +white space in the middle
127 test_cmp expect out &&
129 git diff -b --ignore-space-at-eol >out &&
130 test_cmp expect out &&
132 git diff -b --ignore-cr-at-eol >out &&
133 test_cmp expect out &&
135 tr "Q_" "\015 " <<-\EOF >expect &&
137 index d99af23..22d9f73 100644
141 -whitespace at beginning
143 -whitespace in the middle
144 +_ whitespace at beginning
146 +white space in the middle
151 git diff --ignore-space-at-eol >out &&
152 test_cmp expect out &&
154 git diff --ignore-space-at-eol --ignore-cr-at-eol >out &&
155 test_cmp expect out &&
157 tr "Q_" "\015 " <<-\EOF >expect &&
159 index_d99af23..22d9f73 100644
163 -whitespace at beginning
165 -whitespace in the middle
167 +_ whitespace at beginning
169 +white space in the middle
174 git diff --ignore-cr-at-eol >out &&
178 test_expect_success
'ignore-blank-lines: only new lines' '
180 git update-index x &&
181 test_seq 5 | sed "/3/i\\
183 git diff --ignore-blank-lines >out &&
184 test_must_be_empty out
187 test_expect_success
'ignore-blank-lines: only new lines with space' '
189 git update-index x &&
190 test_seq 5 | sed "/3/i\\
192 git diff -w --ignore-blank-lines >out &&
193 test_must_be_empty out
196 test_expect_success
'ignore-blank-lines: after change' '
208 git update-index x &&
221 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
222 cat <<-\EOF >expected &&
236 compare_diff_patch expected out.tmp
239 test_expect_success
'ignore-blank-lines: before change' '
250 git update-index x &&
263 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
264 cat <<-\EOF >expected &&
277 compare_diff_patch expected out.tmp
280 test_expect_success
'ignore-blank-lines: between changes' '
295 git update-index x &&
312 git diff --ignore-blank-lines >out.tmp &&
313 cat <<-\EOF >expected &&
334 compare_diff_patch expected out.tmp
337 test_expect_success
'ignore-blank-lines: between changes (with interhunkctx)' '
339 git update-index x &&
357 git diff --inter-hunk-context=2 --ignore-blank-lines >out.tmp &&
358 cat <<-\EOF >expected &&
379 compare_diff_patch expected out.tmp
382 test_expect_success
'ignore-blank-lines: scattered spaces' '
384 git update-index x &&
405 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
406 cat <<-\EOF >expected &&
421 compare_diff_patch expected out.tmp
424 test_expect_success
'ignore-blank-lines: spaces coalesce' '
426 git update-index x &&
440 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
441 cat <<-\EOF >expected &&
458 compare_diff_patch expected out.tmp
461 test_expect_success
'ignore-blank-lines: mix changes and blank lines' '
463 git update-index x &&
489 git diff --ignore-blank-lines >out.tmp &&
490 cat <<-\EOF >expected &&
519 compare_diff_patch expected out.tmp
522 test_expect_success
'check mixed spaces and tabs in indent' '
523 # This is indented with SP HT SP.
525 git diff --check | grep "space before tab in indent"
528 test_expect_success
'check mixed tabs and spaces in indent' '
529 # This is indented with HT SP HT.
531 git diff --check | grep "space before tab in indent"
534 test_expect_success
'check with no whitespace errors' '
535 git commit -m "snapshot" &&
540 test_expect_success
'check with trailing whitespace' '
542 test_must_fail git diff --check
545 test_expect_success
'check with space before tab in indent' '
546 # indent has space followed by hard tab
548 test_must_fail git diff --check
551 test_expect_success
'--check and --exit-code are not exclusive' '
553 git diff --check --exit-code
556 test_expect_success
'--check and --quiet are not exclusive' '
557 git diff --check --quiet
560 test_expect_success
'check staged with no whitespace errors' '
563 git diff --cached --check
566 test_expect_success
'check staged with trailing whitespace' '
569 test_must_fail git diff --cached --check
572 test_expect_success
'check staged with space before tab in indent' '
573 # indent has space followed by hard tab
576 test_must_fail git diff --cached --check
579 test_expect_success
'check with no whitespace errors (diff-index)' '
582 git diff-index --check HEAD
585 test_expect_success
'check with trailing whitespace (diff-index)' '
588 test_must_fail git diff-index --check HEAD
591 test_expect_success
'check with space before tab in indent (diff-index)' '
592 # indent has space followed by hard tab
595 test_must_fail git diff-index --check HEAD
598 test_expect_success
'check staged with no whitespace errors (diff-index)' '
601 git diff-index --cached --check HEAD
604 test_expect_success
'check staged with trailing whitespace (diff-index)' '
607 test_must_fail git diff-index --cached --check HEAD
610 test_expect_success
'check staged with space before tab in indent (diff-index)' '
611 # indent has space followed by hard tab
614 test_must_fail git diff-index --cached --check HEAD
617 test_expect_success
'check with no whitespace errors (diff-tree)' '
619 git commit -m "new commit" x &&
620 git diff-tree --check HEAD^ HEAD
623 test_expect_success
'check with trailing whitespace (diff-tree)' '
625 git commit -m "another commit" x &&
626 test_must_fail git diff-tree --check HEAD^ HEAD
629 test_expect_success
'check with space before tab in indent (diff-tree)' '
630 # indent has space followed by hard tab
632 git commit -m "yet another" x &&
633 test_must_fail git diff-tree --check HEAD^ HEAD
636 test_expect_success
'check with ignored trailing whitespace attr (diff-tree)' '
637 test_when_finished "git reset --hard HEAD^" &&
639 # create a whitespace error that should be ignored
640 echo "* -whitespace" >.gitattributes &&
641 git add .gitattributes &&
644 git commit -m "add trailing space" &&
646 # with a worktree diff-tree ignores the whitespace error
647 git diff-tree --root --check HEAD &&
649 # without a worktree diff-tree still ignores the whitespace error
650 git -C .git diff-tree --root --check HEAD
653 test_expect_success
'check trailing whitespace (trailing-space: off)' '
654 git config core.whitespace "-trailing-space" &&
655 echo "foo (); " >x &&
659 test_expect_success
'check trailing whitespace (trailing-space: on)' '
660 git config core.whitespace "trailing-space" &&
661 echo "foo (); " >x &&
662 test_must_fail git diff --check
665 test_expect_success
'check space before tab in indent (space-before-tab: off)' '
666 # indent contains space followed by HT
667 git config core.whitespace "-space-before-tab" &&
668 echo " foo ();" >x &&
672 test_expect_success
'check space before tab in indent (space-before-tab: on)' '
673 # indent contains space followed by HT
674 git config core.whitespace "space-before-tab" &&
675 echo " foo (); " >x &&
676 test_must_fail git diff --check
679 test_expect_success
'check spaces as indentation (indent-with-non-tab: off)' '
680 git config core.whitespace "-indent-with-non-tab" &&
681 echo " foo ();" >x &&
685 test_expect_success
'check spaces as indentation (indent-with-non-tab: on)' '
686 git config core.whitespace "indent-with-non-tab" &&
687 echo " foo ();" >x &&
688 test_must_fail git diff --check
691 test_expect_success
'ditto, but tabwidth=9' '
692 git config core.whitespace "indent-with-non-tab,tabwidth=9" &&
696 test_expect_success
'check tabs and spaces as indentation (indent-with-non-tab: on)' '
697 git config core.whitespace "indent-with-non-tab" &&
698 echo " foo ();" >x &&
699 test_must_fail git diff --check
702 test_expect_success
'ditto, but tabwidth=10' '
703 git config core.whitespace "indent-with-non-tab,tabwidth=10" &&
704 test_must_fail git diff --check
707 test_expect_success
'ditto, but tabwidth=20' '
708 git config core.whitespace "indent-with-non-tab,tabwidth=20" &&
712 test_expect_success
'check tabs as indentation (tab-in-indent: off)' '
713 git config core.whitespace "-tab-in-indent" &&
714 echo " foo ();" >x &&
718 test_expect_success
'check tabs as indentation (tab-in-indent: on)' '
719 git config core.whitespace "tab-in-indent" &&
720 echo " foo ();" >x &&
721 test_must_fail git diff --check
724 test_expect_success
'check tabs and spaces as indentation (tab-in-indent: on)' '
725 git config core.whitespace "tab-in-indent" &&
726 echo " foo ();" >x &&
727 test_must_fail git diff --check
730 test_expect_success
'ditto, but tabwidth=1 (must be irrelevant)' '
731 git config core.whitespace "tab-in-indent,tabwidth=1" &&
732 test_must_fail git diff --check
735 test_expect_success
'check tab-in-indent and indent-with-non-tab conflict' '
736 git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
738 test_must_fail git diff --check
741 test_expect_success
'check tab-in-indent excluded from wildcard whitespace attribute' '
742 git config --unset core.whitespace &&
743 echo "x whitespace" >.gitattributes &&
744 echo " foo ();" >x &&
749 test_expect_success
'line numbers in --check output are correct' '
751 echo "foo(); " >>x &&
752 git diff --check | grep "x:2:"
755 test_expect_success
'checkdiff detects new trailing blank lines (1)' '
758 git diff --check | grep "new blank line"
761 test_expect_success
'checkdiff detects new trailing blank lines (2)' '
762 { echo a; echo b; echo; echo; } >x &&
764 { echo a; echo; echo; echo; echo; } >x &&
765 git diff --check | grep "new blank line"
768 test_expect_success
'checkdiff allows new blank lines' '
772 echo "/* This is new */" &&
779 test_expect_success
'whitespace-only changes not reported' '
781 echo >x "hello world" &&
783 git commit -m "hello 1" &&
784 echo >x "hello world" &&
785 git diff -b >actual &&
786 test_must_be_empty actual
791 similarity index NUM%
794 index 380c32a..a97b785 100644
796 test_expect_success
'whitespace-only changes reported across renames' '
798 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
800 git commit -m "base" &&
801 sed -e "5s/^/ /" x >z &&
804 git diff -w -M --cached |
805 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
806 test_cmp expect actual
810 diff --git a
/empty b
/void
811 similarity index
100%
816 test_expect_success
'rename empty' '
820 git commit -m empty &&
822 git diff -w --cached -M >current &&
823 test_cmp expected current
826 test_expect_success
'combined diff with autocrlf conversion' '
830 git commit -m "one side" x &&
831 git checkout HEAD^ &&
833 git commit -m "the other side" x &&
834 git config core.autocrlf true &&
835 test_must_fail git merge master &&
837 git diff | sed -e "1,/^@@@/d" >actual &&
842 # Start testing the colored format for whitespace checks
844 test_expect_success
'setup diff colors' '
845 git config color.diff.plain normal &&
846 git config color.diff.meta bold &&
847 git config color.diff.frag cyan &&
848 git config color.diff.func normal &&
849 git config color.diff.old red &&
850 git config color.diff.new green &&
851 git config color.diff.commit yellow &&
852 git config color.diff.whitespace blue &&
854 git config core.autocrlf false
857 test_expect_success
'diff that introduces a line with only tabs' '
858 git config core.whitespace blank-at-eol &&
861 git commit -m "initial" x &&
862 echo "{NTN}" | tr "NT" "\n\t" >>x &&
863 git diff --color | test_decode_color >current &&
865 cat >expected <<-\EOF &&
866 <BOLD>diff --git a/x b/x<RESET>
867 <BOLD>index 9daeafb..2874b91 100644<RESET>
870 <CYAN>@@ -1 +1,4 @@<RESET>
872 <GREEN>+<RESET><GREEN>{<RESET>
873 <GREEN>+<RESET><BLUE> <RESET>
874 <GREEN>+<RESET><GREEN>}<RESET>
877 test_cmp expected current
880 test_expect_success
'diff that introduces and removes ws breakages' '
883 echo "0. blank-at-eol " &&
884 echo "1. blank-at-eol "
886 git commit -a --allow-empty -m preimage &&
888 echo "0. blank-at-eol " &&
889 echo "1. still-blank-at-eol " &&
890 echo "2. and a new line "
894 test_decode_color >current &&
896 cat >expected <<-\EOF &&
897 <BOLD>diff --git a/x b/x<RESET>
898 <BOLD>index d0233a2..700886e 100644<RESET>
901 <CYAN>@@ -1,2 +1,3 @@<RESET>
902 0. blank-at-eol <RESET>
903 <RED>-1. blank-at-eol <RESET>
904 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
905 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
908 test_cmp expected current
911 test_expect_success
'ws-error-highlight test setup' '
915 echo "0. blank-at-eol " &&
916 echo "1. blank-at-eol "
918 git commit -a --allow-empty -m preimage &&
920 echo "0. blank-at-eol " &&
921 echo "1. still-blank-at-eol " &&
922 echo "2. and a new line "
925 cat >expect.default-old <<-\EOF &&
926 <BOLD>diff --git a/x b/x<RESET>
927 <BOLD>index d0233a2..700886e 100644<RESET>
930 <CYAN>@@ -1,2 +1,3 @@<RESET>
931 0. blank-at-eol <RESET>
932 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
933 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
934 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
937 cat >expect.all <<-\EOF &&
938 <BOLD>diff --git a/x b/x<RESET>
939 <BOLD>index d0233a2..700886e 100644<RESET>
942 <CYAN>@@ -1,2 +1,3 @@<RESET>
943 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
944 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
945 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
946 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
949 cat >expect.none <<-\EOF
950 <BOLD>diff --git a/x b/x<RESET>
951 <BOLD>index d0233a2..700886e 100644<RESET>
954 <CYAN>@@ -1,2 +1,3 @@<RESET>
955 0. blank-at-eol <RESET>
956 <RED>-1. blank-at-eol <RESET>
957 <GREEN>+1. still-blank-at-eol <RESET>
958 <GREEN>+2. and a new line <RESET>
963 test_expect_success
'test --ws-error-highlight option' '
965 git diff --color --ws-error-highlight=default,old |
966 test_decode_color >current &&
967 test_cmp expect.default-old current &&
969 git diff --color --ws-error-highlight=all |
970 test_decode_color >current &&
971 test_cmp expect.all current &&
973 git diff --color --ws-error-highlight=none |
974 test_decode_color >current &&
975 test_cmp expect.none current
979 test_expect_success
'test diff.wsErrorHighlight config' '
981 git -c diff.wsErrorHighlight=default,old diff --color |
982 test_decode_color >current &&
983 test_cmp expect.default-old current &&
985 git -c diff.wsErrorHighlight=all diff --color |
986 test_decode_color >current &&
987 test_cmp expect.all current &&
989 git -c diff.wsErrorHighlight=none diff --color |
990 test_decode_color >current &&
991 test_cmp expect.none current
995 test_expect_success
'option overrides diff.wsErrorHighlight' '
997 git -c diff.wsErrorHighlight=none \
998 diff --color --ws-error-highlight=default,old |
999 test_decode_color >current &&
1000 test_cmp expect.default-old current &&
1002 git -c diff.wsErrorHighlight=default \
1003 diff --color --ws-error-highlight=all |
1004 test_decode_color >current &&
1005 test_cmp expect.all current &&
1007 git -c diff.wsErrorHighlight=all \
1008 diff --color --ws-error-highlight=none |
1009 test_decode_color >current &&
1010 test_cmp expect.none current
1014 test_expect_success
'detect moved code, complete file' '
1016 cat <<-\EOF >test.c &&
1020 printf("Hello World");
1024 git commit -m "add main function" &&
1025 git mv test.c main.c &&
1026 test_config color.diff.oldMoved "normal red" &&
1027 test_config color.diff.newMoved "normal green" &&
1028 git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1029 cat >expected <<-\EOF &&
1030 <BOLD>diff --git a/main.c b/main.c<RESET>
1031 <BOLD>new file mode 100644<RESET>
1032 <BOLD>index 0000000..a986c57<RESET>
1033 <BOLD>--- /dev/null<RESET>
1034 <BOLD>+++ b/main.c<RESET>
1035 <CYAN>@@ -0,0 +1,5 @@<RESET>
1036 <BGREEN>+<RESET><BGREEN>#include<stdio.h><RESET>
1037 <BGREEN>+<RESET><BGREEN>main()<RESET>
1038 <BGREEN>+<RESET><BGREEN>{<RESET>
1039 <BGREEN>+<RESET><BGREEN>printf("Hello World");<RESET>
1040 <BGREEN>+<RESET><BGREEN>}<RESET>
1041 <BOLD>diff --git a/test.c b/test.c<RESET>
1042 <BOLD>deleted file mode 100644<RESET>
1043 <BOLD>index a986c57..0000000<RESET>
1044 <BOLD>--- a/test.c<RESET>
1045 <BOLD>+++ /dev/null<RESET>
1046 <CYAN>@@ -1,5 +0,0 @@<RESET>
1047 <BRED>-#include<stdio.h><RESET>
1048 <BRED>-main()<RESET>
1050 <BRED>-printf("Hello World");<RESET>
1054 test_cmp expected actual
1057 test_expect_success
'detect malicious moved code, inside file' '
1058 test_config color.diff.oldMoved "normal red" &&
1059 test_config color.diff.newMoved "normal green" &&
1060 test_config color.diff.oldMovedAlternative "blue" &&
1061 test_config color.diff.newMovedAlternative "yellow" &&
1063 cat <<-\EOF >main.c &&
1071 int secure_foo(struct user *u)
1073 if (!u->is_allowed_foo)
1083 cat <<-\EOF >test.c &&
1087 printf("Hello World, but different\n");
1090 int another_function()
1095 git add main.c test.c &&
1096 git commit -m "add main and test file" &&
1097 cat <<-\EOF >main.c &&
1110 cat <<-\EOF >test.c &&
1114 printf("Hello World, but different\n");
1117 int secure_foo(struct user *u)
1120 if (!u->is_allowed_foo)
1124 int another_function()
1129 git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1130 cat <<-\EOF >expected &&
1131 <BOLD>diff --git a/main.c b/main.c<RESET>
1132 <BOLD>index 27a619c..7cf9336 100644<RESET>
1133 <BOLD>--- a/main.c<RESET>
1134 <BOLD>+++ b/main.c<RESET>
1135 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1136 printf("World\n");<RESET>
1139 <BRED>-int secure_foo(struct user *u)<RESET>
1141 <BLUE>-if (!u->is_allowed_foo)<RESET>
1142 <BLUE>-return;<RESET>
1143 <RED>-foo(u);<RESET>
1149 <BOLD>diff --git a/test.c b/test.c<RESET>
1150 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1151 <BOLD>--- a/test.c<RESET>
1152 <BOLD>+++ b/test.c<RESET>
1153 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1154 printf("Hello World, but different\n");<RESET>
1157 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1158 <BGREEN>+<RESET><BGREEN>{<RESET>
1159 <GREEN>+<RESET><GREEN>foo(u);<RESET>
1160 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1161 <BGREEN>+<RESET><BGREEN>return;<RESET>
1162 <GREEN>+<RESET><GREEN>}<RESET>
1164 int another_function()<RESET>
1169 test_cmp expected actual
1172 test_expect_success
'plain moved code, inside file' '
1173 test_config color.diff.oldMoved "normal red" &&
1174 test_config color.diff.newMoved "normal green" &&
1175 test_config color.diff.oldMovedAlternative "blue" &&
1176 test_config color.diff.newMovedAlternative "yellow" &&
1177 # needs previous test as setup
1178 git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1179 cat <<-\EOF >expected &&
1180 <BOLD>diff --git a/main.c b/main.c<RESET>
1181 <BOLD>index 27a619c..7cf9336 100644<RESET>
1182 <BOLD>--- a/main.c<RESET>
1183 <BOLD>+++ b/main.c<RESET>
1184 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1185 printf("World\n");<RESET>
1188 <BRED>-int secure_foo(struct user *u)<RESET>
1190 <BRED>-if (!u->is_allowed_foo)<RESET>
1191 <BRED>-return;<RESET>
1192 <BRED>-foo(u);<RESET>
1198 <BOLD>diff --git a/test.c b/test.c<RESET>
1199 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1200 <BOLD>--- a/test.c<RESET>
1201 <BOLD>+++ b/test.c<RESET>
1202 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1203 printf("Hello World, but different\n");<RESET>
1206 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1207 <BGREEN>+<RESET><BGREEN>{<RESET>
1208 <BGREEN>+<RESET><BGREEN>foo(u);<RESET>
1209 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1210 <BGREEN>+<RESET><BGREEN>return;<RESET>
1211 <BGREEN>+<RESET><BGREEN>}<RESET>
1213 int another_function()<RESET>
1218 test_cmp expected actual
1221 test_expect_success
'detect blocks of moved code' '
1223 cat <<-\EOF >lines.txt &&
1241 git add lines.txt &&
1242 git commit -m "add poetry" &&
1243 cat <<-\EOF >lines.txt &&
1261 test_config color.diff.oldMoved "magenta" &&
1262 test_config color.diff.newMoved "cyan" &&
1263 test_config color.diff.oldMovedAlternative "blue" &&
1264 test_config color.diff.newMovedAlternative "yellow" &&
1265 test_config color.diff.oldMovedDimmed "normal magenta" &&
1266 test_config color.diff.newMovedDimmed "normal cyan" &&
1267 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1268 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1269 git diff HEAD --no-renames --color-moved=blocks --color >actual.raw &&
1270 grep -v "index" actual.raw | test_decode_color >actual &&
1271 cat <<-\EOF >expected &&
1272 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1273 <BOLD>--- a/lines.txt<RESET>
1274 <BOLD>+++ b/lines.txt<RESET>
1275 <CYAN>@@ -1,16 +1,16 @@<RESET>
1276 <MAGENTA>-long line 1<RESET>
1277 <MAGENTA>-long line 2<RESET>
1278 <MAGENTA>-long line 3<RESET>
1285 <CYAN>+<RESET><CYAN>long line 1<RESET>
1286 <CYAN>+<RESET><CYAN>long line 2<RESET>
1287 <CYAN>+<RESET><CYAN>long line 3<RESET>
1288 <CYAN>+<RESET><CYAN>long line 14<RESET>
1289 <CYAN>+<RESET><CYAN>long line 15<RESET>
1290 <CYAN>+<RESET><CYAN>long line 16<RESET>
1295 <MAGENTA>-long line 14<RESET>
1296 <MAGENTA>-long line 15<RESET>
1297 <MAGENTA>-long line 16<RESET>
1299 test_cmp expected actual
1303 test_expect_success
'detect permutations inside moved code -- dimmed-zebra' '
1304 # reuse setup from test before!
1305 test_config color.diff.oldMoved "magenta" &&
1306 test_config color.diff.newMoved "cyan" &&
1307 test_config color.diff.oldMovedAlternative "blue" &&
1308 test_config color.diff.newMovedAlternative "yellow" &&
1309 test_config color.diff.oldMovedDimmed "normal magenta" &&
1310 test_config color.diff.newMovedDimmed "normal cyan" &&
1311 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1312 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1313 git diff HEAD --no-renames --color-moved=dimmed-zebra --color >actual.raw &&
1314 grep -v "index" actual.raw | test_decode_color >actual &&
1315 cat <<-\EOF >expected &&
1316 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1317 <BOLD>--- a/lines.txt<RESET>
1318 <BOLD>+++ b/lines.txt<RESET>
1319 <CYAN>@@ -1,16 +1,16 @@<RESET>
1320 <BMAGENTA>-long line 1<RESET>
1321 <BMAGENTA>-long line 2<RESET>
1322 <BMAGENTA>-long line 3<RESET>
1329 <BCYAN>+<RESET><BCYAN>long line 1<RESET>
1330 <BCYAN>+<RESET><BCYAN>long line 2<RESET>
1331 <CYAN>+<RESET><CYAN>long line 3<RESET>
1332 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1333 <BYELLOW>+<RESET><BYELLOW>long line 15<RESET>
1334 <BYELLOW>+<RESET><BYELLOW>long line 16<RESET>
1339 <BMAGENTA>-long line 14<RESET>
1340 <BMAGENTA>-long line 15<RESET>
1341 <BMAGENTA>-long line 16<RESET>
1343 test_cmp expected actual
1346 test_expect_success
'cmd option assumes configured colored-moved' '
1347 test_config color.diff.oldMoved "magenta" &&
1348 test_config color.diff.newMoved "cyan" &&
1349 test_config color.diff.oldMovedAlternative "blue" &&
1350 test_config color.diff.newMovedAlternative "yellow" &&
1351 test_config color.diff.oldMovedDimmed "normal magenta" &&
1352 test_config color.diff.newMovedDimmed "normal cyan" &&
1353 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1354 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1355 test_config diff.colorMoved zebra &&
1356 git diff HEAD --no-renames --color-moved --color >actual.raw &&
1357 grep -v "index" actual.raw | test_decode_color >actual &&
1358 cat <<-\EOF >expected &&
1359 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1360 <BOLD>--- a/lines.txt<RESET>
1361 <BOLD>+++ b/lines.txt<RESET>
1362 <CYAN>@@ -1,16 +1,16 @@<RESET>
1363 <MAGENTA>-long line 1<RESET>
1364 <MAGENTA>-long line 2<RESET>
1365 <MAGENTA>-long line 3<RESET>
1372 <CYAN>+<RESET><CYAN>long line 1<RESET>
1373 <CYAN>+<RESET><CYAN>long line 2<RESET>
1374 <CYAN>+<RESET><CYAN>long line 3<RESET>
1375 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1376 <YELLOW>+<RESET><YELLOW>long line 15<RESET>
1377 <YELLOW>+<RESET><YELLOW>long line 16<RESET>
1382 <MAGENTA>-long line 14<RESET>
1383 <MAGENTA>-long line 15<RESET>
1384 <MAGENTA>-long line 16<RESET>
1386 test_cmp expected actual
1389 test_expect_success
'no effect from --color-moved with --word-diff' '
1390 cat <<-\EOF >text.txt &&
1391 Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1394 git commit -a -m "clean state" &&
1395 cat <<-\EOF >text.txt &&
1396 simply Lorem Ipsum dummy is text of the typesetting and printing industry.
1398 git diff --color-moved --word-diff >actual &&
1399 git diff --word-diff >expect &&
1400 test_cmp expect actual
1403 test_expect_success
'set up whitespace tests' '
1405 # Note that these lines have no leading or trailing whitespace.
1406 cat <<-\EOF >lines.txt &&
1417 git add lines.txt &&
1418 git commit -m "add poetry" &&
1419 git config color.diff.oldMoved "magenta" &&
1420 git config color.diff.newMoved "cyan"
1423 test_expect_success
'move detection ignoring whitespace ' '
1424 q_to_tab <<-\EOF >lines.txt &&
1428 Qchanged long line 9
1435 git diff HEAD --no-renames --color-moved --color >actual.raw &&
1436 grep -v "index" actual.raw | test_decode_color >actual &&
1437 cat <<-\EOF >expected &&
1438 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1439 <BOLD>--- a/lines.txt<RESET>
1440 <BOLD>+++ b/lines.txt<RESET>
1441 <CYAN>@@ -1,9 +1,9 @@<RESET>
1442 <GREEN>+<RESET> <GREEN>long line 6<RESET>
1443 <GREEN>+<RESET> <GREEN>long line 7<RESET>
1444 <GREEN>+<RESET> <GREEN>long line 8<RESET>
1445 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1451 <RED>-long line 6<RESET>
1452 <RED>-long line 7<RESET>
1453 <RED>-long line 8<RESET>
1454 <RED>-long line 9<RESET>
1456 test_cmp expected actual &&
1458 git diff HEAD --no-renames --color-moved --color \
1459 --color-moved-ws=ignore-all-space >actual.raw &&
1460 grep -v "index" actual.raw | test_decode_color >actual &&
1461 cat <<-\EOF >expected &&
1462 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1463 <BOLD>--- a/lines.txt<RESET>
1464 <BOLD>+++ b/lines.txt<RESET>
1465 <CYAN>@@ -1,9 +1,9 @@<RESET>
1466 <CYAN>+<RESET> <CYAN>long line 6<RESET>
1467 <CYAN>+<RESET> <CYAN>long line 7<RESET>
1468 <CYAN>+<RESET> <CYAN>long line 8<RESET>
1469 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1475 <MAGENTA>-long line 6<RESET>
1476 <MAGENTA>-long line 7<RESET>
1477 <MAGENTA>-long line 8<RESET>
1478 <RED>-long line 9<RESET>
1480 test_cmp expected actual
1483 test_expect_success
'move detection ignoring whitespace changes' '
1485 # Lines 6-8 have a space change, but 9 is new whitespace
1486 q_to_tab <<-\EOF >lines.txt &&
1498 git diff HEAD --no-renames --color-moved --color >actual.raw &&
1499 grep -v "index" actual.raw | test_decode_color >actual &&
1500 cat <<-\EOF >expected &&
1501 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1502 <BOLD>--- a/lines.txt<RESET>
1503 <BOLD>+++ b/lines.txt<RESET>
1504 <CYAN>@@ -1,9 +1,9 @@<RESET>
1505 <GREEN>+<RESET><GREEN>long line 6<RESET>
1506 <GREEN>+<RESET><GREEN>long line 7<RESET>
1507 <GREEN>+<RESET><GREEN>long line 8<RESET>
1508 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1514 <RED>-long line 6<RESET>
1515 <RED>-long line 7<RESET>
1516 <RED>-long line 8<RESET>
1517 <RED>-long line 9<RESET>
1519 test_cmp expected actual &&
1521 git diff HEAD --no-renames --color-moved --color \
1522 --color-moved-ws=ignore-space-change >actual.raw &&
1523 grep -v "index" actual.raw | test_decode_color >actual &&
1524 cat <<-\EOF >expected &&
1525 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1526 <BOLD>--- a/lines.txt<RESET>
1527 <BOLD>+++ b/lines.txt<RESET>
1528 <CYAN>@@ -1,9 +1,9 @@<RESET>
1529 <CYAN>+<RESET><CYAN>long line 6<RESET>
1530 <CYAN>+<RESET><CYAN>long line 7<RESET>
1531 <CYAN>+<RESET><CYAN>long line 8<RESET>
1532 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1538 <MAGENTA>-long line 6<RESET>
1539 <MAGENTA>-long line 7<RESET>
1540 <MAGENTA>-long line 8<RESET>
1541 <RED>-long line 9<RESET>
1543 test_cmp expected actual
1546 test_expect_success
'move detection ignoring whitespace at eol' '
1548 # Lines 6-9 have new eol whitespace, but 9 also has it in the middle
1549 q_to_tab <<-\EOF >lines.txt &&
1561 # avoid cluttering the output with complaints about our eol whitespace
1562 test_config core.whitespace -blank-at-eol &&
1564 git diff HEAD --no-renames --color-moved --color >actual.raw &&
1565 grep -v "index" actual.raw | test_decode_color >actual &&
1566 cat <<-\EOF >expected &&
1567 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1568 <BOLD>--- a/lines.txt<RESET>
1569 <BOLD>+++ b/lines.txt<RESET>
1570 <CYAN>@@ -1,9 +1,9 @@<RESET>
1571 <GREEN>+<RESET><GREEN>long line 6 <RESET>
1572 <GREEN>+<RESET><GREEN>long line 7 <RESET>
1573 <GREEN>+<RESET><GREEN>long line 8 <RESET>
1574 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1580 <RED>-long line 6<RESET>
1581 <RED>-long line 7<RESET>
1582 <RED>-long line 8<RESET>
1583 <RED>-long line 9<RESET>
1585 test_cmp expected actual &&
1587 git diff HEAD --no-renames --color-moved --color \
1588 --color-moved-ws=ignore-space-at-eol >actual.raw &&
1589 grep -v "index" actual.raw | test_decode_color >actual &&
1590 cat <<-\EOF >expected &&
1591 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1592 <BOLD>--- a/lines.txt<RESET>
1593 <BOLD>+++ b/lines.txt<RESET>
1594 <CYAN>@@ -1,9 +1,9 @@<RESET>
1595 <CYAN>+<RESET><CYAN>long line 6 <RESET>
1596 <CYAN>+<RESET><CYAN>long line 7 <RESET>
1597 <CYAN>+<RESET><CYAN>long line 8 <RESET>
1598 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1604 <MAGENTA>-long line 6<RESET>
1605 <MAGENTA>-long line 7<RESET>
1606 <MAGENTA>-long line 8<RESET>
1607 <RED>-long line 9<RESET>
1609 test_cmp expected actual
1612 test_expect_success
'clean up whitespace-test colors' '
1613 git config --unset color.diff.oldMoved &&
1614 git config --unset color.diff.newMoved
1617 test_expect_success
'--color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1634 git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1635 grep -v "index" actual.raw | test_decode_color >actual &&
1636 cat >expected <<-\EOF &&
1637 <BOLD>diff --git a/bar b/bar<RESET>
1638 <BOLD>--- a/bar<RESET>
1639 <BOLD>+++ b/bar<RESET>
1640 <CYAN>@@ -0,0 +1 @@<RESET>
1641 <GREEN>+<RESET><GREEN>line1<RESET>
1642 <BOLD>diff --git a/foo b/foo<RESET>
1643 <BOLD>--- a/foo<RESET>
1644 <BOLD>+++ b/foo<RESET>
1645 <CYAN>@@ -1,2 +1 @@<RESET>
1646 irrelevant_line<RESET>
1650 test_cmp expected actual
1653 test_expect_success
'--color-moved respects MIN_ALNUM_COUNT' '
1656 nineteen chars 456789
1658 twenty chars 234567890
1668 twenty chars 234567890
1669 nineteen chars 456789
1672 git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1673 grep -v "index" actual.raw | test_decode_color >actual &&
1674 cat >expected <<-\EOF &&
1675 <BOLD>diff --git a/bar b/bar<RESET>
1676 <BOLD>--- a/bar<RESET>
1677 <BOLD>+++ b/bar<RESET>
1678 <CYAN>@@ -0,0 +1,2 @@<RESET>
1679 <BOLD;CYAN>+<RESET><BOLD;CYAN>twenty chars 234567890<RESET>
1680 <GREEN>+<RESET><GREEN>nineteen chars 456789<RESET>
1681 <BOLD>diff --git a/foo b/foo<RESET>
1682 <BOLD>--- a/foo<RESET>
1683 <BOLD>+++ b/foo<RESET>
1684 <CYAN>@@ -1,3 +1 @@<RESET>
1685 <RED>-nineteen chars 456789<RESET>
1686 irrelevant_line<RESET>
1687 <BOLD;MAGENTA>-twenty chars 234567890<RESET>
1690 test_cmp expected actual
1693 test_expect_success
'--color-moved treats adjacent blocks as separate for MIN_ALNUM_COUNT' '
1714 git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1715 grep -v "index" actual.raw | test_decode_color >actual &&
1716 cat >expected <<-\EOF &&
1717 <BOLD>diff --git a/bar b/bar<RESET>
1718 <BOLD>--- a/bar<RESET>
1719 <BOLD>+++ b/bar<RESET>
1720 <CYAN>@@ -0,0 +1,3 @@<RESET>
1721 <GREEN>+<RESET><GREEN>7charsB<RESET>
1722 <GREEN>+<RESET><GREEN>7charsC<RESET>
1723 <GREEN>+<RESET><GREEN>7charsA<RESET>
1724 <BOLD>diff --git a/foo b/foo<RESET>
1725 <BOLD>--- a/foo<RESET>
1726 <BOLD>+++ b/foo<RESET>
1727 <CYAN>@@ -1,4 +1 @@<RESET>
1728 <RED>-7charsA<RESET>
1729 irrelevant_line<RESET>
1730 <RED>-7charsB<RESET>
1731 <RED>-7charsC<RESET>
1734 test_cmp expected actual
1737 test_expect_success
'move detection with submodules' '
1738 test_create_repo bananas &&
1739 echo ripe >bananas/recipe &&
1740 git -C bananas add recipe &&
1741 test_commit fruit &&
1742 test_commit -C bananas recipe &&
1743 git submodule add ./bananas &&
1745 git commit -a -m "bananas are like a heavy library?" &&
1746 echo foul >bananas/recipe &&
1747 echo ripe >fruit.t &&
1749 git diff --submodule=diff --color-moved --color >actual &&
1751 # no move detection as the moved line is across repository boundaries.
1752 test_decode_color <actual >decoded_actual &&
1753 ! grep BGREEN decoded_actual &&
1754 ! grep BRED decoded_actual &&
1756 # nor did we mess with it another way
1757 git diff --submodule=diff --color | test_decode_color >expect &&
1758 test_cmp expect decoded_actual &&
1760 git submodule deinit bananas
1763 test_expect_success
'only move detection ignores white spaces' '
1765 q_to_tab <<-\EOF >text.txt &&
1766 a long line to exceed per-line minimum
1767 another long line to exceed per-line minimum
1771 git commit -m "add text" &&
1772 q_to_tab <<-\EOF >text.txt &&
1773 Qa long line to exceed per-line minimum
1774 Qanother long line to exceed per-line minimum
1778 # Make sure we get a different diff using -w
1779 git diff --color --color-moved -w >actual.raw &&
1780 grep -v "index" actual.raw | test_decode_color >actual &&
1781 q_to_tab <<-\EOF >expected &&
1782 <BOLD>diff --git a/text.txt b/text.txt<RESET>
1783 <BOLD>--- a/text.txt<RESET>
1784 <BOLD>+++ b/text.txt<RESET>
1785 <CYAN>@@ -1,3 +1,3 @@<RESET>
1786 Qa long line to exceed per-line minimum<RESET>
1787 Qanother long line to exceed per-line minimum<RESET>
1788 <RED>-original file<RESET>
1789 <GREEN>+<RESET><GREEN>new file<RESET>
1791 test_cmp expected actual &&
1793 # And now ignoring white space only in the move detection
1794 git diff --color --color-moved \
1795 --color-moved-ws=ignore-all-space,ignore-space-change,ignore-space-at-eol >actual.raw &&
1796 grep -v "index" actual.raw | test_decode_color >actual &&
1797 q_to_tab <<-\EOF >expected &&
1798 <BOLD>diff --git a/text.txt b/text.txt<RESET>
1799 <BOLD>--- a/text.txt<RESET>
1800 <BOLD>+++ b/text.txt<RESET>
1801 <CYAN>@@ -1,3 +1,3 @@<RESET>
1802 <BOLD;MAGENTA>-a long line to exceed per-line minimum<RESET>
1803 <BOLD;MAGENTA>-another long line to exceed per-line minimum<RESET>
1804 <RED>-original file<RESET>
1805 <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>a long line to exceed per-line minimum<RESET>
1806 <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>another long line to exceed per-line minimum<RESET>
1807 <GREEN>+<RESET><GREEN>new file<RESET>
1809 test_cmp expected actual
1812 test_expect_success
'compare whitespace delta across moved blocks' '
1815 q_to_tab <<-\EOF >text.txt &&
1819 QBut! <- this stands out
1821 QQdifferent starting
1827 QQQthat has similar lines
1828 QQQto previous blocks, but with different indent
1829 QQQYetQAnotherQoutlierQ
1830 QLine with internal w h i t e s p a c e change
1834 git commit -m "add text.txt" &&
1836 q_to_tab <<-\EOF >text.txt &&
1840 QQQBut! <- this stands out
1848 QQthat has similar lines
1849 QQto previous blocks, but with different indent
1850 QQYetQAnotherQoutlier
1851 QLine with internal whitespace change
1854 git diff --color --color-moved --color-moved-ws=allow-indentation-change >actual.raw &&
1855 grep -v "index" actual.raw | test_decode_color >actual &&
1857 q_to_tab <<-\EOF >expected &&
1858 <BOLD>diff --git a/text.txt b/text.txt<RESET>
1859 <BOLD>--- a/text.txt<RESET>
1860 <BOLD>+++ b/text.txt<RESET>
1861 <CYAN>@@ -1,15 +1,15 @@<RESET>
1862 <BOLD;MAGENTA>-QIndented<RESET>
1863 <BOLD;MAGENTA>-QText across<RESET>
1864 <BOLD;MAGENTA>-Qsome lines<RESET>
1865 <RED>-QBut! <- this stands out<RESET>
1866 <BOLD;MAGENTA>-QAdjusting with<RESET>
1867 <BOLD;MAGENTA>-QQdifferent starting<RESET>
1868 <BOLD;MAGENTA>-Qwhite spaces<RESET>
1869 <RED>-QAnother outlier<RESET>
1870 <BOLD;MAGENTA>-QQQIndented<RESET>
1871 <BOLD;MAGENTA>-QQQText across<RESET>
1872 <BOLD;MAGENTA>-QQQfive lines<RESET>
1873 <BOLD;MAGENTA>-QQQthat has similar lines<RESET>
1874 <BOLD;MAGENTA>-QQQto previous blocks, but with different indent<RESET>
1875 <RED>-QQQYetQAnotherQoutlierQ<RESET>
1876 <RED>-QLine with internal w h i t e s p a c e change<RESET>
1877 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
1878 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
1879 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>some lines<RESET>
1880 <GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
1881 <BOLD;CYAN>+<RESET><BOLD;CYAN>Adjusting with<RESET>
1882 <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>different starting<RESET>
1883 <BOLD;CYAN>+<RESET><BOLD;CYAN>white spaces<RESET>
1884 <GREEN>+<RESET><GREEN>AnotherQoutlier<RESET>
1885 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
1886 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
1887 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>five lines<RESET>
1888 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>that has similar lines<RESET>
1889 <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>to previous blocks, but with different indent<RESET>
1890 <GREEN>+<RESET>QQ<GREEN>YetQAnotherQoutlier<RESET>
1891 <GREEN>+<RESET>Q<GREEN>Line with internal whitespace change<RESET>
1894 test_cmp expected actual
1897 test_expect_success
'bogus settings in move detection erroring out' '
1898 test_must_fail git diff --color-moved=bogus 2>err &&
1899 test_i18ngrep "must be one of" err &&
1900 test_i18ngrep bogus err &&
1902 test_must_fail git -c diff.colormoved=bogus diff 2>err &&
1903 test_i18ngrep "must be one of" err &&
1904 test_i18ngrep "from command-line config" err &&
1906 test_must_fail git diff --color-moved-ws=bogus 2>err &&
1907 test_i18ngrep "possible values" err &&
1908 test_i18ngrep bogus err &&
1910 test_must_fail git -c diff.colormovedws=bogus diff 2>err &&
1911 test_i18ngrep "possible values" err &&
1912 test_i18ngrep "from command-line config" err
1915 test_expect_success
'compare whitespace delta incompatible with other space options' '
1916 test_must_fail git diff \
1917 --color-moved-ws=allow-indentation-change,ignore-all-space \
1919 test_i18ngrep allow-indentation-change err
1923 test_expect_success
'compare mixed whitespace delta across moved blocks' '
1926 tr Q_ "\t " <<-EOF >text.txt &&
1928 ____too short without
1930 ___being grouped across blank line
1936 ____Indented text to
1937 _Q____be further indented by four spaces across
1939 QQ____These two lines have had their
1940 ____indentation reduced by four spaces
1941 Qdifferent indentation change
1946 git commit -m "add text.txt" &&
1948 tr Q_ "\t " <<-EOF >text.txt &&
1954 QQbe further indented by four spaces across
1959 Q_______being grouped across blank line
1961 Q_QThese two lines have had their
1962 indentation reduced by four spaces
1963 QQdifferent indentation change
1967 git -c color.diff.whitespace="normal red" \
1968 -c core.whitespace=space-before-tab \
1969 diff --color --color-moved --ws-error-highlight=all \
1970 --color-moved-ws=allow-indentation-change >actual.raw &&
1971 grep -v "index" actual.raw | test_decode_color >actual &&
1973 cat <<-\EOF >expected &&
1974 <BOLD>diff --git a/text.txt b/text.txt<RESET>
1975 <BOLD>--- a/text.txt<RESET>
1976 <BOLD>+++ b/text.txt<RESET>
1977 <CYAN>@@ -1,16 +1,16 @@<RESET>
1978 <BOLD;MAGENTA>-<RESET>
1979 <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> too short without<RESET>
1980 <BOLD;MAGENTA>-<RESET>
1981 <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> being grouped across blank line<RESET>
1982 <BOLD;MAGENTA>-<RESET>
1983 <RESET>context<RESET>
1986 <RESET>anchor<RESET>
1987 <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> Indented text to<RESET>
1988 <BOLD;MAGENTA>-<RESET><BRED> <RESET> <BOLD;MAGENTA> be further indented by four spaces across<RESET>
1989 <BOLD;MAGENTA>-<RESET><BRED> <RESET> <BOLD;MAGENTA>several lines<RESET>
1990 <BOLD;BLUE>-<RESET> <BOLD;BLUE> These two lines have had their<RESET>
1991 <BOLD;BLUE>-<RESET><BOLD;BLUE> indentation reduced by four spaces<RESET>
1992 <BOLD;MAGENTA>-<RESET> <BOLD;MAGENTA>different indentation change<RESET>
1993 <RED>-<RESET><RED> too short<RESET>
1994 <BOLD;CYAN>+<RESET> <BOLD;CYAN>Indented text to<RESET>
1995 <BOLD;CYAN>+<RESET> <BOLD;CYAN>be further indented by four spaces across<RESET>
1996 <BOLD;CYAN>+<RESET> <BOLD;CYAN> several lines<RESET>
1997 <BOLD;YELLOW>+<RESET>
1998 <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>too short without<RESET>
1999 <BOLD;YELLOW>+<RESET>
2000 <BOLD;YELLOW>+<RESET> <BOLD;YELLOW> being grouped across blank line<RESET>
2001 <BOLD;YELLOW>+<RESET>
2002 <BOLD;CYAN>+<RESET> <BRED> <RESET> <BOLD;CYAN>These two lines have had their<RESET>
2003 <BOLD;CYAN>+<RESET><BOLD;CYAN>indentation reduced by four spaces<RESET>
2004 <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>different indentation change<RESET>
2005 <GREEN>+<RESET><BRED> <RESET> <GREEN>too short<RESET>
2008 test_cmp expected actual
2011 # Note that the "6" in the expected hunk header below is funny, since we only
2012 # show 5 lines (the missing one was blank and thus ignored). This is how
2013 # --ignore-blank-lines behaves even without --function-context, and this test
2014 # is just checking the interaction of the two features. Don't take it as an
2015 # endorsement of that output.
2016 test_expect_success
'combine --ignore-blank-lines with --function-context' '
2017 test_write_lines 1 "" 2 3 4 5 >a &&
2018 test_write_lines 1 2 3 4 >b &&
2019 test_must_fail git diff --no-index \
2020 --ignore-blank-lines --function-context a b >actual.raw &&
2021 sed -n "/@@/,\$p" <actual.raw >actual &&
2022 cat <<-\EOF >expect &&
2030 test_cmp expect actual