threads / patch / 12121

patchFix line numbers emitted by "git diff --check"

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

## tl;dr

2 messages between Feb 15, 2008 and Feb 16, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Jay Soffian· Feb 15, 2008, 23:33 UTC · lore

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(-)
Show changes to 2 files +12 −1

diff.c, t/t4015-diff-whitespace.sh

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· Feb 16, 2008, 07:04 UTC · re: Jay Soffian · lore

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

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.

← back to recent threads