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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux