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 &&
98 test_cmp expect out &&
100 git diff -w -b >out &&
101 test_cmp expect out &&
103 git diff -w --ignore-space-at-eol >out &&
104 test_cmp expect out &&
106 git diff -w -b --ignore-space-at-eol >out &&
107 test_cmp expect out &&
109 git diff -w --ignore-cr-at-eol >out &&
110 test_cmp expect out &&
112 tr "Q_" "\015 " <<-\EOF >expect &&
114 index d99af23..22d9f73 100644
118 -whitespace at beginning
119 +_ whitespace at beginning
121 -whitespace in the middle
122 +white space in the middle
128 test_cmp expect out &&
130 git diff -b --ignore-space-at-eol >out &&
131 test_cmp expect out &&
133 git diff -b --ignore-cr-at-eol >out &&
134 test_cmp expect out &&
136 tr "Q_" "\015 " <<-\EOF >expect &&
138 index d99af23..22d9f73 100644
142 -whitespace at beginning
144 -whitespace in the middle
145 +_ whitespace at beginning
147 +white space in the middle
152 git diff --ignore-space-at-eol >out &&
153 test_cmp expect out &&
155 git diff --ignore-space-at-eol --ignore-cr-at-eol >out &&
156 test_cmp expect out &&
158 tr "Q_" "\015 " <<-\EOF >expect &&
160 index_d99af23..22d9f73 100644
164 -whitespace at beginning
166 -whitespace in the middle
168 +_ whitespace at beginning
170 +white space in the middle
175 git diff --ignore-cr-at-eol >out &&
179 test_expect_success
'ignore-blank-lines: only new lines' '
181 git update-index x &&
182 test_seq 5 | sed "/3/i\\
184 git diff --ignore-blank-lines >out &&
189 test_expect_success
'ignore-blank-lines: only new lines with space' '
191 git update-index x &&
192 test_seq 5 | sed "/3/i\\
194 git diff -w --ignore-blank-lines >out &&
199 test_expect_success
'ignore-blank-lines: after change' '
211 git update-index x &&
224 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
225 cat <<-\EOF >expected &&
239 compare_diff_patch expected out.tmp
242 test_expect_success
'ignore-blank-lines: before change' '
253 git update-index x &&
266 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
267 cat <<-\EOF >expected &&
280 compare_diff_patch expected out.tmp
283 test_expect_success
'ignore-blank-lines: between changes' '
298 git update-index x &&
315 git diff --ignore-blank-lines >out.tmp &&
316 cat <<-\EOF >expected &&
337 compare_diff_patch expected out.tmp
340 test_expect_success
'ignore-blank-lines: between changes (with interhunkctx)' '
342 git update-index x &&
360 git diff --inter-hunk-context=2 --ignore-blank-lines >out.tmp &&
361 cat <<-\EOF >expected &&
382 compare_diff_patch expected out.tmp
385 test_expect_success
'ignore-blank-lines: scattered spaces' '
387 git update-index x &&
408 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
409 cat <<-\EOF >expected &&
424 compare_diff_patch expected out.tmp
427 test_expect_success
'ignore-blank-lines: spaces coalesce' '
429 git update-index x &&
443 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
444 cat <<-\EOF >expected &&
461 compare_diff_patch expected out.tmp
464 test_expect_success
'ignore-blank-lines: mix changes and blank lines' '
466 git update-index x &&
492 git diff --ignore-blank-lines >out.tmp &&
493 cat <<-\EOF >expected &&
522 compare_diff_patch expected out.tmp
525 test_expect_success
'check mixed spaces and tabs in indent' '
526 # This is indented with SP HT SP.
528 git diff --check | grep "space before tab in indent"
531 test_expect_success
'check mixed tabs and spaces in indent' '
532 # This is indented with HT SP HT.
534 git diff --check | grep "space before tab in indent"
537 test_expect_success
'check with no whitespace errors' '
538 git commit -m "snapshot" &&
543 test_expect_success
'check with trailing whitespace' '
545 test_must_fail git diff --check
548 test_expect_success
'check with space before tab in indent' '
549 # indent has space followed by hard tab
551 test_must_fail git diff --check
554 test_expect_success
'--check and --exit-code are not exclusive' '
556 git diff --check --exit-code
559 test_expect_success
'--check and --quiet are not exclusive' '
560 git diff --check --quiet
563 test_expect_success
'check staged with no whitespace errors' '
566 git diff --cached --check
569 test_expect_success
'check staged with trailing whitespace' '
572 test_must_fail git diff --cached --check
575 test_expect_success
'check staged with space before tab in indent' '
576 # indent has space followed by hard tab
579 test_must_fail git diff --cached --check
582 test_expect_success
'check with no whitespace errors (diff-index)' '
585 git diff-index --check HEAD
588 test_expect_success
'check with trailing whitespace (diff-index)' '
591 test_must_fail git diff-index --check HEAD
594 test_expect_success
'check with space before tab in indent (diff-index)' '
595 # indent has space followed by hard tab
598 test_must_fail git diff-index --check HEAD
601 test_expect_success
'check staged with no whitespace errors (diff-index)' '
604 git diff-index --cached --check HEAD
607 test_expect_success
'check staged with trailing whitespace (diff-index)' '
610 test_must_fail git diff-index --cached --check HEAD
613 test_expect_success
'check staged with space before tab in indent (diff-index)' '
614 # indent has space followed by hard tab
617 test_must_fail git diff-index --cached --check HEAD
620 test_expect_success
'check with no whitespace errors (diff-tree)' '
622 git commit -m "new commit" x &&
623 git diff-tree --check HEAD^ HEAD
626 test_expect_success
'check with trailing whitespace (diff-tree)' '
628 git commit -m "another commit" x &&
629 test_must_fail git diff-tree --check HEAD^ HEAD
632 test_expect_success
'check with space before tab in indent (diff-tree)' '
633 # indent has space followed by hard tab
635 git commit -m "yet another" x &&
636 test_must_fail git diff-tree --check HEAD^ HEAD
639 test_expect_success
'check trailing whitespace (trailing-space: off)' '
640 git config core.whitespace "-trailing-space" &&
641 echo "foo (); " >x &&
645 test_expect_success
'check trailing whitespace (trailing-space: on)' '
646 git config core.whitespace "trailing-space" &&
647 echo "foo (); " >x &&
648 test_must_fail git diff --check
651 test_expect_success
'check space before tab in indent (space-before-tab: off)' '
652 # indent contains space followed by HT
653 git config core.whitespace "-space-before-tab" &&
654 echo " foo ();" >x &&
658 test_expect_success
'check space before tab in indent (space-before-tab: on)' '
659 # indent contains space followed by HT
660 git config core.whitespace "space-before-tab" &&
661 echo " foo (); " >x &&
662 test_must_fail git diff --check
665 test_expect_success
'check spaces as indentation (indent-with-non-tab: off)' '
666 git config core.whitespace "-indent-with-non-tab" &&
667 echo " foo ();" >x &&
671 test_expect_success
'check spaces as indentation (indent-with-non-tab: on)' '
672 git config core.whitespace "indent-with-non-tab" &&
673 echo " foo ();" >x &&
674 test_must_fail git diff --check
677 test_expect_success
'ditto, but tabwidth=9' '
678 git config core.whitespace "indent-with-non-tab,tabwidth=9" &&
682 test_expect_success
'check tabs and spaces as indentation (indent-with-non-tab: on)' '
683 git config core.whitespace "indent-with-non-tab" &&
684 echo " foo ();" >x &&
685 test_must_fail git diff --check
688 test_expect_success
'ditto, but tabwidth=10' '
689 git config core.whitespace "indent-with-non-tab,tabwidth=10" &&
690 test_must_fail git diff --check
693 test_expect_success
'ditto, but tabwidth=20' '
694 git config core.whitespace "indent-with-non-tab,tabwidth=20" &&
698 test_expect_success
'check tabs as indentation (tab-in-indent: off)' '
699 git config core.whitespace "-tab-in-indent" &&
700 echo " foo ();" >x &&
704 test_expect_success
'check tabs as indentation (tab-in-indent: on)' '
705 git config core.whitespace "tab-in-indent" &&
706 echo " foo ();" >x &&
707 test_must_fail git diff --check
710 test_expect_success
'check tabs and spaces as indentation (tab-in-indent: on)' '
711 git config core.whitespace "tab-in-indent" &&
712 echo " foo ();" >x &&
713 test_must_fail git diff --check
716 test_expect_success
'ditto, but tabwidth=1 (must be irrelevant)' '
717 git config core.whitespace "tab-in-indent,tabwidth=1" &&
718 test_must_fail git diff --check
721 test_expect_success
'check tab-in-indent and indent-with-non-tab conflict' '
722 git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
724 test_must_fail git diff --check
727 test_expect_success
'check tab-in-indent excluded from wildcard whitespace attribute' '
728 git config --unset core.whitespace &&
729 echo "x whitespace" >.gitattributes &&
730 echo " foo ();" >x &&
735 test_expect_success
'line numbers in --check output are correct' '
737 echo "foo(); " >>x &&
738 git diff --check | grep "x:2:"
741 test_expect_success
'checkdiff detects new trailing blank lines (1)' '
744 git diff --check | grep "new blank line"
747 test_expect_success
'checkdiff detects new trailing blank lines (2)' '
748 { echo a; echo b; echo; echo; } >x &&
750 { echo a; echo; echo; echo; echo; } >x &&
751 git diff --check | grep "new blank line"
754 test_expect_success
'checkdiff allows new blank lines' '
758 echo "/* This is new */" &&
767 test_expect_success
'whitespace-only changes not reported' '
769 echo >x "hello world" &&
771 git commit -m "hello 1" &&
772 echo >x "hello world" &&
773 git diff -b >actual &&
774 test_cmp expect actual
779 similarity index NUM%
782 index 380c32a..a97b785 100644
784 test_expect_success
'whitespace-only changes reported across renames' '
786 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
788 git commit -m "base" &&
789 sed -e "5s/^/ /" x >z &&
792 git diff -w -M --cached |
793 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
794 test_cmp expect actual
798 diff --git a
/empty b
/void
799 similarity index
100%
804 test_expect_success
'rename empty' '
808 git commit -m empty &&
810 git diff -w --cached -M >current &&
811 test_cmp expected current
814 test_expect_success
'combined diff with autocrlf conversion' '
818 git commit -m "one side" x &&
819 git checkout HEAD^ &&
821 git commit -m "the other side" x &&
822 git config core.autocrlf true &&
823 test_must_fail git merge master &&
825 git diff | sed -e "1,/^@@@/d" >actual &&
830 # Start testing the colored format for whitespace checks
832 test_expect_success
'setup diff colors' '
833 git config color.diff.plain normal &&
834 git config color.diff.meta bold &&
835 git config color.diff.frag cyan &&
836 git config color.diff.func normal &&
837 git config color.diff.old red &&
838 git config color.diff.new green &&
839 git config color.diff.commit yellow &&
840 git config color.diff.whitespace blue &&
842 git config core.autocrlf false
845 test_expect_success
'diff that introduces a line with only tabs' '
846 git config core.whitespace blank-at-eol &&
849 git commit -m "initial" x &&
850 echo "{NTN}" | tr "NT" "\n\t" >>x &&
851 git diff --color | test_decode_color >current &&
853 cat >expected <<-\EOF &&
854 <BOLD>diff --git a/x b/x<RESET>
855 <BOLD>index 9daeafb..2874b91 100644<RESET>
858 <CYAN>@@ -1 +1,4 @@<RESET>
860 <GREEN>+<RESET><GREEN>{<RESET>
861 <GREEN>+<RESET><BLUE> <RESET>
862 <GREEN>+<RESET><GREEN>}<RESET>
865 test_cmp expected current
868 test_expect_success
'diff that introduces and removes ws breakages' '
871 echo "0. blank-at-eol " &&
872 echo "1. blank-at-eol "
874 git commit -a --allow-empty -m preimage &&
876 echo "0. blank-at-eol " &&
877 echo "1. still-blank-at-eol " &&
878 echo "2. and a new line "
882 test_decode_color >current &&
884 cat >expected <<-\EOF &&
885 <BOLD>diff --git a/x b/x<RESET>
886 <BOLD>index d0233a2..700886e 100644<RESET>
889 <CYAN>@@ -1,2 +1,3 @@<RESET>
890 0. blank-at-eol <RESET>
891 <RED>-1. blank-at-eol <RESET>
892 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
893 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
896 test_cmp expected current
899 test_expect_success
'ws-error-highlight test setup' '
903 echo "0. blank-at-eol " &&
904 echo "1. blank-at-eol "
906 git commit -a --allow-empty -m preimage &&
908 echo "0. blank-at-eol " &&
909 echo "1. still-blank-at-eol " &&
910 echo "2. and a new line "
913 cat >expect.default-old <<-\EOF &&
914 <BOLD>diff --git a/x b/x<RESET>
915 <BOLD>index d0233a2..700886e 100644<RESET>
918 <CYAN>@@ -1,2 +1,3 @@<RESET>
919 0. blank-at-eol <RESET>
920 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
921 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
922 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
925 cat >expect.all <<-\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 <RESET>0. blank-at-eol<RESET><BLUE> <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.none <<-\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 0. blank-at-eol <RESET>
944 <RED>-1. blank-at-eol <RESET>
945 <GREEN>+1. still-blank-at-eol <RESET>
946 <GREEN>+2. and a new line <RESET>
951 test_expect_success
'test --ws-error-highlight option' '
953 git diff --color --ws-error-highlight=default,old |
954 test_decode_color >current &&
955 test_cmp expect.default-old current &&
957 git diff --color --ws-error-highlight=all |
958 test_decode_color >current &&
959 test_cmp expect.all current &&
961 git diff --color --ws-error-highlight=none |
962 test_decode_color >current &&
963 test_cmp expect.none current
967 test_expect_success
'test diff.wsErrorHighlight config' '
969 git -c diff.wsErrorHighlight=default,old diff --color |
970 test_decode_color >current &&
971 test_cmp expect.default-old current &&
973 git -c diff.wsErrorHighlight=all diff --color |
974 test_decode_color >current &&
975 test_cmp expect.all current &&
977 git -c diff.wsErrorHighlight=none diff --color |
978 test_decode_color >current &&
979 test_cmp expect.none current
983 test_expect_success
'option overrides diff.wsErrorHighlight' '
985 git -c diff.wsErrorHighlight=none \
986 diff --color --ws-error-highlight=default,old |
987 test_decode_color >current &&
988 test_cmp expect.default-old current &&
990 git -c diff.wsErrorHighlight=default \
991 diff --color --ws-error-highlight=all |
992 test_decode_color >current &&
993 test_cmp expect.all current &&
995 git -c diff.wsErrorHighlight=all \
996 diff --color --ws-error-highlight=none |
997 test_decode_color >current &&
998 test_cmp expect.none current
1002 test_expect_success
'detect moved code, complete file' '
1004 cat <<-\EOF >test.c &&
1008 printf("Hello World");
1012 git commit -m "add main function" &&
1013 git mv test.c main.c &&
1014 test_config color.diff.oldMoved "normal red" &&
1015 test_config color.diff.newMoved "normal green" &&
1016 git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1017 cat >expected <<-\EOF &&
1018 <BOLD>diff --git a/main.c b/main.c<RESET>
1019 <BOLD>new file mode 100644<RESET>
1020 <BOLD>index 0000000..a986c57<RESET>
1021 <BOLD>--- /dev/null<RESET>
1022 <BOLD>+++ b/main.c<RESET>
1023 <CYAN>@@ -0,0 +1,5 @@<RESET>
1024 <BGREEN>+<RESET><BGREEN>#include<stdio.h><RESET>
1025 <BGREEN>+<RESET><BGREEN>main()<RESET>
1026 <BGREEN>+<RESET><BGREEN>{<RESET>
1027 <BGREEN>+<RESET><BGREEN>printf("Hello World");<RESET>
1028 <BGREEN>+<RESET><BGREEN>}<RESET>
1029 <BOLD>diff --git a/test.c b/test.c<RESET>
1030 <BOLD>deleted file mode 100644<RESET>
1031 <BOLD>index a986c57..0000000<RESET>
1032 <BOLD>--- a/test.c<RESET>
1033 <BOLD>+++ /dev/null<RESET>
1034 <CYAN>@@ -1,5 +0,0 @@<RESET>
1035 <BRED>-#include<stdio.h><RESET>
1036 <BRED>-main()<RESET>
1038 <BRED>-printf("Hello World");<RESET>
1042 test_cmp expected actual
1045 test_expect_success
'detect malicious moved code, inside file' '
1046 test_config color.diff.oldMoved "normal red" &&
1047 test_config color.diff.newMoved "normal green" &&
1048 test_config color.diff.oldMovedAlternative "blue" &&
1049 test_config color.diff.newMovedAlternative "yellow" &&
1051 cat <<-\EOF >main.c &&
1059 int secure_foo(struct user *u)
1061 if (!u->is_allowed_foo)
1071 cat <<-\EOF >test.c &&
1075 printf("Hello World, but different\n");
1078 int another_function()
1083 git add main.c test.c &&
1084 git commit -m "add main and test file" &&
1085 cat <<-\EOF >main.c &&
1098 cat <<-\EOF >test.c &&
1102 printf("Hello World, but different\n");
1105 int secure_foo(struct user *u)
1108 if (!u->is_allowed_foo)
1112 int another_function()
1117 git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1118 cat <<-\EOF >expected &&
1119 <BOLD>diff --git a/main.c b/main.c<RESET>
1120 <BOLD>index 27a619c..7cf9336 100644<RESET>
1121 <BOLD>--- a/main.c<RESET>
1122 <BOLD>+++ b/main.c<RESET>
1123 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1124 printf("World\n");<RESET>
1127 <BRED>-int secure_foo(struct user *u)<RESET>
1129 <BLUE>-if (!u->is_allowed_foo)<RESET>
1130 <BLUE>-return;<RESET>
1131 <RED>-foo(u);<RESET>
1137 <BOLD>diff --git a/test.c b/test.c<RESET>
1138 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1139 <BOLD>--- a/test.c<RESET>
1140 <BOLD>+++ b/test.c<RESET>
1141 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1142 printf("Hello World, but different\n");<RESET>
1145 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1146 <BGREEN>+<RESET><BGREEN>{<RESET>
1147 <GREEN>+<RESET><GREEN>foo(u);<RESET>
1148 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1149 <BGREEN>+<RESET><BGREEN>return;<RESET>
1150 <GREEN>+<RESET><GREEN>}<RESET>
1152 int another_function()<RESET>
1157 test_cmp expected actual
1160 test_expect_success
'plain moved code, inside file' '
1161 test_config color.diff.oldMoved "normal red" &&
1162 test_config color.diff.newMoved "normal green" &&
1163 test_config color.diff.oldMovedAlternative "blue" &&
1164 test_config color.diff.newMovedAlternative "yellow" &&
1165 # needs previous test as setup
1166 git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1167 cat <<-\EOF >expected &&
1168 <BOLD>diff --git a/main.c b/main.c<RESET>
1169 <BOLD>index 27a619c..7cf9336 100644<RESET>
1170 <BOLD>--- a/main.c<RESET>
1171 <BOLD>+++ b/main.c<RESET>
1172 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1173 printf("World\n");<RESET>
1176 <BRED>-int secure_foo(struct user *u)<RESET>
1178 <BRED>-if (!u->is_allowed_foo)<RESET>
1179 <BRED>-return;<RESET>
1180 <BRED>-foo(u);<RESET>
1186 <BOLD>diff --git a/test.c b/test.c<RESET>
1187 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1188 <BOLD>--- a/test.c<RESET>
1189 <BOLD>+++ b/test.c<RESET>
1190 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1191 printf("Hello World, but different\n");<RESET>
1194 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1195 <BGREEN>+<RESET><BGREEN>{<RESET>
1196 <BGREEN>+<RESET><BGREEN>foo(u);<RESET>
1197 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1198 <BGREEN>+<RESET><BGREEN>return;<RESET>
1199 <BGREEN>+<RESET><BGREEN>}<RESET>
1201 int another_function()<RESET>
1206 test_cmp expected actual
1209 test_expect_success
'detect permutations inside moved code -- dimmed_zebra' '
1211 cat <<-\EOF >lines.txt &&
1229 git add lines.txt &&
1230 git commit -m "add poetry" &&
1231 cat <<-\EOF >lines.txt &&
1249 test_config color.diff.oldMoved "magenta" &&
1250 test_config color.diff.newMoved "cyan" &&
1251 test_config color.diff.oldMovedAlternative "blue" &&
1252 test_config color.diff.newMovedAlternative "yellow" &&
1253 test_config color.diff.oldMovedDimmed "normal magenta" &&
1254 test_config color.diff.newMovedDimmed "normal cyan" &&
1255 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1256 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1257 git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
1259 test_decode_color >actual &&
1260 cat <<-\EOF >expected &&
1261 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1262 <BOLD>--- a/lines.txt<RESET>
1263 <BOLD>+++ b/lines.txt<RESET>
1264 <CYAN>@@ -1,16 +1,16 @@<RESET>
1265 <BMAGENTA>-long line 1<RESET>
1266 <BMAGENTA>-long line 2<RESET>
1267 <BMAGENTA>-long line 3<RESET>
1274 <BCYAN>+<RESET><BCYAN>long line 1<RESET>
1275 <BCYAN>+<RESET><BCYAN>long line 2<RESET>
1276 <CYAN>+<RESET><CYAN>long line 3<RESET>
1277 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1278 <BYELLOW>+<RESET><BYELLOW>long line 15<RESET>
1279 <BYELLOW>+<RESET><BYELLOW>long line 16<RESET>
1284 <BMAGENTA>-long line 14<RESET>
1285 <BMAGENTA>-long line 15<RESET>
1286 <BMAGENTA>-long line 16<RESET>
1288 test_cmp expected actual
1291 test_expect_success
'cmd option assumes configured colored-moved' '
1292 test_config color.diff.oldMoved "magenta" &&
1293 test_config color.diff.newMoved "cyan" &&
1294 test_config color.diff.oldMovedAlternative "blue" &&
1295 test_config color.diff.newMovedAlternative "yellow" &&
1296 test_config color.diff.oldMovedDimmed "normal magenta" &&
1297 test_config color.diff.newMovedDimmed "normal cyan" &&
1298 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1299 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1300 test_config diff.colorMoved zebra &&
1301 git diff HEAD --no-renames --color-moved --color |
1303 test_decode_color >actual &&
1304 cat <<-\EOF >expected &&
1305 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1306 <BOLD>--- a/lines.txt<RESET>
1307 <BOLD>+++ b/lines.txt<RESET>
1308 <CYAN>@@ -1,16 +1,16 @@<RESET>
1309 <MAGENTA>-long line 1<RESET>
1310 <MAGENTA>-long line 2<RESET>
1311 <MAGENTA>-long line 3<RESET>
1318 <CYAN>+<RESET><CYAN>long line 1<RESET>
1319 <CYAN>+<RESET><CYAN>long line 2<RESET>
1320 <CYAN>+<RESET><CYAN>long line 3<RESET>
1321 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1322 <YELLOW>+<RESET><YELLOW>long line 15<RESET>
1323 <YELLOW>+<RESET><YELLOW>long line 16<RESET>
1328 <MAGENTA>-long line 14<RESET>
1329 <MAGENTA>-long line 15<RESET>
1330 <MAGENTA>-long line 16<RESET>
1332 test_cmp expected actual
1335 test_expect_success
'no effect from --color-moved with --word-diff' '
1336 cat <<-\EOF >text.txt &&
1337 Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1340 git commit -a -m "clean state" &&
1341 cat <<-\EOF >text.txt &&
1342 simply Lorem Ipsum dummy is text of the typesetting and printing industry.
1344 git diff --color-moved --word-diff >actual &&
1345 git diff --word-diff >expect &&
1346 test_cmp expect actual
1349 test_expect_success
'set up whitespace tests' '
1351 # Note that these lines have no leading or trailing whitespace.
1352 cat <<-\EOF >lines.txt &&
1363 git add lines.txt &&
1364 git commit -m "add poetry" &&
1365 git config color.diff.oldMoved "magenta" &&
1366 git config color.diff.newMoved "cyan"
1369 test_expect_success
'move detection ignoring whitespace ' '
1370 q_to_tab <<-\EOF >lines.txt &&
1374 Qchanged long line 9
1381 git diff HEAD --no-renames --color-moved --color |
1383 test_decode_color >actual &&
1384 cat <<-\EOF >expected &&
1385 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1386 <BOLD>--- a/lines.txt<RESET>
1387 <BOLD>+++ b/lines.txt<RESET>
1388 <CYAN>@@ -1,9 +1,9 @@<RESET>
1389 <GREEN>+<RESET> <GREEN>long line 6<RESET>
1390 <GREEN>+<RESET> <GREEN>long line 7<RESET>
1391 <GREEN>+<RESET> <GREEN>long line 8<RESET>
1392 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1398 <RED>-long line 6<RESET>
1399 <RED>-long line 7<RESET>
1400 <RED>-long line 8<RESET>
1401 <RED>-long line 9<RESET>
1403 test_cmp expected actual &&
1405 git diff HEAD --no-renames -w --color-moved --color |
1407 test_decode_color >actual &&
1408 cat <<-\EOF >expected &&
1409 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1410 <BOLD>--- a/lines.txt<RESET>
1411 <BOLD>+++ b/lines.txt<RESET>
1412 <CYAN>@@ -1,9 +1,9 @@<RESET>
1413 <CYAN>+<RESET> <CYAN>long line 6<RESET>
1414 <CYAN>+<RESET> <CYAN>long line 7<RESET>
1415 <CYAN>+<RESET> <CYAN>long line 8<RESET>
1416 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1422 <MAGENTA>-long line 6<RESET>
1423 <MAGENTA>-long line 7<RESET>
1424 <MAGENTA>-long line 8<RESET>
1425 <RED>-long line 9<RESET>
1427 test_cmp expected actual
1430 test_expect_success
'move detection ignoring whitespace changes' '
1432 # Lines 6-8 have a space change, but 9 is new whitespace
1433 q_to_tab <<-\EOF >lines.txt &&
1445 git diff HEAD --no-renames --color-moved --color |
1447 test_decode_color >actual &&
1448 cat <<-\EOF >expected &&
1449 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1450 <BOLD>--- a/lines.txt<RESET>
1451 <BOLD>+++ b/lines.txt<RESET>
1452 <CYAN>@@ -1,9 +1,9 @@<RESET>
1453 <GREEN>+<RESET><GREEN>long line 6<RESET>
1454 <GREEN>+<RESET><GREEN>long line 7<RESET>
1455 <GREEN>+<RESET><GREEN>long line 8<RESET>
1456 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1462 <RED>-long line 6<RESET>
1463 <RED>-long line 7<RESET>
1464 <RED>-long line 8<RESET>
1465 <RED>-long line 9<RESET>
1467 test_cmp expected actual &&
1469 git diff HEAD --no-renames -b --color-moved --color |
1471 test_decode_color >actual &&
1472 cat <<-\EOF >expected &&
1473 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1474 <BOLD>--- a/lines.txt<RESET>
1475 <BOLD>+++ b/lines.txt<RESET>
1476 <CYAN>@@ -1,9 +1,9 @@<RESET>
1477 <CYAN>+<RESET><CYAN>long line 6<RESET>
1478 <CYAN>+<RESET><CYAN>long line 7<RESET>
1479 <CYAN>+<RESET><CYAN>long line 8<RESET>
1480 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1486 <MAGENTA>-long line 6<RESET>
1487 <MAGENTA>-long line 7<RESET>
1488 <MAGENTA>-long line 8<RESET>
1489 <RED>-long line 9<RESET>
1491 test_cmp expected actual
1494 test_expect_success
'move detection ignoring whitespace at eol' '
1496 # Lines 6-9 have new eol whitespace, but 9 also has it in the middle
1497 q_to_tab <<-\EOF >lines.txt &&
1509 # avoid cluttering the output with complaints about our eol whitespace
1510 test_config core.whitespace -blank-at-eol &&
1512 git diff HEAD --no-renames --color-moved --color |
1514 test_decode_color >actual &&
1515 cat <<-\EOF >expected &&
1516 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1517 <BOLD>--- a/lines.txt<RESET>
1518 <BOLD>+++ b/lines.txt<RESET>
1519 <CYAN>@@ -1,9 +1,9 @@<RESET>
1520 <GREEN>+<RESET><GREEN>long line 6 <RESET>
1521 <GREEN>+<RESET><GREEN>long line 7 <RESET>
1522 <GREEN>+<RESET><GREEN>long line 8 <RESET>
1523 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1529 <RED>-long line 6<RESET>
1530 <RED>-long line 7<RESET>
1531 <RED>-long line 8<RESET>
1532 <RED>-long line 9<RESET>
1534 test_cmp expected actual &&
1536 git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
1538 test_decode_color >actual &&
1539 cat <<-\EOF >expected &&
1540 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1541 <BOLD>--- a/lines.txt<RESET>
1542 <BOLD>+++ b/lines.txt<RESET>
1543 <CYAN>@@ -1,9 +1,9 @@<RESET>
1544 <CYAN>+<RESET><CYAN>long line 6 <RESET>
1545 <CYAN>+<RESET><CYAN>long line 7 <RESET>
1546 <CYAN>+<RESET><CYAN>long line 8 <RESET>
1547 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1553 <MAGENTA>-long line 6<RESET>
1554 <MAGENTA>-long line 7<RESET>
1555 <MAGENTA>-long line 8<RESET>
1556 <RED>-long line 9<RESET>
1558 test_cmp expected actual
1561 test_expect_success
'clean up whitespace-test colors' '
1562 git config --unset color.diff.oldMoved &&
1563 git config --unset color.diff.newMoved
1566 test_expect_success
'--color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1583 git diff HEAD --color-moved=zebra --color --no-renames |
1585 test_decode_color >actual &&
1586 cat >expected <<-\EOF &&
1587 <BOLD>diff --git a/bar b/bar<RESET>
1588 <BOLD>--- a/bar<RESET>
1589 <BOLD>+++ b/bar<RESET>
1590 <CYAN>@@ -0,0 +1 @@<RESET>
1591 <GREEN>+<RESET><GREEN>line1<RESET>
1592 <BOLD>diff --git a/foo b/foo<RESET>
1593 <BOLD>--- a/foo<RESET>
1594 <BOLD>+++ b/foo<RESET>
1595 <CYAN>@@ -1,2 +1 @@<RESET>
1596 irrelevant_line<RESET>
1600 test_cmp expected actual
1603 test_expect_success
'--color-moved respects MIN_ALNUM_COUNT' '
1606 nineteen chars 456789
1608 twenty chars 234567890
1618 twenty chars 234567890
1619 nineteen chars 456789
1622 git diff HEAD --color-moved=zebra --color --no-renames |
1624 test_decode_color >actual &&
1625 cat >expected <<-\EOF &&
1626 <BOLD>diff --git a/bar b/bar<RESET>
1627 <BOLD>--- a/bar<RESET>
1628 <BOLD>+++ b/bar<RESET>
1629 <CYAN>@@ -0,0 +1,2 @@<RESET>
1630 <BOLD;CYAN>+<RESET><BOLD;CYAN>twenty chars 234567890<RESET>
1631 <GREEN>+<RESET><GREEN>nineteen chars 456789<RESET>
1632 <BOLD>diff --git a/foo b/foo<RESET>
1633 <BOLD>--- a/foo<RESET>
1634 <BOLD>+++ b/foo<RESET>
1635 <CYAN>@@ -1,3 +1 @@<RESET>
1636 <RED>-nineteen chars 456789<RESET>
1637 irrelevant_line<RESET>
1638 <BOLD;MAGENTA>-twenty chars 234567890<RESET>
1641 test_cmp expected actual
1644 test_expect_success
'--color-moved treats adjacent blocks as separate for MIN_ALNUM_COUNT' '
1665 git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
1666 cat >expected <<-\EOF &&
1667 <BOLD>diff --git a/bar b/bar<RESET>
1668 <BOLD>--- a/bar<RESET>
1669 <BOLD>+++ b/bar<RESET>
1670 <CYAN>@@ -0,0 +1,3 @@<RESET>
1671 <GREEN>+<RESET><GREEN>7charsB<RESET>
1672 <GREEN>+<RESET><GREEN>7charsC<RESET>
1673 <GREEN>+<RESET><GREEN>7charsA<RESET>
1674 <BOLD>diff --git a/foo b/foo<RESET>
1675 <BOLD>--- a/foo<RESET>
1676 <BOLD>+++ b/foo<RESET>
1677 <CYAN>@@ -1,4 +1 @@<RESET>
1678 <RED>-7charsA<RESET>
1679 irrelevant_line<RESET>
1680 <RED>-7charsB<RESET>
1681 <RED>-7charsC<RESET>
1684 test_cmp expected actual
1687 test_expect_success
'move detection with submodules' '
1688 test_create_repo bananas &&
1689 echo ripe >bananas/recipe &&
1690 git -C bananas add recipe &&
1691 test_commit fruit &&
1692 test_commit -C bananas recipe &&
1693 git submodule add ./bananas &&
1695 git commit -a -m "bananas are like a heavy library?" &&
1696 echo foul >bananas/recipe &&
1697 echo ripe >fruit.t &&
1699 git diff --submodule=diff --color-moved --color >actual &&
1701 # no move detection as the moved line is across repository boundaries.
1702 test_decode_color <actual >decoded_actual &&
1703 ! grep BGREEN decoded_actual &&
1704 ! grep BRED decoded_actual &&
1706 # nor did we mess with it another way
1707 git diff --submodule=diff --color | test_decode_color >expect &&
1708 test_cmp expect decoded_actual