git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git diff --check always shows line 1 for blank at EOF for new files

From
Christoph Mallon <christoph.mallon@gmx.de>
Date
Oct 7, 2010, 12:33 UTC
Message-ID
<4CADBE01.4000901@gmx.de>
In-Reply-To
<20101007093258.GA10941@burratino>
On 07.10.2010 11:32, Jonathan Nieder wrote:
Show 15 quoted lines
> Try this:
>
>      git init test
>      cd test
>      printf 'a\nb\nc\n'>  file
>      git add -A
>      echo hello>>  file
>      echo>>  file
>      git diff --check
>
> As you can see, it still returns line 4, which is the beginning of the
> hunk that adds the blank line.
>
> A change to make it print the line number of the blank line itself
> does not sound so bad, though.
You're right. I think, the attached patch corrects the issue.
>From 45eaa882dae35f2976e77cf0b6b06be78283c13f Mon Sep 17 00:00:00 2001
From: Christoph Mallon <christoph.mallon@gmx.de>
Date: Thu, 7 Oct 2010 14:22:02 +0200
Subject: [PATCH] When git diff --check detects a blank line at EOF, show the line number of the empty line, not the line number of the beginning of the hunk.
---
 diff.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index 71efa8e..452fdf4 100644
--- a/diff.c
+++ b/diff.c
@@ -2153,7 +2153,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
 
 			ecbdata.ws_rule = data.ws_rule;
 			check_blank_at_eof(&mf1, &mf2, &ecbdata);
-			blank_at_eof = ecbdata.blank_at_eof_in_preimage;
+			blank_at_eof = ecbdata.blank_at_eof_in_postimage;
 
 			if (blank_at_eof) {
 				static char *err;
-- 
1.7.3
Previous: Jonathan NiederNext: Junio C Hamano
Message 3 of 4 in “git diff --check always shows line 1 for blank at EOF for new files”
  1. Christoph MallonOct 6, 2010
  2. Jonathan NiederOct 7, 2010
  3. Christoph MallonOct 7, 2010
  4. Junio C HamanoOct 10, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.