Skip to content

Commit 18374e5

Browse files
committed
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>
1 parent e636106 commit 18374e5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

diff.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,12 +1150,14 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
11501150
char *err;
11511151

11521152
if (line[0] == '+') {
1153+
unsigned bad;
11531154
data->lineno++;
1154-
data->status = check_and_emit_line(line + 1, len - 1,
1155+
bad = check_and_emit_line(line + 1, len - 1,
11551156
data->ws_rule, NULL, NULL, NULL, NULL);
1156-
if (!data->status)
1157+
if (!bad)
11571158
return;
1158-
err = whitespace_error_string(data->status);
1159+
data->status |= bad;
1160+
err = whitespace_error_string(bad);
11591161
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
11601162
free(err);
11611163
emit_line(data->file, set, reset, line, 1);

t/t4017-diff-retval.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' '
105105
106106
'
107107

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+
108116
test_done

0 commit comments

Comments
 (0)