Skip to content

Commit

Permalink
diff: Fix miscounting of --check output
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 16, 2008
1 parent 13bf1a9 commit 0ef617f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
char *err;

if (line[0] == '+') {
data->lineno++;
data->status = check_and_emit_line(line + 1, len - 1,
data->ws_rule, NULL, NULL, NULL, NULL);
if (!data->status)
Expand All @@ -1023,13 +1024,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
emit_line(set, reset, line, 1);
(void)check_and_emit_line(line + 1, len - 1, data->ws_rule,
stdout, set, reset, ws);
data->lineno++;
} else if (line[0] == ' ')
data->lineno++;
else if (line[0] == '@') {
char *plus = strchr(line, '+');
if (plus)
data->lineno = strtol(plus, NULL, 10);
data->lineno = strtol(plus, NULL, 10) - 1;
else
die("invalid diff");
}
Expand Down
9 changes: 9 additions & 0 deletions t/t4015-diff-whitespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,13 @@ test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab:
! git diff --check
'

test_expect_success 'line numbers in --check output are correct' '
echo "" > x &&
echo "foo(); " >> x &&
git diff --check | grep "x:2:"
'

test_done

0 comments on commit 0ef617f

Please sign in to comment.