@@ -16,6 +16,7 @@ test_expect_success "Ray Lehtiniemi's example" '
16
16
} while (0);
17
17
EOF
18
18
git update-index --add x &&
19
+ before=$(git rev-parse --short $(git hash-object x)) &&
19
20
20
21
cat <<-\EOF >x &&
21
22
do
@@ -24,10 +25,11 @@ test_expect_success "Ray Lehtiniemi's example" '
24
25
}
25
26
while (0);
26
27
EOF
28
+ after=$(git rev-parse --short $(git hash-object x)) &&
27
29
28
- cat <<-\ EOF >expect &&
30
+ cat <<-EOF >expect &&
29
31
diff --git a/x b/x
30
- index adf3937..6edc172 100644
32
+ index $before..$after 100644
31
33
--- a/x
32
34
+++ b/x
33
35
@@ -1,3 +1,5 @@
@@ -61,6 +63,7 @@ test_expect_success 'another test, without options' '
61
63
EOF
62
64
63
65
git update-index x &&
66
+ before=$(git rev-parse --short $(git hash-object x)) &&
64
67
65
68
tr "_" " " <<-\EOF >x &&
66
69
_ whitespace at beginning
@@ -70,10 +73,11 @@ test_expect_success 'another test, without options' '
70
73
unchanged line
71
74
CR at end
72
75
EOF
76
+ after=$(git rev-parse --short $(git hash-object x)) &&
73
77
74
- tr "Q_" "\015 " <<-\ EOF >expect &&
78
+ tr "Q_" "\015 " <<-EOF >expect &&
75
79
diff --git a/x b/x
76
- index d99af23..22d9f73 100644
80
+ index $before..$after 100644
77
81
--- a/x
78
82
+++ b/x
79
83
@@ -1,6 +1,6 @@
@@ -108,9 +112,9 @@ test_expect_success 'another test, without options' '
108
112
git diff -w --ignore-cr-at-eol >out &&
109
113
test_must_be_empty out &&
110
114
111
- tr "Q_" "\015 " <<-\ EOF >expect &&
115
+ tr "Q_" "\015 " <<-EOF >expect &&
112
116
diff --git a/x b/x
113
- index d99af23..22d9f73 100644
117
+ index $before..$after 100644
114
118
--- a/x
115
119
+++ b/x
116
120
@@ -1,6 +1,6 @@
@@ -132,9 +136,9 @@ test_expect_success 'another test, without options' '
132
136
git diff -b --ignore-cr-at-eol >out &&
133
137
test_cmp expect out &&
134
138
135
- tr "Q_" "\015 " <<-\ EOF >expect &&
139
+ tr "Q_" "\015 " <<-EOF >expect &&
136
140
diff --git a/x b/x
137
- index d99af23..22d9f73 100644
141
+ index $before..$after 100644
138
142
--- a/x
139
143
+++ b/x
140
144
@@ -1,6 +1,6 @@
@@ -154,9 +158,9 @@ test_expect_success 'another test, without options' '
154
158
git diff --ignore-space-at-eol --ignore-cr-at-eol >out &&
155
159
test_cmp expect out &&
156
160
157
- tr "Q_" "\015 " <<-\ EOF >expect &&
161
+ tr "Q_" "\015 " <<-EOF >expect &&
158
162
diff --git a/x b/x
159
- index_d99af23..22d9f73 100644
163
+ index_$before..$after 100644
160
164
--- a/x
161
165
+++ b/x
162
166
@@ -1,6 +1,6 @@
@@ -786,23 +790,25 @@ test_expect_success 'whitespace-only changes not reported' '
786
790
test_must_be_empty actual
787
791
'
788
792
789
- cat << EOF >expect
790
- diff --git a/x b/z
791
- similarity index NUM%
792
- rename from x
793
- rename to z
794
- index 380c32a..a97b785 100644
795
- EOF
796
793
test_expect_success ' whitespace-only changes reported across renames' '
797
794
git reset --hard &&
798
795
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
799
796
git add x &&
797
+ before=$(git rev-parse --short $(git hash-object x)) &&
800
798
git commit -m "base" &&
801
799
sed -e "5s/^/ /" x >z &&
802
800
git rm x &&
803
801
git add z &&
802
+ after=$(git rev-parse --short $(git hash-object z)) &&
804
803
git diff -w -M --cached |
805
804
sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
805
+ cat <<-EOF >expect &&
806
+ diff --git a/x b/z
807
+ similarity index NUM%
808
+ rename from x
809
+ rename to z
810
+ index $before..$after 100644
811
+ EOF
806
812
test_cmp expect actual
807
813
'
808
814
@@ -858,13 +864,15 @@ test_expect_success 'diff that introduces a line with only tabs' '
858
864
git config core.whitespace blank-at-eol &&
859
865
git reset --hard &&
860
866
echo "test" >x &&
867
+ before=$(git rev-parse --short $(git hash-object x)) &&
861
868
git commit -m "initial" x &&
862
869
echo "{NTN}" | tr "NT" "\n\t" >>x &&
870
+ after=$(git rev-parse --short $(git hash-object x)) &&
863
871
git diff --color | test_decode_color >current &&
864
872
865
- cat >expected <<-\ EOF &&
873
+ cat >expected <<-EOF &&
866
874
<BOLD>diff --git a/x b/x<RESET>
867
- <BOLD>index 9daeafb..2874b91 100644<RESET>
875
+ <BOLD>index $before..$after 100644<RESET>
868
876
<BOLD>--- a/x<RESET>
869
877
<BOLD>+++ b/x<RESET>
870
878
<CYAN>@@ -1 +1,4 @@<RESET>
@@ -883,19 +891,21 @@ test_expect_success 'diff that introduces and removes ws breakages' '
883
891
echo "0. blank-at-eol " &&
884
892
echo "1. blank-at-eol "
885
893
} >x &&
894
+ before=$(git rev-parse --short $(git hash-object x)) &&
886
895
git commit -a --allow-empty -m preimage &&
887
896
{
888
897
echo "0. blank-at-eol " &&
889
898
echo "1. still-blank-at-eol " &&
890
899
echo "2. and a new line "
891
900
} >x &&
901
+ after=$(git rev-parse --short $(git hash-object x)) &&
892
902
893
903
git diff --color |
894
904
test_decode_color >current &&
895
905
896
- cat >expected <<-\ EOF &&
906
+ cat >expected <<-EOF &&
897
907
<BOLD>diff --git a/x b/x<RESET>
898
- <BOLD>index d0233a2..700886e 100644<RESET>
908
+ <BOLD>index $before..$after 100644<RESET>
899
909
<BOLD>--- a/x<RESET>
900
910
<BOLD>+++ b/x<RESET>
901
911
<CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -915,16 +925,18 @@ test_expect_success 'ws-error-highlight test setup' '
915
925
echo "0. blank-at-eol " &&
916
926
echo "1. blank-at-eol "
917
927
} >x &&
928
+ before=$(git rev-parse --short $(git hash-object x)) &&
918
929
git commit -a --allow-empty -m preimage &&
919
930
{
920
931
echo "0. blank-at-eol " &&
921
932
echo "1. still-blank-at-eol " &&
922
933
echo "2. and a new line "
923
934
} >x &&
935
+ after=$(git rev-parse --short $(git hash-object x)) &&
924
936
925
- cat >expect.default-old <<-\ EOF &&
937
+ cat >expect.default-old <<-EOF &&
926
938
<BOLD>diff --git a/x b/x<RESET>
927
- <BOLD>index d0233a2..700886e 100644<RESET>
939
+ <BOLD>index $before..$after 100644<RESET>
928
940
<BOLD>--- a/x<RESET>
929
941
<BOLD>+++ b/x<RESET>
930
942
<CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -934,9 +946,9 @@ test_expect_success 'ws-error-highlight test setup' '
934
946
<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
935
947
EOF
936
948
937
- cat >expect.all <<-\ EOF &&
949
+ cat >expect.all <<-EOF &&
938
950
<BOLD>diff --git a/x b/x<RESET>
939
- <BOLD>index d0233a2..700886e 100644<RESET>
951
+ <BOLD>index $before..$after 100644<RESET>
940
952
<BOLD>--- a/x<RESET>
941
953
<BOLD>+++ b/x<RESET>
942
954
<CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -946,9 +958,9 @@ test_expect_success 'ws-error-highlight test setup' '
946
958
<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
947
959
EOF
948
960
949
- cat >expect.none <<-\ EOF
961
+ cat >expect.none <<-EOF
950
962
<BOLD>diff --git a/x b/x<RESET>
951
- <BOLD>index d0233a2..700886e 100644<RESET>
963
+ <BOLD>index $before..$after 100644<RESET>
952
964
<BOLD>--- a/x<RESET>
953
965
<BOLD>+++ b/x<RESET>
954
966
<CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -1022,14 +1034,15 @@ test_expect_success 'detect moved code, complete file' '
1022
1034
EOF
1023
1035
git add test.c &&
1024
1036
git commit -m "add main function" &&
1037
+ file=$(git rev-parse --short HEAD:test.c) &&
1025
1038
git mv test.c main.c &&
1026
1039
test_config color.diff.oldMoved "normal red" &&
1027
1040
test_config color.diff.newMoved "normal green" &&
1028
1041
git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1029
- cat >expected <<-\ EOF &&
1042
+ cat >expected <<-EOF &&
1030
1043
<BOLD>diff --git a/main.c b/main.c<RESET>
1031
1044
<BOLD>new file mode 100644<RESET>
1032
- <BOLD>index 0000000..a986c57 <RESET>
1045
+ <BOLD>index 0000000..$file <RESET>
1033
1046
<BOLD>--- /dev/null<RESET>
1034
1047
<BOLD>+++ b/main.c<RESET>
1035
1048
<CYAN>@@ -0,0 +1,5 @@<RESET>
@@ -1040,7 +1053,7 @@ test_expect_success 'detect moved code, complete file' '
1040
1053
<BGREEN>+<RESET><BGREEN>}<RESET>
1041
1054
<BOLD>diff --git a/test.c b/test.c<RESET>
1042
1055
<BOLD>deleted file mode 100644<RESET>
1043
- <BOLD>index a986c57 ..0000000<RESET>
1056
+ <BOLD>index $file ..0000000<RESET>
1044
1057
<BOLD>--- a/test.c<RESET>
1045
1058
<BOLD>+++ /dev/null<RESET>
1046
1059
<CYAN>@@ -1,5 +0,0 @@<RESET>
@@ -1094,6 +1107,8 @@ test_expect_success 'detect malicious moved code, inside file' '
1094
1107
EOF
1095
1108
git add main.c test.c &&
1096
1109
git commit -m "add main and test file" &&
1110
+ before_main=$(git rev-parse --short HEAD:main.c) &&
1111
+ before_test=$(git rev-parse --short HEAD:test.c) &&
1097
1112
cat <<-\EOF >main.c &&
1098
1113
#include<stdio.h>
1099
1114
int stuff()
@@ -1126,10 +1141,12 @@ test_expect_success 'detect malicious moved code, inside file' '
1126
1141
bar();
1127
1142
}
1128
1143
EOF
1144
+ after_main=$(git rev-parse --short $(git hash-object main.c)) &&
1145
+ after_test=$(git rev-parse --short $(git hash-object test.c)) &&
1129
1146
git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1130
- cat <<-\ EOF >expected &&
1147
+ cat <<-EOF >expected &&
1131
1148
<BOLD>diff --git a/main.c b/main.c<RESET>
1132
- <BOLD>index 27a619c..7cf9336 100644<RESET>
1149
+ <BOLD>index $before_main..$after_main 100644<RESET>
1133
1150
<BOLD>--- a/main.c<RESET>
1134
1151
<BOLD>+++ b/main.c<RESET>
1135
1152
<CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
@@ -1147,7 +1164,7 @@ test_expect_success 'detect malicious moved code, inside file' '
1147
1164
{<RESET>
1148
1165
foo();<RESET>
1149
1166
<BOLD>diff --git a/test.c b/test.c<RESET>
1150
- <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1167
+ <BOLD>index $before_test..$after_test 100644<RESET>
1151
1168
<BOLD>--- a/test.c<RESET>
1152
1169
<BOLD>+++ b/test.c<RESET>
1153
1170
<CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
@@ -1176,9 +1193,9 @@ test_expect_success 'plain moved code, inside file' '
1176
1193
test_config color.diff.newMovedAlternative "yellow" &&
1177
1194
# needs previous test as setup
1178
1195
git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1179
- cat <<-\ EOF >expected &&
1196
+ cat <<-EOF >expected &&
1180
1197
<BOLD>diff --git a/main.c b/main.c<RESET>
1181
- <BOLD>index 27a619c..7cf9336 100644<RESET>
1198
+ <BOLD>index $before_main..$after_main 100644<RESET>
1182
1199
<BOLD>--- a/main.c<RESET>
1183
1200
<BOLD>+++ b/main.c<RESET>
1184
1201
<CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
@@ -1196,7 +1213,7 @@ test_expect_success 'plain moved code, inside file' '
1196
1213
{<RESET>
1197
1214
foo();<RESET>
1198
1215
<BOLD>diff --git a/test.c b/test.c<RESET>
1199
- <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1216
+ <BOLD>index $before_test..$after_test 100644<RESET>
1200
1217
<BOLD>--- a/test.c<RESET>
1201
1218
<BOLD>+++ b/test.c<RESET>
1202
1219
<CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
0 commit comments