Commits

Junio C Hamano  committed 18374e5

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>

  • Participants
  • Parent commits e636106

Comments (0)

Files changed (2)

 	char *err;
 
 	if (line[0] == '+') {
+		unsigned bad;
 		data->lineno++;
-		data->status = check_and_emit_line(line + 1, len - 1,
+		bad = check_and_emit_line(line + 1, len - 1,
 		    data->ws_rule, NULL, NULL, NULL, NULL);
-		if (!data->status)
+		if (!bad)
 			return;
-		err = whitespace_error_string(data->status);
+		data->status |= bad;
+		err = whitespace_error_string(bad);
 		fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
 		free(err);
 		emit_line(data->file, set, reset, line, 1);

File t/t4017-diff-retval.sh

 
 '
 
+
+test_expect_success 'check should test not just the last line' '
+	echo "" >>a &&
+	git --no-pager diff --check
+	test $? = 2
+
+'
+
 test_done