# [PATCH] Fix line numbers emitted by "git diff --check"

2 messages from 2008-02-15 to 2008-02-16. Participants: Jay Soffian, Junio C Hamano.
Thread: https://gitlist.dev/t/12121

## Jay Soffian, 2008-02-15 23:33

Subject: [PATCH] Fix line numbers emitted by "git diff --check"
Message-ID: <1203118423-32642-1-git-send-email-jaysoffian@gmail.com>
URL: https://gitlist.dev/e/1203118423-32642-1-git-send-email-jaysoffian%40gmail.com

```
Fixes a problem where git diff --check was emitting incorrect lines
numbers. Adds a test to verify the fix.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 diff.c                     |    4 +++-
 t/t4015-diff-whitespace.sh |    9 +++++++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/diff.c b/diff.c
index cd8bc4d..a002573 100644
--- a/diff.c
+++ b/diff.c
@@ -1023,8 +1023,10 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 	if (line[0] == '+') {
 		data->status = check_and_emit_line(line + 1, len - 1,
 		    data->ws_rule, NULL, NULL, NULL, NULL);
-		if (!data->status)
+		if (!data->status) {
+			data->lineno++;
 			return;
+		}
 		err = whitespace_error_string(data->status);
 		printf("%s:%d: %s.\n", data->filename, data->lineno, err);
 		free(err);
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index d30169f..83c54b7 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -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
-- 
1.5.4.1.1281.g75df

```

## Junio C Hamano, 2008-02-16 07:04

Subject: Re: [PATCH] Fix line numbers emitted by "git diff --check"
Message-ID: <7vk5l5crg7.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk5l5crg7.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1203118423-32642-1-git-send-email-jaysoffian@gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

> Fixes a problem where git diff --check was emitting incorrect lines
> numbers. Adds a test to verify the fix.
>
> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>

Ahh, our mails crossed, and our fixes are equivalent, but yours
has an additional test, which is always good.

Will steal the test part and squash it in (I've already patched
'maint' with the one I sent out), if you do not mind.

```
