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 */" &&
781 test_expect_success
'whitespace-only changes not reported' '
783 echo >x "hello world" &&
785 git commit -m "hello 1" &&
786 echo >x "hello world" &&
787 git diff -b >actual &&
788 test_cmp expect actual
793 similarity index NUM%
796 index 380c32a..a97b785 100644
798 test_expect_success
'whitespace-only changes reported across renames' '
800 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
802 git commit -m "base" &&
803 sed -e "5s/^/ /" x >z &&
806 git diff -w -M --cached |
807 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
808 test_cmp expect actual
812 diff --git a
/empty b
/void
813 similarity index
100%
818 test_expect_success
'rename empty' '
822 git commit -m empty &&
824 git diff -w --cached -M >current &&
825 test_cmp expected current
828 test_expect_success
'combined diff with autocrlf conversion' '
832 git commit -m "one side" x &&
833 git checkout HEAD^ &&
835 git commit -m "the other side" x &&
836 git config core.autocrlf true &&
837 test_must_fail git merge master &&
839 git diff | sed -e "1,/^@@@/d" >actual &&
844 # Start testing the colored format for whitespace checks
846 test_expect_success
'setup diff colors' '
847 git config color.diff.plain normal &&
848 git config color.diff.meta bold &&
849 git config color.diff.frag cyan &&
850 git config color.diff.func normal &&
851 git config color.diff.old red &&
852 git config color.diff.new green &&
853 git config color.diff.commit yellow &&
854 git config color.diff.whitespace blue &&
856 git config core.autocrlf false
859 test_expect_success
'diff that introduces a line with only tabs' '
860 git config core.whitespace blank-at-eol &&
863 git commit -m "initial" x &&
864 echo "{NTN}" | tr "NT" "\n\t" >>x &&
865 git diff --color | test_decode_color >current &&
867 cat >expected <<-\EOF &&
868 <BOLD>diff --git a/x b/x<RESET>
869 <BOLD>index 9daeafb..2874b91 100644<RESET>
872 <CYAN>@@ -1 +1,4 @@<RESET>
874 <GREEN>+<RESET><GREEN>{<RESET>
875 <GREEN>+<RESET><BLUE> <RESET>
876 <GREEN>+<RESET><GREEN>}<RESET>
879 test_cmp expected current
882 test_expect_success
'diff that introduces and removes ws breakages' '
885 echo "0. blank-at-eol " &&
886 echo "1. blank-at-eol "
888 git commit -a --allow-empty -m preimage &&
890 echo "0. blank-at-eol " &&
891 echo "1. still-blank-at-eol " &&
892 echo "2. and a new line "
896 test_decode_color >current &&
898 cat >expected <<-\EOF &&
899 <BOLD>diff --git a/x b/x<RESET>
900 <BOLD>index d0233a2..700886e 100644<RESET>
903 <CYAN>@@ -1,2 +1,3 @@<RESET>
904 0. blank-at-eol <RESET>
905 <RED>-1. blank-at-eol <RESET>
906 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
907 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
910 test_cmp expected current
913 test_expect_success
'ws-error-highlight test setup' '
917 echo "0. blank-at-eol " &&
918 echo "1. blank-at-eol "
920 git commit -a --allow-empty -m preimage &&
922 echo "0. blank-at-eol " &&
923 echo "1. still-blank-at-eol " &&
924 echo "2. and a new line "
927 cat >expect.default-old <<-\EOF &&
928 <BOLD>diff --git a/x b/x<RESET>
929 <BOLD>index d0233a2..700886e 100644<RESET>
932 <CYAN>@@ -1,2 +1,3 @@<RESET>
933 0. blank-at-eol <RESET>
934 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
935 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
936 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
939 cat >expect.all <<-\EOF &&
940 <BOLD>diff --git a/x b/x<RESET>
941 <BOLD>index d0233a2..700886e 100644<RESET>
944 <CYAN>@@ -1,2 +1,3 @@<RESET>
945 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
946 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
947 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
948 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
951 cat >expect.none <<-\EOF
952 <BOLD>diff --git a/x b/x<RESET>
953 <BOLD>index d0233a2..700886e 100644<RESET>
956 <CYAN>@@ -1,2 +1,3 @@<RESET>
957 0. blank-at-eol <RESET>
958 <RED>-1. blank-at-eol <RESET>
959 <GREEN>+1. still-blank-at-eol <RESET>
960 <GREEN>+2. and a new line <RESET>
965 test_expect_success
'test --ws-error-highlight option' '
967 git diff --color --ws-error-highlight=default,old |
968 test_decode_color >current &&
969 test_cmp expect.default-old current &&
971 git diff --color --ws-error-highlight=all |
972 test_decode_color >current &&
973 test_cmp expect.all current &&
975 git diff --color --ws-error-highlight=none |
976 test_decode_color >current &&
977 test_cmp expect.none current
981 test_expect_success
'test diff.wsErrorHighlight config' '
983 git -c diff.wsErrorHighlight=default,old diff --color |
984 test_decode_color >current &&
985 test_cmp expect.default-old current &&
987 git -c diff.wsErrorHighlight=all diff --color |
988 test_decode_color >current &&
989 test_cmp expect.all current &&
991 git -c diff.wsErrorHighlight=none diff --color |
992 test_decode_color >current &&
993 test_cmp expect.none current
997 test_expect_success
'option overrides diff.wsErrorHighlight' '
999 git -c diff.wsErrorHighlight=none \
1000 diff --color --ws-error-highlight=default,old |
1001 test_decode_color >current &&
1002 test_cmp expect.default-old current &&
1004 git -c diff.wsErrorHighlight=default \
1005 diff --color --ws-error-highlight=all |
1006 test_decode_color >current &&
1007 test_cmp expect.all current &&
1009 git -c diff.wsErrorHighlight=all \
1010 diff --color --ws-error-highlight=none |
1011 test_decode_color >current &&
1012 test_cmp expect.none current
1016 test_expect_success
'detect moved code, complete file' '
1018 cat <<-\EOF >test.c &&
1022 printf("Hello World");
1026 git commit -m "add main function" &&
1027 git mv test.c main.c &&
1028 test_config color.diff.oldMoved "normal red" &&
1029 test_config color.diff.newMoved "normal green" &&
1030 git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1031 cat >expected <<-\EOF &&
1032 <BOLD>diff --git a/main.c b/main.c<RESET>
1033 <BOLD>new file mode 100644<RESET>
1034 <BOLD>index 0000000..a986c57<RESET>
1035 <BOLD>--- /dev/null<RESET>
1036 <BOLD>+++ b/main.c<RESET>
1037 <CYAN>@@ -0,0 +1,5 @@<RESET>
1038 <BGREEN>+<RESET><BGREEN>#include<stdio.h><RESET>
1039 <BGREEN>+<RESET><BGREEN>main()<RESET>
1040 <BGREEN>+<RESET><BGREEN>{<RESET>
1041 <BGREEN>+<RESET><BGREEN>printf("Hello World");<RESET>
1042 <BGREEN>+<RESET><BGREEN>}<RESET>
1043 <BOLD>diff --git a/test.c b/test.c<RESET>
1044 <BOLD>deleted file mode 100644<RESET>
1045 <BOLD>index a986c57..0000000<RESET>
1046 <BOLD>--- a/test.c<RESET>
1047 <BOLD>+++ /dev/null<RESET>
1048 <CYAN>@@ -1,5 +0,0 @@<RESET>
1049 <BRED>-#include<stdio.h><RESET>
1050 <BRED>-main()<RESET>
1052 <BRED>-printf("Hello World");<RESET>
1056 test_cmp expected actual
1059 test_expect_success
'detect malicious moved code, inside file' '
1060 test_config color.diff.oldMoved "normal red" &&
1061 test_config color.diff.newMoved "normal green" &&
1062 test_config color.diff.oldMovedAlternative "blue" &&
1063 test_config color.diff.newMovedAlternative "yellow" &&
1065 cat <<-\EOF >main.c &&
1073 int secure_foo(struct user *u)
1075 if (!u->is_allowed_foo)
1085 cat <<-\EOF >test.c &&
1089 printf("Hello World, but different\n");
1092 int another_function()
1097 git add main.c test.c &&
1098 git commit -m "add main and test file" &&
1099 cat <<-\EOF >main.c &&
1112 cat <<-\EOF >test.c &&
1116 printf("Hello World, but different\n");
1119 int secure_foo(struct user *u)
1122 if (!u->is_allowed_foo)
1126 int another_function()
1131 git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1132 cat <<-\EOF >expected &&
1133 <BOLD>diff --git a/main.c b/main.c<RESET>
1134 <BOLD>index 27a619c..7cf9336 100644<RESET>
1135 <BOLD>--- a/main.c<RESET>
1136 <BOLD>+++ b/main.c<RESET>
1137 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1138 printf("World\n");<RESET>
1141 <BRED>-int secure_foo(struct user *u)<RESET>
1143 <BLUE>-if (!u->is_allowed_foo)<RESET>
1144 <BLUE>-return;<RESET>
1145 <RED>-foo(u);<RESET>
1151 <BOLD>diff --git a/test.c b/test.c<RESET>
1152 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1153 <BOLD>--- a/test.c<RESET>
1154 <BOLD>+++ b/test.c<RESET>
1155 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1156 printf("Hello World, but different\n");<RESET>
1159 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1160 <BGREEN>+<RESET><BGREEN>{<RESET>
1161 <GREEN>+<RESET><GREEN>foo(u);<RESET>
1162 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1163 <BGREEN>+<RESET><BGREEN>return;<RESET>
1164 <GREEN>+<RESET><GREEN>}<RESET>
1166 int another_function()<RESET>
1171 test_cmp expected actual
1174 test_expect_success
'plain moved code, inside file' '
1175 test_config color.diff.oldMoved "normal red" &&
1176 test_config color.diff.newMoved "normal green" &&
1177 test_config color.diff.oldMovedAlternative "blue" &&
1178 test_config color.diff.newMovedAlternative "yellow" &&
1179 # needs previous test as setup
1180 git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1181 cat <<-\EOF >expected &&
1182 <BOLD>diff --git a/main.c b/main.c<RESET>
1183 <BOLD>index 27a619c..7cf9336 100644<RESET>
1184 <BOLD>--- a/main.c<RESET>
1185 <BOLD>+++ b/main.c<RESET>
1186 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1187 printf("World\n");<RESET>
1190 <BRED>-int secure_foo(struct user *u)<RESET>
1192 <BRED>-if (!u->is_allowed_foo)<RESET>
1193 <BRED>-return;<RESET>
1194 <BRED>-foo(u);<RESET>
1200 <BOLD>diff --git a/test.c b/test.c<RESET>
1201 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1202 <BOLD>--- a/test.c<RESET>
1203 <BOLD>+++ b/test.c<RESET>
1204 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1205 printf("Hello World, but different\n");<RESET>
1208 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1209 <BGREEN>+<RESET><BGREEN>{<RESET>
1210 <BGREEN>+<RESET><BGREEN>foo(u);<RESET>
1211 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1212 <BGREEN>+<RESET><BGREEN>return;<RESET>
1213 <BGREEN>+<RESET><BGREEN>}<RESET>
1215 int another_function()<RESET>
1220 test_cmp expected actual
1223 test_expect_success
'detect permutations inside moved code -- dimmed_zebra' '
1225 cat <<-\EOF >lines.txt &&
1243 git add lines.txt &&
1244 git commit -m "add poetry" &&
1245 cat <<-\EOF >lines.txt &&
1263 test_config color.diff.oldMoved "magenta" &&
1264 test_config color.diff.newMoved "cyan" &&
1265 test_config color.diff.oldMovedAlternative "blue" &&
1266 test_config color.diff.newMovedAlternative "yellow" &&
1267 test_config color.diff.oldMovedDimmed "normal magenta" &&
1268 test_config color.diff.newMovedDimmed "normal cyan" &&
1269 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1270 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1271 git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
1273 test_decode_color >actual &&
1274 cat <<-\EOF >expected &&
1275 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1276 <BOLD>--- a/lines.txt<RESET>
1277 <BOLD>+++ b/lines.txt<RESET>
1278 <CYAN>@@ -1,16 +1,16 @@<RESET>
1279 <BMAGENTA>-long line 1<RESET>
1280 <BMAGENTA>-long line 2<RESET>
1281 <BMAGENTA>-long line 3<RESET>
1288 <BCYAN>+<RESET><BCYAN>long line 1<RESET>
1289 <BCYAN>+<RESET><BCYAN>long line 2<RESET>
1290 <CYAN>+<RESET><CYAN>long line 3<RESET>
1291 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1292 <BYELLOW>+<RESET><BYELLOW>long line 15<RESET>
1293 <BYELLOW>+<RESET><BYELLOW>long line 16<RESET>
1298 <BMAGENTA>-long line 14<RESET>
1299 <BMAGENTA>-long line 15<RESET>
1300 <BMAGENTA>-long line 16<RESET>
1302 test_cmp expected actual
1305 test_expect_success
'cmd option assumes configured colored-moved' '
1306 test_config color.diff.oldMoved "magenta" &&
1307 test_config color.diff.newMoved "cyan" &&
1308 test_config color.diff.oldMovedAlternative "blue" &&
1309 test_config color.diff.newMovedAlternative "yellow" &&
1310 test_config color.diff.oldMovedDimmed "normal magenta" &&
1311 test_config color.diff.newMovedDimmed "normal cyan" &&
1312 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1313 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1314 test_config diff.colorMoved zebra &&
1315 git diff HEAD --no-renames --color-moved --color |
1317 test_decode_color >actual &&
1318 cat <<-\EOF >expected &&
1319 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1320 <BOLD>--- a/lines.txt<RESET>
1321 <BOLD>+++ b/lines.txt<RESET>
1322 <CYAN>@@ -1,16 +1,16 @@<RESET>
1323 <MAGENTA>-long line 1<RESET>
1324 <MAGENTA>-long line 2<RESET>
1325 <MAGENTA>-long line 3<RESET>
1332 <CYAN>+<RESET><CYAN>long line 1<RESET>
1333 <CYAN>+<RESET><CYAN>long line 2<RESET>
1334 <CYAN>+<RESET><CYAN>long line 3<RESET>
1335 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1336 <YELLOW>+<RESET><YELLOW>long line 15<RESET>
1337 <YELLOW>+<RESET><YELLOW>long line 16<RESET>
1342 <MAGENTA>-long line 14<RESET>
1343 <MAGENTA>-long line 15<RESET>
1344 <MAGENTA>-long line 16<RESET>
1346 test_cmp expected actual
1349 test_expect_success
'no effect from --color-moved with --word-diff' '
1350 cat <<-\EOF >text.txt &&
1351 Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1354 git commit -a -m "clean state" &&
1355 cat <<-\EOF >text.txt &&
1356 simply Lorem Ipsum dummy is text of the typesetting and printing industry.
1358 git diff --color-moved --word-diff >actual &&
1359 git diff --word-diff >expect &&
1360 test_cmp expect actual
1363 test_expect_success
'set up whitespace tests' '
1365 # Note that these lines have no leading or trailing whitespace.
1366 cat <<-\EOF >lines.txt &&
1377 git add lines.txt &&
1378 git commit -m "add poetry" &&
1379 git config color.diff.oldMoved "magenta" &&
1380 git config color.diff.newMoved "cyan"
1383 test_expect_success
'move detection ignoring whitespace ' '
1384 q_to_tab <<-\EOF >lines.txt &&
1388 Qchanged long line 9
1395 git diff HEAD --no-renames --color-moved --color |
1397 test_decode_color >actual &&
1398 cat <<-\EOF >expected &&
1399 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1400 <BOLD>--- a/lines.txt<RESET>
1401 <BOLD>+++ b/lines.txt<RESET>
1402 <CYAN>@@ -1,9 +1,9 @@<RESET>
1403 <GREEN>+<RESET> <GREEN>long line 6<RESET>
1404 <GREEN>+<RESET> <GREEN>long line 7<RESET>
1405 <GREEN>+<RESET> <GREEN>long line 8<RESET>
1406 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1412 <RED>-long line 6<RESET>
1413 <RED>-long line 7<RESET>
1414 <RED>-long line 8<RESET>
1415 <RED>-long line 9<RESET>
1417 test_cmp expected actual &&
1419 git diff HEAD --no-renames -w --color-moved --color |
1421 test_decode_color >actual &&
1422 cat <<-\EOF >expected &&
1423 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1424 <BOLD>--- a/lines.txt<RESET>
1425 <BOLD>+++ b/lines.txt<RESET>
1426 <CYAN>@@ -1,9 +1,9 @@<RESET>
1427 <CYAN>+<RESET> <CYAN>long line 6<RESET>
1428 <CYAN>+<RESET> <CYAN>long line 7<RESET>
1429 <CYAN>+<RESET> <CYAN>long line 8<RESET>
1430 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1436 <MAGENTA>-long line 6<RESET>
1437 <MAGENTA>-long line 7<RESET>
1438 <MAGENTA>-long line 8<RESET>
1439 <RED>-long line 9<RESET>
1441 test_cmp expected actual
1444 test_expect_success
'move detection ignoring whitespace changes' '
1446 # Lines 6-8 have a space change, but 9 is new whitespace
1447 q_to_tab <<-\EOF >lines.txt &&
1459 git diff HEAD --no-renames --color-moved --color |
1461 test_decode_color >actual &&
1462 cat <<-\EOF >expected &&
1463 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1464 <BOLD>--- a/lines.txt<RESET>
1465 <BOLD>+++ b/lines.txt<RESET>
1466 <CYAN>@@ -1,9 +1,9 @@<RESET>
1467 <GREEN>+<RESET><GREEN>long line 6<RESET>
1468 <GREEN>+<RESET><GREEN>long line 7<RESET>
1469 <GREEN>+<RESET><GREEN>long line 8<RESET>
1470 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1476 <RED>-long line 6<RESET>
1477 <RED>-long line 7<RESET>
1478 <RED>-long line 8<RESET>
1479 <RED>-long line 9<RESET>
1481 test_cmp expected actual &&
1483 git diff HEAD --no-renames -b --color-moved --color |
1485 test_decode_color >actual &&
1486 cat <<-\EOF >expected &&
1487 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1488 <BOLD>--- a/lines.txt<RESET>
1489 <BOLD>+++ b/lines.txt<RESET>
1490 <CYAN>@@ -1,9 +1,9 @@<RESET>
1491 <CYAN>+<RESET><CYAN>long line 6<RESET>
1492 <CYAN>+<RESET><CYAN>long line 7<RESET>
1493 <CYAN>+<RESET><CYAN>long line 8<RESET>
1494 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1500 <MAGENTA>-long line 6<RESET>
1501 <MAGENTA>-long line 7<RESET>
1502 <MAGENTA>-long line 8<RESET>
1503 <RED>-long line 9<RESET>
1505 test_cmp expected actual
1508 test_expect_success
'move detection ignoring whitespace at eol' '
1510 # Lines 6-9 have new eol whitespace, but 9 also has it in the middle
1511 q_to_tab <<-\EOF >lines.txt &&
1523 # avoid cluttering the output with complaints about our eol whitespace
1524 test_config core.whitespace -blank-at-eol &&
1526 git diff HEAD --no-renames --color-moved --color |
1528 test_decode_color >actual &&
1529 cat <<-\EOF >expected &&
1530 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1531 <BOLD>--- a/lines.txt<RESET>
1532 <BOLD>+++ b/lines.txt<RESET>
1533 <CYAN>@@ -1,9 +1,9 @@<RESET>
1534 <GREEN>+<RESET><GREEN>long line 6 <RESET>
1535 <GREEN>+<RESET><GREEN>long line 7 <RESET>
1536 <GREEN>+<RESET><GREEN>long line 8 <RESET>
1537 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1543 <RED>-long line 6<RESET>
1544 <RED>-long line 7<RESET>
1545 <RED>-long line 8<RESET>
1546 <RED>-long line 9<RESET>
1548 test_cmp expected actual &&
1550 git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
1552 test_decode_color >actual &&
1553 cat <<-\EOF >expected &&
1554 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1555 <BOLD>--- a/lines.txt<RESET>
1556 <BOLD>+++ b/lines.txt<RESET>
1557 <CYAN>@@ -1,9 +1,9 @@<RESET>
1558 <CYAN>+<RESET><CYAN>long line 6 <RESET>
1559 <CYAN>+<RESET><CYAN>long line 7 <RESET>
1560 <CYAN>+<RESET><CYAN>long line 8 <RESET>
1561 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1567 <MAGENTA>-long line 6<RESET>
1568 <MAGENTA>-long line 7<RESET>
1569 <MAGENTA>-long line 8<RESET>
1570 <RED>-long line 9<RESET>
1572 test_cmp expected actual
1575 test_expect_success
'clean up whitespace-test colors' '
1576 git config --unset color.diff.oldMoved &&
1577 git config --unset color.diff.newMoved
1580 test_expect_success
'--color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1597 git diff HEAD --color-moved=zebra --color --no-renames |
1599 test_decode_color >actual &&
1600 cat >expected <<-\EOF &&
1601 <BOLD>diff --git a/bar b/bar<RESET>
1602 <BOLD>--- a/bar<RESET>
1603 <BOLD>+++ b/bar<RESET>
1604 <CYAN>@@ -0,0 +1 @@<RESET>
1605 <GREEN>+<RESET><GREEN>line1<RESET>
1606 <BOLD>diff --git a/foo b/foo<RESET>
1607 <BOLD>--- a/foo<RESET>
1608 <BOLD>+++ b/foo<RESET>
1609 <CYAN>@@ -1,2 +1 @@<RESET>
1610 irrelevant_line<RESET>
1614 test_cmp expected actual
1617 test_expect_success
'--color-moved respects MIN_ALNUM_COUNT' '
1620 nineteen chars 456789
1622 twenty chars 234567890
1632 twenty chars 234567890
1633 nineteen chars 456789
1636 git diff HEAD --color-moved=zebra --color --no-renames |
1638 test_decode_color >actual &&
1639 cat >expected <<-\EOF &&
1640 <BOLD>diff --git a/bar b/bar<RESET>
1641 <BOLD>--- a/bar<RESET>
1642 <BOLD>+++ b/bar<RESET>
1643 <CYAN>@@ -0,0 +1,2 @@<RESET>
1644 <BOLD;CYAN>+<RESET><BOLD;CYAN>twenty chars 234567890<RESET>
1645 <GREEN>+<RESET><GREEN>nineteen chars 456789<RESET>
1646 <BOLD>diff --git a/foo b/foo<RESET>
1647 <BOLD>--- a/foo<RESET>
1648 <BOLD>+++ b/foo<RESET>
1649 <CYAN>@@ -1,3 +1 @@<RESET>
1650 <RED>-nineteen chars 456789<RESET>
1651 irrelevant_line<RESET>
1652 <BOLD;MAGENTA>-twenty chars 234567890<RESET>
1655 test_cmp expected actual
1658 test_expect_success
'--color-moved treats adjacent blocks as separate for MIN_ALNUM_COUNT' '
1679 git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
1680 cat >expected <<-\EOF &&
1681 <BOLD>diff --git a/bar b/bar<RESET>
1682 <BOLD>--- a/bar<RESET>
1683 <BOLD>+++ b/bar<RESET>
1684 <CYAN>@@ -0,0 +1,3 @@<RESET>
1685 <GREEN>+<RESET><GREEN>7charsB<RESET>
1686 <GREEN>+<RESET><GREEN>7charsC<RESET>
1687 <GREEN>+<RESET><GREEN>7charsA<RESET>
1688 <BOLD>diff --git a/foo b/foo<RESET>
1689 <BOLD>--- a/foo<RESET>
1690 <BOLD>+++ b/foo<RESET>
1691 <CYAN>@@ -1,4 +1 @@<RESET>
1692 <RED>-7charsA<RESET>
1693 irrelevant_line<RESET>
1694 <RED>-7charsB<RESET>
1695 <RED>-7charsC<RESET>
1698 test_cmp expected actual
1701 test_expect_success
'move detection with submodules' '
1702 test_create_repo bananas &&
1703 echo ripe >bananas/recipe &&
1704 git -C bananas add recipe &&
1705 test_commit fruit &&
1706 test_commit -C bananas recipe &&
1707 git submodule add ./bananas &&
1709 git commit -a -m "bananas are like a heavy library?" &&
1710 echo foul >bananas/recipe &&
1711 echo ripe >fruit.t &&
1713 git diff --submodule=diff --color-moved --color >actual &&
1715 # no move detection as the moved line is across repository boundaries.
1716 test_decode_color <actual >decoded_actual &&
1717 ! grep BGREEN decoded_actual &&
1718 ! grep BRED decoded_actual &&
1720 # nor did we mess with it another way
1721 git diff --submodule=diff --color | test_decode_color >expect &&
1722 test_cmp expect decoded_actual