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 always &&
806 git config color.diff.plain normal &&
807 git config color.diff.meta bold &&
808 git config color.diff.frag cyan &&
809 git config color.diff.func normal &&
810 git config color.diff.old red &&
811 git config color.diff.new green &&
812 git config color.diff.commit yellow &&
813 git config color.diff.whitespace blue &&
815 git config core.autocrlf false
818 test_expect_success
'diff that introduces a line with only tabs' '
819 git config core.whitespace blank-at-eol &&
822 git commit -m "initial" x &&
823 echo "{NTN}" | tr "NT" "\n\t" >>x &&
824 git -c color.diff=always diff | test_decode_color >current &&
826 cat >expected <<-\EOF &&
827 <BOLD>diff --git a/x b/x<RESET>
828 <BOLD>index 9daeafb..2874b91 100644<RESET>
831 <CYAN>@@ -1 +1,4 @@<RESET>
833 <GREEN>+<RESET><GREEN>{<RESET>
834 <GREEN>+<RESET><BLUE> <RESET>
835 <GREEN>+<RESET><GREEN>}<RESET>
838 test_cmp expected current
841 test_expect_success
'diff that introduces and removes ws breakages' '
844 echo "0. blank-at-eol " &&
845 echo "1. blank-at-eol "
847 git commit -a --allow-empty -m preimage &&
849 echo "0. blank-at-eol " &&
850 echo "1. still-blank-at-eol " &&
851 echo "2. and a new line "
854 git -c color.diff=always diff |
855 test_decode_color >current &&
857 cat >expected <<-\EOF &&
858 <BOLD>diff --git a/x b/x<RESET>
859 <BOLD>index d0233a2..700886e 100644<RESET>
862 <CYAN>@@ -1,2 +1,3 @@<RESET>
863 0. blank-at-eol <RESET>
864 <RED>-1. blank-at-eol <RESET>
865 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
866 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
869 test_cmp expected current
872 test_expect_success
'ws-error-highlight test setup' '
876 echo "0. blank-at-eol " &&
877 echo "1. blank-at-eol "
879 git commit -a --allow-empty -m preimage &&
881 echo "0. blank-at-eol " &&
882 echo "1. still-blank-at-eol " &&
883 echo "2. and a new line "
886 cat >expect.default-old <<-\EOF &&
887 <BOLD>diff --git a/x b/x<RESET>
888 <BOLD>index d0233a2..700886e 100644<RESET>
891 <CYAN>@@ -1,2 +1,3 @@<RESET>
892 0. blank-at-eol <RESET>
893 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
894 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
895 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
898 cat >expect.all <<-\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 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
905 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <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 cat >expect.none <<-\EOF
911 <BOLD>diff --git a/x b/x<RESET>
912 <BOLD>index d0233a2..700886e 100644<RESET>
915 <CYAN>@@ -1,2 +1,3 @@<RESET>
916 0. blank-at-eol <RESET>
917 <RED>-1. blank-at-eol <RESET>
918 <GREEN>+1. still-blank-at-eol <RESET>
919 <GREEN>+2. and a new line <RESET>
924 test_expect_success
'test --ws-error-highlight option' '
926 git -c color.diff=always diff --ws-error-highlight=default,old |
927 test_decode_color >current &&
928 test_cmp expect.default-old current &&
930 git -c color.diff=always diff --ws-error-highlight=all |
931 test_decode_color >current &&
932 test_cmp expect.all current &&
934 git -c color.diff=always diff --ws-error-highlight=none |
935 test_decode_color >current &&
936 test_cmp expect.none current
940 test_expect_success
'test diff.wsErrorHighlight config' '
942 git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
943 test_decode_color >current &&
944 test_cmp expect.default-old current &&
946 git -c color.diff=always -c diff.wsErrorHighlight=all diff |
947 test_decode_color >current &&
948 test_cmp expect.all current &&
950 git -c color.diff=always -c diff.wsErrorHighlight=none diff |
951 test_decode_color >current &&
952 test_cmp expect.none current
956 test_expect_success
'option overrides diff.wsErrorHighlight' '
958 git -c color.diff=always -c diff.wsErrorHighlight=none \
959 diff --ws-error-highlight=default,old |
960 test_decode_color >current &&
961 test_cmp expect.default-old current &&
963 git -c color.diff=always -c diff.wsErrorHighlight=default \
964 diff --ws-error-highlight=all |
965 test_decode_color >current &&
966 test_cmp expect.all current &&
968 git -c color.diff=always -c diff.wsErrorHighlight=all \
969 diff --ws-error-highlight=none |
970 test_decode_color >current &&
971 test_cmp expect.none current
975 test_expect_success
'detect moved code, complete file' '
977 cat <<-\EOF >test.c &&
981 printf("Hello World");
985 git commit -m "add main function" &&
986 git mv test.c main.c &&
987 test_config color.diff.oldMoved "normal red" &&
988 test_config color.diff.newMoved "normal green" &&
989 git diff HEAD --color-moved=zebra --no-renames | test_decode_color >actual &&
990 cat >expected <<-\EOF &&
991 <BOLD>diff --git a/main.c b/main.c<RESET>
992 <BOLD>new file mode 100644<RESET>
993 <BOLD>index 0000000..a986c57<RESET>
994 <BOLD>--- /dev/null<RESET>
995 <BOLD>+++ b/main.c<RESET>
996 <CYAN>@@ -0,0 +1,5 @@<RESET>
997 <BGREEN>+<RESET><BGREEN>#include<stdio.h><RESET>
998 <BGREEN>+<RESET><BGREEN>main()<RESET>
999 <BGREEN>+<RESET><BGREEN>{<RESET>
1000 <BGREEN>+<RESET><BGREEN>printf("Hello World");<RESET>
1001 <BGREEN>+<RESET><BGREEN>}<RESET>
1002 <BOLD>diff --git a/test.c b/test.c<RESET>
1003 <BOLD>deleted file mode 100644<RESET>
1004 <BOLD>index a986c57..0000000<RESET>
1005 <BOLD>--- a/test.c<RESET>
1006 <BOLD>+++ /dev/null<RESET>
1007 <CYAN>@@ -1,5 +0,0 @@<RESET>
1008 <BRED>-#include<stdio.h><RESET>
1009 <BRED>-main()<RESET>
1011 <BRED>-printf("Hello World");<RESET>
1015 test_cmp expected actual
1018 test_expect_success
'detect malicious moved code, inside file' '
1019 test_config color.diff.oldMoved "normal red" &&
1020 test_config color.diff.newMoved "normal green" &&
1021 test_config color.diff.oldMovedAlternative "blue" &&
1022 test_config color.diff.newMovedAlternative "yellow" &&
1024 cat <<-\EOF >main.c &&
1032 int secure_foo(struct user *u)
1034 if (!u->is_allowed_foo)
1044 cat <<-\EOF >test.c &&
1048 printf("Hello World, but different\n");
1051 int another_function()
1056 git add main.c test.c &&
1057 git commit -m "add main and test file" &&
1058 cat <<-\EOF >main.c &&
1071 cat <<-\EOF >test.c &&
1075 printf("Hello World, but different\n");
1078 int secure_foo(struct user *u)
1081 if (!u->is_allowed_foo)
1085 int another_function()
1090 git diff HEAD --no-renames --color-moved=zebra| test_decode_color >actual &&
1091 cat <<-\EOF >expected &&
1092 <BOLD>diff --git a/main.c b/main.c<RESET>
1093 <BOLD>index 27a619c..7cf9336 100644<RESET>
1094 <BOLD>--- a/main.c<RESET>
1095 <BOLD>+++ b/main.c<RESET>
1096 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1097 printf("World\n");<RESET>
1100 <BRED>-int secure_foo(struct user *u)<RESET>
1102 <BLUE>-if (!u->is_allowed_foo)<RESET>
1103 <BLUE>-return;<RESET>
1104 <RED>-foo(u);<RESET>
1110 <BOLD>diff --git a/test.c b/test.c<RESET>
1111 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1112 <BOLD>--- a/test.c<RESET>
1113 <BOLD>+++ b/test.c<RESET>
1114 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1115 printf("Hello World, but different\n");<RESET>
1118 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1119 <BGREEN>+<RESET><BGREEN>{<RESET>
1120 <GREEN>+<RESET><GREEN>foo(u);<RESET>
1121 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1122 <BGREEN>+<RESET><BGREEN>return;<RESET>
1123 <GREEN>+<RESET><GREEN>}<RESET>
1125 int another_function()<RESET>
1130 test_cmp expected actual
1133 test_expect_success
'plain moved code, inside file' '
1134 test_config color.diff.oldMoved "normal red" &&
1135 test_config color.diff.newMoved "normal green" &&
1136 test_config color.diff.oldMovedAlternative "blue" &&
1137 test_config color.diff.newMovedAlternative "yellow" &&
1138 # needs previous test as setup
1139 git diff HEAD --no-renames --color-moved=plain| test_decode_color >actual &&
1140 cat <<-\EOF >expected &&
1141 <BOLD>diff --git a/main.c b/main.c<RESET>
1142 <BOLD>index 27a619c..7cf9336 100644<RESET>
1143 <BOLD>--- a/main.c<RESET>
1144 <BOLD>+++ b/main.c<RESET>
1145 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
1146 printf("World\n");<RESET>
1149 <BRED>-int secure_foo(struct user *u)<RESET>
1151 <BRED>-if (!u->is_allowed_foo)<RESET>
1152 <BRED>-return;<RESET>
1153 <BRED>-foo(u);<RESET>
1159 <BOLD>diff --git a/test.c b/test.c<RESET>
1160 <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1161 <BOLD>--- a/test.c<RESET>
1162 <BOLD>+++ b/test.c<RESET>
1163 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
1164 printf("Hello World, but different\n");<RESET>
1167 <BGREEN>+<RESET><BGREEN>int secure_foo(struct user *u)<RESET>
1168 <BGREEN>+<RESET><BGREEN>{<RESET>
1169 <BGREEN>+<RESET><BGREEN>foo(u);<RESET>
1170 <BGREEN>+<RESET><BGREEN>if (!u->is_allowed_foo)<RESET>
1171 <BGREEN>+<RESET><BGREEN>return;<RESET>
1172 <BGREEN>+<RESET><BGREEN>}<RESET>
1174 int another_function()<RESET>
1179 test_cmp expected actual
1182 test_expect_success
'detect permutations inside moved code -- dimmed_zebra' '
1184 cat <<-\EOF >lines.txt &&
1202 git add lines.txt &&
1203 git commit -m "add poetry" &&
1204 cat <<-\EOF >lines.txt &&
1222 test_config color.diff.oldMoved "magenta" &&
1223 test_config color.diff.newMoved "cyan" &&
1224 test_config color.diff.oldMovedAlternative "blue" &&
1225 test_config color.diff.newMovedAlternative "yellow" &&
1226 test_config color.diff.oldMovedDimmed "normal magenta" &&
1227 test_config color.diff.newMovedDimmed "normal cyan" &&
1228 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1229 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1230 git diff HEAD --no-renames --color-moved=dimmed_zebra |
1232 test_decode_color >actual &&
1233 cat <<-\EOF >expected &&
1234 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1235 <BOLD>--- a/lines.txt<RESET>
1236 <BOLD>+++ b/lines.txt<RESET>
1237 <CYAN>@@ -1,16 +1,16 @@<RESET>
1238 <BMAGENTA>-long line 1<RESET>
1239 <BMAGENTA>-long line 2<RESET>
1240 <BMAGENTA>-long line 3<RESET>
1247 <BCYAN>+<RESET><BCYAN>long line 1<RESET>
1248 <BCYAN>+<RESET><BCYAN>long line 2<RESET>
1249 <CYAN>+<RESET><CYAN>long line 3<RESET>
1250 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1251 <BYELLOW>+<RESET><BYELLOW>long line 15<RESET>
1252 <BYELLOW>+<RESET><BYELLOW>long line 16<RESET>
1257 <BMAGENTA>-long line 14<RESET>
1258 <BMAGENTA>-long line 15<RESET>
1259 <BMAGENTA>-long line 16<RESET>
1261 test_cmp expected actual
1264 test_expect_success
'cmd option assumes configured colored-moved' '
1265 test_config color.diff.oldMoved "magenta" &&
1266 test_config color.diff.newMoved "cyan" &&
1267 test_config color.diff.oldMovedAlternative "blue" &&
1268 test_config color.diff.newMovedAlternative "yellow" &&
1269 test_config color.diff.oldMovedDimmed "normal magenta" &&
1270 test_config color.diff.newMovedDimmed "normal cyan" &&
1271 test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
1272 test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1273 test_config diff.colorMoved zebra &&
1274 git diff HEAD --no-renames --color-moved |
1276 test_decode_color >actual &&
1277 cat <<-\EOF >expected &&
1278 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1279 <BOLD>--- a/lines.txt<RESET>
1280 <BOLD>+++ b/lines.txt<RESET>
1281 <CYAN>@@ -1,16 +1,16 @@<RESET>
1282 <MAGENTA>-long line 1<RESET>
1283 <MAGENTA>-long line 2<RESET>
1284 <MAGENTA>-long line 3<RESET>
1291 <CYAN>+<RESET><CYAN>long line 1<RESET>
1292 <CYAN>+<RESET><CYAN>long line 2<RESET>
1293 <CYAN>+<RESET><CYAN>long line 3<RESET>
1294 <YELLOW>+<RESET><YELLOW>long line 14<RESET>
1295 <YELLOW>+<RESET><YELLOW>long line 15<RESET>
1296 <YELLOW>+<RESET><YELLOW>long line 16<RESET>
1301 <MAGENTA>-long line 14<RESET>
1302 <MAGENTA>-long line 15<RESET>
1303 <MAGENTA>-long line 16<RESET>
1305 test_cmp expected actual
1308 test_expect_success
'no effect from --color-moved with --word-diff' '
1309 cat <<-\EOF >text.txt &&
1310 Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1313 git commit -a -m "clean state" &&
1314 cat <<-\EOF >text.txt &&
1315 simply Lorem Ipsum dummy is text of the typesetting and printing industry.
1317 git diff --color-moved --word-diff >actual &&
1318 git diff --word-diff >expect &&
1319 test_cmp expect actual
1322 test_expect_success
'move detection ignoring whitespace ' '
1324 cat <<\EOF >lines.txt &&
1333 git add lines.txt &&
1334 git commit -m "add poetry" &&
1335 cat <<\EOF >lines.txt &&
1344 test_config color.diff.oldMoved "magenta" &&
1345 test_config color.diff.newMoved "cyan" &&
1346 git diff HEAD --no-renames --color-moved |
1348 test_decode_color >actual &&
1349 cat <<-\EOF >expected &&
1350 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1351 <BOLD>--- a/lines.txt<RESET>
1352 <BOLD>+++ b/lines.txt<RESET>
1353 <CYAN>@@ -1,7 +1,7 @@<RESET>
1354 <GREEN>+<RESET> <GREEN>long line 5<RESET>
1355 <GREEN>+<RESET> <GREEN>long line 6<RESET>
1356 <GREEN>+<RESET> <GREEN>long line 7<RESET>
1361 <RED>-long line 5<RESET>
1362 <RED>-long line 6<RESET>
1363 <RED>-long line 7<RESET>
1365 test_cmp expected actual &&
1367 git diff HEAD --no-renames -w --color-moved |
1369 test_decode_color >actual &&
1370 cat <<-\EOF >expected &&
1371 <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1372 <BOLD>--- a/lines.txt<RESET>
1373 <BOLD>+++ b/lines.txt<RESET>
1374 <CYAN>@@ -1,7 +1,7 @@<RESET>
1375 <CYAN>+<RESET> <CYAN>long line 5<RESET>
1376 <CYAN>+<RESET> <CYAN>long line 6<RESET>
1377 <CYAN>+<RESET> <CYAN>long line 7<RESET>
1382 <MAGENTA>-long line 5<RESET>
1383 <MAGENTA>-long line 6<RESET>
1384 <MAGENTA>-long line 7<RESET>
1386 test_cmp expected actual
1389 test_expect_success
'--color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1406 git diff HEAD --color-moved=zebra --no-renames |
1408 test_decode_color >actual &&
1409 cat >expected <<-\EOF &&
1410 <BOLD>diff --git a/bar b/bar<RESET>
1411 <BOLD>--- a/bar<RESET>
1412 <BOLD>+++ b/bar<RESET>
1413 <CYAN>@@ -0,0 +1 @@<RESET>
1414 <GREEN>+<RESET><GREEN>line1<RESET>
1415 <BOLD>diff --git a/foo b/foo<RESET>
1416 <BOLD>--- a/foo<RESET>
1417 <BOLD>+++ b/foo<RESET>
1418 <CYAN>@@ -1,2 +1 @@<RESET>
1419 irrelevant_line<RESET>
1423 test_cmp expected actual
1426 test_expect_success
'--color-moved respects MIN_ALNUM_COUNT' '
1429 nineteen chars 456789
1431 twenty chars 234567890
1441 twenty chars 234567890
1442 nineteen chars 456789
1445 git diff HEAD --color-moved=zebra --no-renames |
1447 test_decode_color >actual &&
1448 cat >expected <<-\EOF &&
1449 <BOLD>diff --git a/bar b/bar<RESET>
1450 <BOLD>--- a/bar<RESET>
1451 <BOLD>+++ b/bar<RESET>
1452 <CYAN>@@ -0,0 +1,2 @@<RESET>
1453 <BOLD;CYAN>+<RESET><BOLD;CYAN>twenty chars 234567890<RESET>
1454 <GREEN>+<RESET><GREEN>nineteen chars 456789<RESET>
1455 <BOLD>diff --git a/foo b/foo<RESET>
1456 <BOLD>--- a/foo<RESET>
1457 <BOLD>+++ b/foo<RESET>
1458 <CYAN>@@ -1,3 +1 @@<RESET>
1459 <RED>-nineteen chars 456789<RESET>
1460 irrelevant_line<RESET>
1461 <BOLD;MAGENTA>-twenty chars 234567890<RESET>
1464 test_cmp expected actual
1467 test_expect_success
'--color-moved treats adjacent blocks as separate for MIN_ALNUM_COUNT' '
1488 git diff HEAD --color-moved=zebra --no-renames | grep -v "index" | test_decode_color >actual &&
1489 cat >expected <<-\EOF &&
1490 <BOLD>diff --git a/bar b/bar<RESET>
1491 <BOLD>--- a/bar<RESET>
1492 <BOLD>+++ b/bar<RESET>
1493 <CYAN>@@ -0,0 +1,3 @@<RESET>
1494 <GREEN>+<RESET><GREEN>7charsB<RESET>
1495 <GREEN>+<RESET><GREEN>7charsC<RESET>
1496 <GREEN>+<RESET><GREEN>7charsA<RESET>
1497 <BOLD>diff --git a/foo b/foo<RESET>
1498 <BOLD>--- a/foo<RESET>
1499 <BOLD>+++ b/foo<RESET>
1500 <CYAN>@@ -1,4 +1 @@<RESET>
1501 <RED>-7charsA<RESET>
1502 irrelevant_line<RESET>
1503 <RED>-7charsB<RESET>
1504 <RED>-7charsC<RESET>
1507 test_cmp expected actual
1510 test_expect_success
'move detection with submodules' '
1511 test_create_repo bananas &&
1512 echo ripe >bananas/recipe &&
1513 git -C bananas add recipe &&
1514 test_commit fruit &&
1515 test_commit -C bananas recipe &&
1516 git submodule add ./bananas &&
1518 git commit -a -m "bananas are like a heavy library?" &&
1519 echo foul >bananas/recipe &&
1520 echo ripe >fruit.t &&
1522 git diff --submodule=diff --color-moved >actual &&
1524 # no move detection as the moved line is across repository boundaries.
1525 test_decode_color <actual >decoded_actual &&
1526 ! grep BGREEN decoded_actual &&
1527 ! grep BRED decoded_actual &&
1529 # nor did we mess with it another way
1530 git diff --submodule=diff | test_decode_color >expect &&
1531 test_cmp expect decoded_actual