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

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Christoph Mallon <hidden>
Date: 2016-06-15 22:49:43

Hi,

there seems to be a glitch in git diff --check for new files: If a new 
file has trailing empty lines, then the error message always refers to 
line 1. This happens with git 1.7.3.1.

Here is a simple test case:
   git init test
   cd test
   printf 'a\nb\nc\n\n' > file
   git add -AN
   git diff --check

The last command will show "file:1: new blank line at EOF.".

It works fine, if the diff is not against /dev/null, e.g.:
   git init test
   cd test
   printf 'a\nb\nc\n' > file
   git add -A
   echo >> file
   git diff --check

This correctly shows "file:4: new blank line at EOF.".

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

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:43

Hi Christoph,

Christoph Mallon wrote:
  git init test
  cd test
  printf 'a\nb\nc\n\n' > file
  git add -AN
  git diff --check

The last command will show "file:1: new blank line at EOF.".

It works fine, if the diff is not against /dev/null, e.g.:
  git init test
  cd test
  printf 'a\nb\nc\n' > file
  git add -A
  echo >> file
  git diff --check

This correctly shows "file:4: new blank line at EOF.".
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.

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

From: Christoph Mallon <hidden>
Date: 2016-06-15 22:49:43

On 07.10.2010 11:32, Jonathan Nieder wrote:
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help