Fix "diff --check" whitespace detection
"diff --check" would only detect spaces before tabs if a tab was the last character in the leading indent. Fix that and add a test case to make sure the bug doesn't regress in the future. Signed-off-by: Wincent Colaiuta <win@wincent.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Wincent Colaiuta committed
Dec 12, 2007 at 17:22 UTC
86f8c2368523db5ee56c8856748b26c31ebeb0aa
2 files changed
+19
-3
diff.c
+10
-3
@@ -1044,11 +1044,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1044
int i, spaces = 0, space_before_tab = 0, white_space_at_end = 0;
1045
1046
/* check space before tab */
1047
- for (i = 1; i < len && (line[i] == ' ' || line[i] == '\t'); i++)
1047
+ for (i = 1; i < len; i++) {
1048
if (line[i] == ' ')
1049
spaces++;
1050
- if (line[i - 1] == '\t' && spaces)
1051
- space_before_tab = 1;
1050
+ else if (line[i] == '\t') {
1051
+ if (spaces) {
1052
+ space_before_tab = 1;
1053
+ break;
1054
+ }
1055
+ }
1056
+ else
1057
+ break;
1058
+ }
1059
1060
/* check whitespace at line end */
1061
if (line[len - 1] == '\n')
t/t4015-diff-whitespace.sh
+9
@@ -117,4 +117,13 @@ EOF
117
git diff -b > out
118
test_expect_success 'another test, with -b' 'git diff expect out'
119
120
+
121
+test_expect_success 'check mixed spaces and tabs in indent' '
122
+
123
+ # This is indented with SP HT SP.
124
+ echo " foo();" > x &&
125
+ git diff --check | grep "space before tab"
126
+
127
+'
128
+
129
test_done