@matheusbsbs / matheus-bagliano / commits / 0ef617f4b6
Fork 0

diff: Fix miscounting of --check output

c1795bb (Unify whitespace checking) incorrectly made the checking function return without incrementing the line numbers when there is no whitespace problem is found on a '+' line. This resurrects the earlier behaviour. Noticed and reported by Jay Soffian. The test script was stolen from Jay's independent fix. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 15, 2008 at 20:30 UTC 0ef617f4b6ea78ad63dd11e90f8c854238176981
2 files changed +11 -2
diff.c
+2 -2
@@ -1013,6 +1013,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1013 char *err;
1014
1015 if (line[0] == '+') {
1016 + data->lineno++;
1017 data->status = check_and_emit_line(line + 1, len - 1,
1018 data->ws_rule, NULL, NULL, NULL, NULL);
1019 if (!data->status)
@@ -1023,13 +1024,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1024 emit_line(set, reset, line, 1);
1025 (void)check_and_emit_line(line + 1, len - 1, data->ws_rule,
1026 stdout, set, reset, ws);
1026 - data->lineno++;
1027 } else if (line[0] == ' ')
1028 data->lineno++;
1029 else if (line[0] == '@') {
1030 char *plus = strchr(line, '+');
1031 if (plus)
1032 - data->lineno = strtol(plus, NULL, 10);
1032 + data->lineno = strtol(plus, NULL, 10) - 1;
1033 else
1034 die("invalid diff");
1035 }
t/t4015-diff-whitespace.sh
+9
@@ -326,4 +326,13 @@ test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab:
326 ! git diff --check
327
328 '
329 +
330 +test_expect_success 'line numbers in --check output are correct' '
331 +
332 + echo "" > x &&
333 + echo "foo(); " >> x &&
334 + git diff --check | grep "x:2:"
335 +
336 +'
337 +
338 test_done