diff --check: do not discard error status upon seeing a good line
"git diff --check" should return non-zero when there was any whitespace error but the code only paid attention to the error status of the last new line in the patch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 26, 2008 at 13:16 UTC
18374e584ca7a820457c1d83ee99867c216e7b75
2 files changed
+13
-3
diff.c
+5
-3
@@ -1150,12 +1150,14 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1150
char *err;
1151
1152
if (line[0] == '+') {
1153
+ unsigned bad;
1154
data->lineno++;
1154
- data->status = check_and_emit_line(line + 1, len - 1,
1155
+ bad = check_and_emit_line(line + 1, len - 1,
1156
data->ws_rule, NULL, NULL, NULL, NULL);
1156
- if (!data->status)
1157
+ if (!bad)
1158
return;
1158
- err = whitespace_error_string(data->status);
1159
+ data->status |= bad;
1160
+ err = whitespace_error_string(bad);
1161
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
1162
free(err);
1163
emit_line(data->file, set, reset, line, 1);
t/t4017-diff-retval.sh
+8
@@ -105,4 +105,12 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' '
105
106
'
107
108
+
109
+test_expect_success 'check should test not just the last line' '
110
+ echo "" >>a &&
111
+ git --no-pager diff --check
112
+ test $? = 2
113
+
114
+'
115
+
116
test_done