threads / discuss / 12364

git diff --name-status does not always list changed files

Subject: git diff --name-status does not always list changed files

## tl;dr

6 messages between Feb 28, 2008 and Feb 28, 2008.

replies: 5people: 2as markdown or json

Sebastian Schuberth· Feb 28, 2008, 14:47 UTC · lore
Hi,

I was getting a lot of "no newline at end of file" warnings with GCC, so I decided to fix these files in my clean working tree with

for i in `find . -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" -o 
-iname "*.h" -o -iname "*.hpp"`; do
     echo $i
     echo wq | ed $i > /dev/null 2>&1
done

Afterwards, I wanted so see a list of files that were actually affected, but to my wonderment "git diff --name-status" did not list any files, although both "git diff" and "gitk" showed the diffs correctly.

Is this a bug in "--name-status" that is does not detected changes if only a final newline has been added, or am I missing something?

Thanks.
-- 
Sebastian Schuberth
Junio C Hamano· Feb 28, 2008, 19:33 UTC · re: Sebastian Schuberth · lore

Re: git diff --name-status does not always list changed files

Sebastian Schuberth <sschuberth@gmail.com> writes:
Show 13 quoted lines
> ...
> so I decided to fix these files in my clean working tree with
>
> for i in `find . -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" -o
> -iname "*.h" -o -iname "*.hpp"`; do
>     echo $i
>     echo wq | ed $i > /dev/null 2>&1
> done
>
> Afterwards, I wanted so see a list of files that were actually
> affected, but to my wonderment "git diff --name-status" did not list
> any files, although both "git diff" and "gitk" showed the diffs
> correctly.
Doesn't reproduce for me.
        $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
        $ git init
        Initialized empty Git repository in .git/
        $ echo -n hello > world
        $ git add world
        $ od -c world
        0000000   h   e   l   l   o
        0000005
        $ echo wq | ed world
        Newline appended
        6
        6
        $ od -c world
        0000000   h   e   l   l   o  \n
        0000006
        $ git diff --name-status
        M	world
        $ git diff --raw
        :100644 100644 b6fc4c6... 0000000... M	world
        $ exit
Sebastian Schuberth· Feb 28, 2008, 21:23 UTC · re: Junio C Hamano · lore

Re: git diff --name-status does not always list changed files

Junio C Hamano wrote:
Show 5 quoted lines
> Doesn't reproduce for me.
>
>         $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
>         $ git init
>         Initialized empty Git repository in .git/
Can you reproduce it if you do
$ git config core.pager "less -F"

after "git init"? The "-F" seems to be important, but I'm not sure why using this switch causes no files to be displayed in this case.

-- 
Sebastian Schuberth
Junio C Hamano· Feb 28, 2008, 21:42 UTC · re: Sebastian Schuberth · lore

Re: git diff --name-status does not always list changed files

"Sebastian Schuberth" <sschuberth@gmail.com> writes:
Show 14 quoted lines
> Junio C Hamano wrote:
>
>> Doesn't reproduce for me.
>>
>>         $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
>>         $ git init
>>         Initialized empty Git repository in .git/
>
> Can you reproduce it if you do
>
> $ git config core.pager "less -F"
>
> after "git init"? The "-F" seems to be important, but I'm not sure why
> using this switch causes no files to be displayed in this case.
Then isn't it what you are asking "less" to do?

Try "less -FX". FYI, by default, we use "LESS=FRSX" exported unless the user knows better than us and uses something of his own.

Sebastian Schuberth· Feb 28, 2008, 22:19 UTC · re: Junio C Hamano · lore

Re: git diff --name-status does not always list changed files

Show 20 quoted lines
>  > Junio C Hamano wrote:
>  >
>  >> Doesn't reproduce for me.
>  >>
>  >>         $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
>  >>         $ git init
>  >>         Initialized empty Git repository in .git/
>  >
>  > Can you reproduce it if you do
>  >
>  > $ git config core.pager "less -F"
>  >
>  > after "git init"? The "-F" seems to be important, but I'm not sure why
>  > using this switch causes no files to be displayed in this case.
>
>  Then isn't it what you are asking "less" to do?
>
>  Try "less -FX".  FYI, by default, we use "LESS=FRSX" exported
>  unless the user knows better than us and uses something of his
>  own.

Thanks, -FX works, though I do not understand why it did not with just -F. From what I understood, -F just makes "less" quit immediately (instead of waiting for the user to press "q") if the lines to display fit completely on screen. In no case it should display nothing if there actually is something to display.

-- 
Sebastian Schuberth
Junio C Hamano· Feb 28, 2008, 22:51 UTC · re: Sebastian Schuberth · lore

Re: git diff --name-status does not always list changed files

"Sebastian Schuberth" <sschuberth@gmail.com> writes:
Show 5 quoted lines
> Thanks, -FX works, though I do not understand why it did not with just
> -F. From what I understood, -F just makes "less" quit immediately
> (instead of waiting for the user to press "q") if the lines to display
> fit completely on screen. In no case it should display nothing if
> there actually is something to display.

My reading and understanding of less manual page, especially the part that talks about -X suggests that everything is working as it is meant to.

"git diff --name-status" displays something, less shows it, and it quits immediately (because you asked it to with -F). As part of its quitting, it clears the screen because you did not ask less not to do that by giving it an -X.

I am tempted to call it a bug in less, but I am a very nice person and I would not actually do so ;-). But it certainly feels like a misfeature between less and terminfo to me.

← back to recent threads