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 &&
110 tr "Q_" "\015 " <<-\EOF >expect &&
112 index d99af23..22d9f73 100644
116 -whitespace at beginning
117 +_ whitespace at beginning
119 -whitespace in the middle
120 +white space in the middle
126 test_cmp expect out &&
128 git diff -b --ignore-space-at-eol >out &&
129 test_cmp expect out &&
131 tr "Q_" "\015 " <<-\EOF >expect &&
133 index d99af23..22d9f73 100644
137 -whitespace at beginning
139 -whitespace in the middle
140 +_ whitespace at beginning
142 +white space in the middle
147 git diff --ignore-space-at-eol >out &&
151 test_expect_success 'ignore-blank-lines: only new lines' '
153 git update-index x &&
154 test_seq 5 | sed "/3/i\\
156 git diff --ignore-blank-lines >out &&
161 test_expect_success 'ignore-blank-lines: only new lines with space' '
163 git update-index x &&
164 test_seq 5 | sed "/3/i\\
166 git diff -w --ignore-blank-lines >out &&
171 test_expect_success 'ignore-blank-lines: after change' '
183 git update-index x &&
196 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
197 cat <<-\EOF >expected &&
211 compare_diff_patch expected out.tmp
214 test_expect_success 'ignore-blank-lines: before change' '
225 git update-index x &&
238 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
239 cat <<-\EOF >expected &&
252 compare_diff_patch expected out.tmp
255 test_expect_success 'ignore-blank-lines: between changes' '
270 git update-index x &&
287 git diff --ignore-blank-lines >out.tmp &&
288 cat <<-\EOF >expected &&
309 compare_diff_patch expected out.tmp
312 test_expect_success 'ignore-blank-lines: between changes (with interhunkctx)' '
314 git update-index x &&
332 git diff --inter-hunk-context=2 --ignore-blank-lines >out.tmp &&
333 cat <<-\EOF >expected &&
354 compare_diff_patch expected out.tmp
357 test_expect_success 'ignore-blank-lines: scattered spaces' '
359 git update-index x &&
380 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
381 cat <<-\EOF >expected &&
396 compare_diff_patch expected out.tmp
399 test_expect_success 'ignore-blank-lines: spaces coalesce' '
401 git update-index x &&
415 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
416 cat <<-\EOF >expected &&
433 compare_diff_patch expected out.tmp
436 test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
438 git update-index x &&
464 git diff --ignore-blank-lines >out.tmp &&
465 cat <<-\EOF >expected &&
494 compare_diff_patch expected out.tmp
497 test_expect_success 'check mixed spaces and tabs in indent' '
498 # This is indented with SP HT SP.
500 git diff --check | grep "space before tab in indent"
503 test_expect_success 'check mixed tabs and spaces in indent' '
504 # This is indented with HT SP HT.
506 git diff --check | grep "space before tab in indent"
509 test_expect_success 'check with no whitespace errors' '
510 git commit -m "snapshot" &&
515 test_expect_success 'check with trailing whitespace' '
517 test_must_fail git diff --check
520 test_expect_success 'check with space before tab in indent' '
521 # indent has space followed by hard tab
523 test_must_fail git diff --check
526 test_expect_success '--check and --exit-code are not exclusive' '
528 git diff --check --exit-code
531 test_expect_success '--check and --quiet are not exclusive' '
532 git diff --check --quiet
535 test_expect_success 'check staged with no whitespace errors' '
538 git diff --cached --check
541 test_expect_success 'check staged with trailing whitespace' '
544 test_must_fail git diff --cached --check
547 test_expect_success 'check staged with space before tab in indent' '
548 # indent has space followed by hard tab
551 test_must_fail git diff --cached --check
554 test_expect_success 'check with no whitespace errors (diff-index)' '
557 git diff-index --check HEAD
560 test_expect_success 'check with trailing whitespace (diff-index)' '
563 test_must_fail git diff-index --check HEAD
566 test_expect_success 'check with space before tab in indent (diff-index)' '
567 # indent has space followed by hard tab
570 test_must_fail git diff-index --check HEAD
573 test_expect_success 'check staged with no whitespace errors (diff-index)' '
576 git diff-index --cached --check HEAD
579 test_expect_success 'check staged with trailing whitespace (diff-index)' '
582 test_must_fail git diff-index --cached --check HEAD
585 test_expect_success 'check staged with space before tab in indent (diff-index)' '
586 # indent has space followed by hard tab
589 test_must_fail git diff-index --cached --check HEAD
592 test_expect_success 'check with no whitespace errors (diff-tree)' '
594 git commit -m "new commit" x &&
595 git diff-tree --check HEAD^ HEAD
598 test_expect_success 'check with trailing whitespace (diff-tree)' '
600 git commit -m "another commit" x &&
601 test_must_fail git diff-tree --check HEAD^ HEAD
604 test_expect_success 'check with space before tab in indent (diff-tree)' '
605 # indent has space followed by hard tab
607 git commit -m "yet another" x &&
608 test_must_fail git diff-tree --check HEAD^ HEAD
611 test_expect_success 'check trailing whitespace (trailing-space: off)' '
612 git config core.whitespace "-trailing-space" &&
613 echo "foo (); " >x &&
617 test_expect_success 'check trailing whitespace (trailing-space: on)' '
618 git config core.whitespace "trailing-space" &&
619 echo "foo (); " >x &&
620 test_must_fail git diff --check
623 test_expect_success 'check space before tab in indent (space-before-tab: off)' '
624 # indent contains space followed by HT
625 git config core.whitespace "-space-before-tab" &&
626 echo " foo ();" >x &&
630 test_expect_success 'check space before tab in indent (space-before-tab: on)' '
631 # indent contains space followed by HT
632 git config core.whitespace "space-before-tab" &&
633 echo " foo (); " >x &&
634 test_must_fail git diff --check
637 test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
638 git config core.whitespace "-indent-with-non-tab" &&
639 echo " foo ();" >x &&
643 test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
644 git config core.whitespace "indent-with-non-tab" &&
645 echo " foo ();" >x &&
646 test_must_fail git diff --check
649 test_expect_success 'ditto, but tabwidth=9' '
650 git config core.whitespace "indent-with-non-tab,tabwidth=9" &&
654 test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '
655 git config core.whitespace "indent-with-non-tab" &&
656 echo " foo ();" >x &&
657 test_must_fail git diff --check
660 test_expect_success 'ditto, but tabwidth=10' '
661 git config core.whitespace "indent-with-non-tab,tabwidth=10" &&
662 test_must_fail git diff --check
665 test_expect_success 'ditto, but tabwidth=20' '
666 git config core.whitespace "indent-with-non-tab,tabwidth=20" &&
670 test_expect_success 'check tabs as indentation (tab-in-indent: off)' '
671 git config core.whitespace "-tab-in-indent" &&
672 echo " foo ();" >x &&
676 test_expect_success 'check tabs as indentation (tab-in-indent: on)' '
677 git config core.whitespace "tab-in-indent" &&
678 echo " foo ();" >x &&
679 test_must_fail git diff --check
682 test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '
683 git config core.whitespace "tab-in-indent" &&
684 echo " foo ();" >x &&
685 test_must_fail git diff --check
688 test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '
689 git config core.whitespace "tab-in-indent,tabwidth=1" &&
690 test_must_fail git diff --check
693 test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
694 git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
696 test_must_fail git diff --check
699 test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '
700 git config --unset core.whitespace &&
701 echo "x whitespace" >.gitattributes &&
702 echo " foo ();" >x &&
707 test_expect_success 'line numbers in --check output are correct' '
709 echo "foo(); " >>x &&
710 git diff --check | grep "x:2:"
713 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
716 git diff --check | grep "new blank line"
719 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
720 { echo a; echo b; echo; echo; } >x &&
722 { echo a; echo; echo; echo; echo; } >x &&
723 git diff --check | grep "new blank line"
726 test_expect_success 'checkdiff allows new blank lines' '
730 echo "/* This is new */" &&
739 test_expect_success 'whitespace-only changes not reported' '
741 echo >x "hello world" &&
743 git commit -m "hello 1" &&
744 echo >x "hello world" &&
745 git diff -b >actual &&
746 test_cmp expect actual
751 similarity index NUM%
754 index 380c32a..a97b785 100644
756 test_expect_success 'whitespace-only changes reported across renames' '
758 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
760 git commit -m "base" &&
761 sed -e "5s/^/ /" x >z &&
764 git diff -w -M --cached |
765 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
766 test_cmp expect actual
770 diff --git a/empty b/void
771 similarity index 100%
776 test_expect_success 'rename empty' '
780 git commit -m empty &&
782 git diff -w --cached -M >current &&
783 test_cmp expected current
786 test_expect_success 'combined diff with autocrlf conversion' '
790 git commit -m "one side" x &&
791 git checkout HEAD^ &&
793 git commit -m "the other side" x &&
794 git config core.autocrlf true &&
795 test_must_fail git merge master &&
797 git diff | sed -e "1,/^@@@/d" >actual &&
802 # Start testing the colored format for whitespace checks
804 test_expect_success 'setup diff colors' '
805 git config color.diff.plain normal &&
806 git config color.diff.meta bold &&
807 git config color.diff.frag cyan &&
808 git config color.diff.func normal &&
809 git config color.diff.old red &&
810 git config color.diff.new green &&
811 git config color.diff.commit yellow &&
812 git config color.diff.whitespace blue &&
814 git config core.autocrlf false
817 test_expect_success 'diff that introduces a line with only tabs' '
818 git config core.whitespace blank-at-eol &&
821 git commit -m "initial" x &&
822 echo "{NTN}" | tr "NT" "\n\t" >>x &&
823 git diff --color | test_decode_color >current &&
825 cat >expected <<-\EOF &&
826 <BOLD>diff --git a/x b/x<RESET>
827 <BOLD>index 9daeafb..2874b91 100644<RESET>
830 <CYAN>@@ -1 +1,4 @@<RESET>
832 <GREEN>+<RESET><GREEN>{<RESET>
833 <GREEN>+<RESET><BLUE> <RESET>
834 <GREEN>+<RESET><GREEN>}<RESET>
837 test_cmp expected current
840 test_expect_success 'diff that introduces and removes ws breakages' '
843 echo "0. blank-at-eol " &&
844 echo "1. blank-at-eol "
846 git commit -a --allow-empty -m preimage &&
848 echo "0. blank-at-eol " &&
849 echo "1. still-blank-at-eol " &&
850 echo "2. and a new line "
854 test_decode_color >current &&
856 cat >expected <<-\EOF &&
857 <BOLD>diff --git a/x b/x<RESET>
858 <BOLD>index d0233a2..700886e 100644<RESET>
861 <CYAN>@@ -1,2 +1,3 @@<RESET>
862 0. blank-at-eol <RESET>
863 <RED>-1. blank-at-eol <RESET>
864 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
865 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
868 test_cmp expected current
871 test_expect_success 'ws-error-highlight test setup' '
875 echo "0. blank-at-eol " &&
876 echo "1. blank-at-eol "
878 git commit -a --allow-empty -m preimage &&
880 echo "0. blank-at-eol " &&
881 echo "1. still-blank-at-eol " &&
882 echo "2. and a new line "
885 cat >expect.default-old <<-\EOF &&
886 <BOLD>diff --git a/x b/x<RESET>
887 <BOLD>index d0233a2..700886e 100644<RESET>
890 <CYAN>@@ -1,2 +1,3 @@<RESET>
891 0. blank-at-eol <RESET>
892 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
893 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
894 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
897 cat >expect.all <<-\EOF &&
898 <BOLD>diff --git a/x b/x<RESET>
899 <BOLD>index d0233a2..700886e 100644<RESET>
902 <CYAN>@@ -1,2 +1,3 @@<RESET>
903 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
904 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
905 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
906 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
909 cat >expect.none <<-\EOF
910 <BOLD>diff --git a/x b/x<RESET>
911 <BOLD>index d0233a2..700886e 100644<RESET>
914 <CYAN>@@ -1,2 +1,3 @@<RESET>
915 0. blank-at-eol <RESET>
916 <RED>-1. blank-at-eol <RESET>
917 <GREEN>+1. still-blank-at-eol <RESET>
918 <GREEN>+2. and a new line <RESET>
923 test_expect_success 'test --ws-error-highlight option' '
925 git diff --color --ws-error-highlight=default,old |
926 test_decode_color >current &&
927 test_cmp expect.default-old current &&
929 git diff --color --ws-error-highlight=all |
930 test_decode_color >current &&
931 test_cmp expect.all current &&
933 git diff --color --ws-error-highlight=none |
934 test_decode_color >current &&
935 test_cmp expect.none current
939 test_expect_success 'test diff.wsErrorHighlight config' '
941 git -c diff.wsErrorHighlight=default,old diff --color |
942 test_decode_color >current &&
943 test_cmp expect.default-old current &&
945 git -c diff.wsErrorHighlight=all diff --color |
946 test_decode_color >current &&
947 test_cmp expect.all current &&
949 git -c diff.wsErrorHighlight=none diff --color |
950 test_decode_color >current &&
951 test_cmp expect.none current
955 test_expect_success 'option overrides diff.wsErrorHighlight' '
957 git -c diff.wsErrorHighlight=none \
958 diff --color --ws-error-highlight=default,old |
959 test_decode_color >current &&
960 test_cmp expect.default-old current &&
962 git -c diff.wsErrorHighlight=default \
963 diff --color --ws-error-highlight=all |
964 test_decode_color >current &&
965 test_cmp expect.all current &&
967 git -c diff.wsErrorHighlight=all \
968 diff --color --ws-error-highlight=none |
969 test_decode_color >current &&
970 test_cmp expect.none current
974 test_expect_success 'detect moved code, complete file' '
976 cat <<-\EOF >test.c &&
980 printf("Hello World");
984 git commit -m "add main function" &&
985 git mv test.c main.c &&
986 test_config color.diff.oldMoved "normal red" &&
987 test_config color.diff.newMoved "normal green" &&
988 git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
989 cat >expected <<-\EOF &&
990 <BOLD>diff --git a/main.c b/main.c<RESET>
991 <BOLD>new file mode 100644<RESET>
992 <BOLD>index 0000000..a986c57<RESET>
993 <BOLD>--- /dev/null<RESET>
994 <BOLD>+++ b/main.c<RESET>
995 <CYAN>@@ -0,0 +1,5 @@<RESET>
996 <BGREEN>+<RESET><BGREEN>#include<stdio.h><RESET>
997 <BGREEN>+<RESET><BGREEN>main()<RESET>
998 <BGREEN>+<RESET><BGREEN>{<RESET>
999 <BGREEN>+<RESET><BGREEN>printf("Hello World");<RESET>
1000 <BGREEN>+<RESET><BGREEN>}<RESET>
1001 <BOLD>diff --git a/test.c b/test.c<RESET>
1002 <BOLD>deleted file mode 100644<RESET>
1003 <BOLD>index a986c57..0000000<RESET>
1004 <BOLD>--- a/test.c<RESET>
1005 <BOLD>+++ /dev/null<RESET>
1006 <CYAN>@@ -1,5 +0,0 @@<RESET>
1007 <BRED>-#include<stdio.h><RESET>
1008 <BRED>-main()<RESET>
1010 <BRED>-printf("Hello World");<RESET>
1014 test_cmp expected actual
1017 test_expect_success 'detect malicious moved code, inside file' '
1018 test_config color.diff.oldMoved "normal red" &&
1019 test_config color.diff.newMoved "normal green" &&
1020 test_config color.diff.oldMovedAlternative "blue" &&
1021 test_config color.diff.newMovedAlternative "yellow" &&
1023 cat <<-\EOF >main.c &&
1031 int secure_foo(struct user *u)
1033 if (!u->is_allowed_foo)
1043 cat <<-\EOF >test.c &&
1047 printf("Hello World, but different\n");
1050 int another_function()
1055 git add main.c test.c &&
1056 git commit -m "add main and test file" &&
1057 cat <<-\EOF >main.c &&
1070 cat <<-\EOF >test.c &&
1074 printf("Hello World, but different\n");
1077 int secure_foo(struct user *u)
1080 if (!u->is_allowed_foo)
1084 int another_function()
1089 git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1090 cat <<-\EOF >expected &&
1091 <BOLD>diff --git a/main.c b/main.c<RESET>
1092 <BOLD>index 27a619c..7cf9336 100644<RESET>
1093 <BOLD>--- a/main.c<RESET>
1094 <BOLD>+++ b/main.c<RESET>
1095 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1096 printf("World\n");<RESET>
1099 <BRED>-int secure_foo(struct user *u)<RESET>
1101 <BLUE>-if (!u->is_allowed_foo)<RESET>
1102 <BLUE>-return;<RESET>
1103 <RED>-foo(u);<RESET>
1109 <BOLD>diff --git a/test.c b/test.c<RESET>
1110 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1111 <BOLD>--- a/test.c<RESET>
1112 <BOLD>+++ b/test.c<RESET>
1113 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1114 printf("Hello World, but different\n");<RESET>
1117 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1118 <BGREEN>+<RESET><BGREEN>{<RESET>
1119 <GREEN>+<RESET><GREEN>foo(u);<RESET>
1120 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1121 <BGREEN>+<RESET><BGREEN>return;<RESET>
1122 <GREEN>+<RESET><GREEN>}<RESET>
1124 int another_function()<RESET>
1129 test_cmp expected actual
1132 test_expect_success 'plain moved code, inside file' '
1133 test_config color.diff.oldMoved "normal red" &&
1134 test_config color.diff.newMoved "normal green" &&
1135 test_config color.diff.oldMovedAlternative "blue" &&
1136 test_config color.diff.newMovedAlternative "yellow" &&
1137 # needs previous test as setup
1138 git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1139 cat <<-\EOF >expected &&
1140 <BOLD>diff --git a/main.c b/main.c<RESET>
1141 <BOLD>index 27a619c..7cf9336 100644<RESET>
1142 <BOLD>--- a/main.c<RESET>
1143 <BOLD>+++ b/main.c<RESET>
1144 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1145 printf("World\n");<RESET>
1148 <BRED>-int secure_foo(struct user *u)<RESET>
1150 <BRED>-if (!u->is_allowed_foo)<RESET>
1151 <BRED>-return;<RESET>
1152 <BRED>-foo(u);<RESET>
1158 <BOLD>diff --git a/test.c b/test.c<RESET>
1159 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1160 <BOLD>--- a/test.c<RESET>
1161 <BOLD>+++ b/test.c<RESET>
1162 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1163 printf("Hello World, but different\n");<RESET>
1166 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1167 <BGREEN>+<RESET><BGREEN>{<RESET>
1168 <BGREEN>+<RESET><BGREEN>foo(u);<RESET>
1169 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1170 <BGREEN>+<RESET><BGREEN>return;<RESET>
1171 <BGREEN>+<RESET><BGREEN>}<RESET>
1173 int another_function()<RESET>
1178 test_cmp expected actual
1181 test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
1183 cat <<-\EOF >lines.txt &&
1201 git add lines.txt &&
1202 git commit -m "add poetry" &&
1203 cat <<-\EOF >lines.txt &&
1221 test_config color.diff.oldMoved "magenta" &&
1222 test_config color.diff.newMoved "cyan" &&
1223 test_config color.diff.oldMovedAlternative "blue" &&
1224 test_config color.diff.newMovedAlternative "yellow" &&
1225 test_config color.diff.oldMovedDimmed "normal magenta" &&
1226 test_config color.diff.newMovedDimmed "normal cyan" &&
1227 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1228 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1229 git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
1231 test_decode_color >actual &&
1232 cat <<-\EOF >expected &&
1233 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1234 <BOLD>--- a/lines.txt<RESET>
1235 <BOLD>+++ b/lines.txt<RESET>
1236 <CYAN>@@ -1,16 +1,16 @@<RESET>
1237 <BMAGENTA>-long line 1<RESET>
1238 <BMAGENTA>-long line 2<RESET>
1239 <BMAGENTA>-long line 3<RESET>
1246 <BCYAN>+<RESET><BCYAN>long line 1<RESET>
1247 <BCYAN>+<RESET><BCYAN>long line 2<RESET>
1248 <CYAN>+<RESET><CYAN>long line 3<RESET>
1249 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1250 <BYELLOW>+<RESET><BYELLOW>long line 15<RESET>
1251 <BYELLOW>+<RESET><BYELLOW>long line 16<RESET>
1256 <BMAGENTA>-long line 14<RESET>
1257 <BMAGENTA>-long line 15<RESET>
1258 <BMAGENTA>-long line 16<RESET>
1260 test_cmp expected actual
1263 test_expect_success 'cmd option assumes configured colored-moved' '
1264 test_config color.diff.oldMoved "magenta" &&
1265 test_config color.diff.newMoved "cyan" &&
1266 test_config color.diff.oldMovedAlternative "blue" &&
1267 test_config color.diff.newMovedAlternative "yellow" &&
1268 test_config color.diff.oldMovedDimmed "normal magenta" &&
1269 test_config color.diff.newMovedDimmed "normal cyan" &&
1270 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1271 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1272 test_config diff.colorMoved zebra &&
1273 git diff HEAD --no-renames --color-moved --color |
1275 test_decode_color >actual &&
1276 cat <<-\EOF >expected &&
1277 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1278 <BOLD>--- a/lines.txt<RESET>
1279 <BOLD>+++ b/lines.txt<RESET>
1280 <CYAN>@@ -1,16 +1,16 @@<RESET>
1281 <MAGENTA>-long line 1<RESET>
1282 <MAGENTA>-long line 2<RESET>
1283 <MAGENTA>-long line 3<RESET>
1290 <CYAN>+<RESET><CYAN>long line 1<RESET>
1291 <CYAN>+<RESET><CYAN>long line 2<RESET>
1292 <CYAN>+<RESET><CYAN>long line 3<RESET>
1293 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1294 <YELLOW>+<RESET><YELLOW>long line 15<RESET>
1295 <YELLOW>+<RESET><YELLOW>long line 16<RESET>
1300 <MAGENTA>-long line 14<RESET>
1301 <MAGENTA>-long line 15<RESET>
1302 <MAGENTA>-long line 16<RESET>
1304 test_cmp expected actual
1307 test_expect_success 'no effect from --color-moved with --word-diff' '
1308 cat <<-\EOF >text.txt &&
1309 Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1312 git commit -a -m "clean state" &&
1313 cat <<-\EOF >text.txt &&
1314 simply Lorem Ipsum dummy is text of the typesetting and printing industry.
1316 git diff --color-moved --word-diff >actual &&
1317 git diff --word-diff >expect &&
1318 test_cmp expect actual
1321 test_expect_success 'set up whitespace tests' '
1323 # Note that these lines have no leading or trailing whitespace.
1324 cat <<-\EOF >lines.txt &&
1335 git add lines.txt &&
1336 git commit -m "add poetry" &&
1337 git config color.diff.oldMoved "magenta" &&
1338 git config color.diff.newMoved "cyan"
1341 test_expect_success 'move detection ignoring whitespace ' '
1342 q_to_tab <<-\EOF >lines.txt &&
1346 Qchanged long line 9
1353 git diff HEAD --no-renames --color-moved --color |
1355 test_decode_color >actual &&
1356 cat <<-\EOF >expected &&
1357 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1358 <BOLD>--- a/lines.txt<RESET>
1359 <BOLD>+++ b/lines.txt<RESET>
1360 <CYAN>@@ -1,9 +1,9 @@<RESET>
1361 <GREEN>+<RESET> <GREEN>long line 6<RESET>
1362 <GREEN>+<RESET> <GREEN>long line 7<RESET>
1363 <GREEN>+<RESET> <GREEN>long line 8<RESET>
1364 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1370 <RED>-long line 6<RESET>
1371 <RED>-long line 7<RESET>
1372 <RED>-long line 8<RESET>
1373 <RED>-long line 9<RESET>
1375 test_cmp expected actual &&
1377 git diff HEAD --no-renames -w --color-moved --color |
1379 test_decode_color >actual &&
1380 cat <<-\EOF >expected &&
1381 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1382 <BOLD>--- a/lines.txt<RESET>
1383 <BOLD>+++ b/lines.txt<RESET>
1384 <CYAN>@@ -1,9 +1,9 @@<RESET>
1385 <CYAN>+<RESET> <CYAN>long line 6<RESET>
1386 <CYAN>+<RESET> <CYAN>long line 7<RESET>
1387 <CYAN>+<RESET> <CYAN>long line 8<RESET>
1388 <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1394 <MAGENTA>-long line 6<RESET>
1395 <MAGENTA>-long line 7<RESET>
1396 <MAGENTA>-long line 8<RESET>
1397 <RED>-long line 9<RESET>
1399 test_cmp expected actual
1402 test_expect_success 'move detection ignoring whitespace changes' '
1404 # Lines 6-8 have a space change, but 9 is new whitespace
1405 q_to_tab <<-\EOF >lines.txt &&
1417 git diff HEAD --no-renames --color-moved --color |
1419 test_decode_color >actual &&
1420 cat <<-\EOF >expected &&
1421 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1422 <BOLD>--- a/lines.txt<RESET>
1423 <BOLD>+++ b/lines.txt<RESET>
1424 <CYAN>@@ -1,9 +1,9 @@<RESET>
1425 <GREEN>+<RESET><GREEN>long line 6<RESET>
1426 <GREEN>+<RESET><GREEN>long line 7<RESET>
1427 <GREEN>+<RESET><GREEN>long line 8<RESET>
1428 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1434 <RED>-long line 6<RESET>
1435 <RED>-long line 7<RESET>
1436 <RED>-long line 8<RESET>
1437 <RED>-long line 9<RESET>
1439 test_cmp expected actual &&
1441 git diff HEAD --no-renames -b --color-moved --color |
1443 test_decode_color >actual &&
1444 cat <<-\EOF >expected &&
1445 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1446 <BOLD>--- a/lines.txt<RESET>
1447 <BOLD>+++ b/lines.txt<RESET>
1448 <CYAN>@@ -1,9 +1,9 @@<RESET>
1449 <CYAN>+<RESET><CYAN>long line 6<RESET>
1450 <CYAN>+<RESET><CYAN>long line 7<RESET>
1451 <CYAN>+<RESET><CYAN>long line 8<RESET>
1452 <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1458 <MAGENTA>-long line 6<RESET>
1459 <MAGENTA>-long line 7<RESET>
1460 <MAGENTA>-long line 8<RESET>
1461 <RED>-long line 9<RESET>
1463 test_cmp expected actual
1466 test_expect_success 'move detection ignoring whitespace at eol' '
1468 # Lines 6-9 have new eol whitespace, but 9 also has it in the middle
1469 q_to_tab <<-\EOF >lines.txt &&
1481 # avoid cluttering the output with complaints about our eol whitespace
1482 test_config core.whitespace -blank-at-eol &&
1484 git diff HEAD --no-renames --color-moved --color |
1486 test_decode_color >actual &&
1487 cat <<-\EOF >expected &&
1488 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1489 <BOLD>--- a/lines.txt<RESET>
1490 <BOLD>+++ b/lines.txt<RESET>
1491 <CYAN>@@ -1,9 +1,9 @@<RESET>
1492 <GREEN>+<RESET><GREEN>long line 6 <RESET>
1493 <GREEN>+<RESET><GREEN>long line 7 <RESET>
1494 <GREEN>+<RESET><GREEN>long line 8 <RESET>
1495 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1501 <RED>-long line 6<RESET>
1502 <RED>-long line 7<RESET>
1503 <RED>-long line 8<RESET>
1504 <RED>-long line 9<RESET>
1506 test_cmp expected actual &&
1508 git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
1510 test_decode_color >actual &&
1511 cat <<-\EOF >expected &&
1512 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1513 <BOLD>--- a/lines.txt<RESET>
1514 <BOLD>+++ b/lines.txt<RESET>
1515 <CYAN>@@ -1,9 +1,9 @@<RESET>
1516 <CYAN>+<RESET><CYAN>long line 6 <RESET>
1517 <CYAN>+<RESET><CYAN>long line 7 <RESET>
1518 <CYAN>+<RESET><CYAN>long line 8 <RESET>
1519 <GREEN>+<RESET><GREEN>long line 9 <RESET>
1525 <MAGENTA>-long line 6<RESET>
1526 <MAGENTA>-long line 7<RESET>
1527 <MAGENTA>-long line 8<RESET>
1528 <RED>-long line 9<RESET>
1530 test_cmp expected actual
1533 test_expect_success 'clean up whitespace-test colors' '
1534 git config --unset color.diff.oldMoved &&
1535 git config --unset color.diff.newMoved
1538 test_expect_success '--color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1555 git diff HEAD --color-moved=zebra --color --no-renames |
1557 test_decode_color >actual &&
1558 cat >expected <<-\EOF &&
1559 <BOLD>diff --git a/bar b/bar<RESET>
1560 <BOLD>--- a/bar<RESET>
1561 <BOLD>+++ b/bar<RESET>
1562 <CYAN>@@ -0,0 +1 @@<RESET>
1563 <GREEN>+<RESET><GREEN>line1<RESET>
1564 <BOLD>diff --git a/foo b/foo<RESET>
1565 <BOLD>--- a/foo<RESET>
1566 <BOLD>+++ b/foo<RESET>
1567 <CYAN>@@ -1,2 +1 @@<RESET>
1568 irrelevant_line<RESET>
1572 test_cmp expected actual
1575 test_expect_success '--color-moved respects MIN_ALNUM_COUNT' '
1578 nineteen chars 456789
1580 twenty chars 234567890
1590 twenty chars 234567890
1591 nineteen chars 456789
1594 git diff HEAD --color-moved=zebra --color --no-renames |
1596 test_decode_color >actual &&
1597 cat >expected <<-\EOF &&
1598 <BOLD>diff --git a/bar b/bar<RESET>
1599 <BOLD>--- a/bar<RESET>
1600 <BOLD>+++ b/bar<RESET>
1601 <CYAN>@@ -0,0 +1,2 @@<RESET>
1602 <BOLD;CYAN>+<RESET><BOLD;CYAN>twenty chars 234567890<RESET>
1603 <GREEN>+<RESET><GREEN>nineteen chars 456789<RESET>
1604 <BOLD>diff --git a/foo b/foo<RESET>
1605 <BOLD>--- a/foo<RESET>
1606 <BOLD>+++ b/foo<RESET>
1607 <CYAN>@@ -1,3 +1 @@<RESET>
1608 <RED>-nineteen chars 456789<RESET>
1609 irrelevant_line<RESET>
1610 <BOLD;MAGENTA>-twenty chars 234567890<RESET>
1613 test_cmp expected actual
1616 test_expect_success '--color-moved treats adjacent blocks as separate for MIN_ALNUM_COUNT' '
1637 git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
1638 cat >expected <<-\EOF &&
1639 <BOLD>diff --git a/bar b/bar<RESET>
1640 <BOLD>--- a/bar<RESET>
1641 <BOLD>+++ b/bar<RESET>
1642 <CYAN>@@ -0,0 +1,3 @@<RESET>
1643 <GREEN>+<RESET><GREEN>7charsB<RESET>
1644 <GREEN>+<RESET><GREEN>7charsC<RESET>
1645 <GREEN>+<RESET><GREEN>7charsA<RESET>
1646 <BOLD>diff --git a/foo b/foo<RESET>
1647 <BOLD>--- a/foo<RESET>
1648 <BOLD>+++ b/foo<RESET>
1649 <CYAN>@@ -1,4 +1 @@<RESET>
1650 <RED>-7charsA<RESET>
1651 irrelevant_line<RESET>
1652 <RED>-7charsB<RESET>
1653 <RED>-7charsC<RESET>
1656 test_cmp expected actual
1659 test_expect_success 'move detection with submodules' '
1660 test_create_repo bananas &&
1661 echo ripe >bananas/recipe &&
1662 git -C bananas add recipe &&
1663 test_commit fruit &&
1664 test_commit -C bananas recipe &&
1665 git submodule add ./bananas &&
1667 git commit -a -m "bananas are like a heavy library?" &&
1668 echo foul >bananas/recipe &&
1669 echo ripe >fruit.t &&
1671 git diff --submodule=diff --color-moved --color >actual &&
1673 # no move detection as the moved line is across repository boundaries.
1674 test_decode_color <actual >decoded_actual &&
1675 ! grep BGREEN decoded_actual &&
1676 ! grep BRED decoded_actual &&
1678 # nor did we mess with it another way
1679 git diff --submodule=diff --color | test_decode_color >expect &&
1680 test_cmp expect decoded_actual