threads / discuss / 55264

"git diff-files" command reports differences that don't exist

Subject: "git diff-files" command reports differences that don't exist

## tl;dr

5 messages between Mar 5, 2021 and Mar 5, 2021.

replies: 4people: 3as markdown or json

Michael Brown· Mar 5, 2021, 19:28 UTC · lore
What did you do before the bug happened? (Steps to reproduce your issue)
1. Be in any existing repository in a clean state (I tested with 2 existing
   repositories and 1 completely fresh)
1. run `git diff-files`, see no output
1. touch an existing file: `touch a`
1. run `git diff-files`
What did you expect to happen? (Expected behavior)
`git diff-files` should show no output
What happened instead? (Actual behavior)
`git diff-files` reported a difference on the touched file.
What's different between what you expected and what actually happened?
git reports a difference where none exists
Anything else you want to add:
This difference vanished after running other commands (e.g. `git diff`).
A complete reproduction using docker is below:
$ docker run -it --rm debian:latest
root@d24ec0793bdf:/# apt update && apt -y install git
…
root@d24ec0793bdf:/# mkdir ~/new-repo
root@d24ec0793bdf:/# cd ~/new-repo
root@d24ec0793bdf:~/new-repo# git init
Initialized empty Git repository in /root/new-repo/.git/
root@d24ec0793bdf:~/new-repo# touch a
root@d24ec0793bdf:~/new-repo# git add a
root@d24ec0793bdf:~/new-repo# git config --global user.email
'user@example.net'
root@d24ec0793bdf:~/new-repo# git config --global user.name 'Example User'
root@d24ec0793bdf:~/new-repo# git commit -m 'initial'
[master (root-commit) 791011f] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
root@d24ec0793bdf:~/new-repo# git diff-files
root@d24ec0793bdf:~/new-repo# touch a
root@d24ec0793bdf:~/new-repo# git diff-files
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
0000000000000000000000000000000000000000 M    a
root@d24ec0793bdf:~/new-repo# git diff
root@d24ec0793bdf:~/new-repo# git diff-files
root@d24ec0793bdf:~/new-repo# git --version
git version 2.20.1

[System Info] git version: git version 2.30.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.11.1-arch1-1 #1 SMP PREEMPT Tue, 23 Feb 2021 14:05:30 +0000 x86_64 compiler info: gnuc: 10.2 libc info: glibc: 2.33 $SHELL (typically, interactive shell): /bin/bash

This same behaviour was also found in:
* 2.20.1
* 2.25.1

[Enabled Hooks] (none)

-- 
Michael Brown
Civilized Discourse Construction Kit, Inc.
https://www.discourse.org/
Junio C Hamano· Mar 5, 2021, 21:49 UTC · re: Michael Brown · lore

Re: "git diff-files" command reports differences that don't exist

Michael Brown <michael.brown@discourse.org> writes:
Show 7 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> 1. Be in any existing repository in a clean state (I tested with 2 existing
>    repositories and 1 completely fresh)
> 1. run `git diff-files`, see no output
> 1. touch an existing file: `touch a`
> 1. run `git diff-files`

This is totally expected behaviour. In general when you are working with plumbing commands like diff-files and diff-index, you are expected to do "update-index --refresh" upfront.

A plumbing command "git diff" has an equivalent of "update-index --refresh" built into it, but the plumbing commands are designed to be used in scripts, and in order to allow scripting programmers to avoid making unnecessary "update-index --refresh", e.g.

	git update-index --refresh
	git diff-files | use diff-files output
	git diff-index | use diff-index output

they leave it the responsibility of the calling script (or the end user who directly use them from the command line) to refresh the cached stat information as necessary.

Eric Sunshine· Mar 5, 2021, 22:18 UTC · re: Junio C Hamano · lore

Re: "git diff-files" command reports differences that don't exist

On Fri, Mar 5, 2021 at 4:50 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> This is totally expected behaviour.  In general when you are working
> with plumbing commands like diff-files and diff-index, you are
> expected to do "update-index --refresh" upfront.
>
> A plumbing command "git diff" has an equivalent of "update-index
> --refresh" built into it, but the plumbing commands are designed
> to be used in scripts, and in order to allow scripting programmers
> to avoid making unnecessary "update-index --refresh", e.g.
Did you mean:
    A porcelain command "git diff" has an equivalent...
?
Junio C Hamano· Mar 5, 2021, 22:28 UTC · re: Eric Sunshine · lore

Re: "git diff-files" command reports differences that don't exist

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 13 quoted lines
> On Fri, Mar 5, 2021 at 4:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>> This is totally expected behaviour.  In general when you are working
>> with plumbing commands like diff-files and diff-index, you are
>> expected to do "update-index --refresh" upfront.
>>
>> A plumbing command "git diff" has an equivalent of "update-index
>> --refresh" built into it, but the plumbing commands are designed
>> to be used in scripts, and in order to allow scripting programmers
>> to avoid making unnecessary "update-index --refresh", e.g.
>
> Did you mean:
>
>     A porcelain command "git diff" has an equivalent...
Yes.
Michael Brown· Mar 5, 2021, 22:20 UTC · re: Junio C Hamano · lore

Re: "git diff-files" command reports differences that don't exist

On 2021-03-05 4:49 p.m., Junio C Hamano wrote:
> This is totally expected behaviour.  In general when you are working
> with plumbing commands like diff-files and diff-index, you are
> expected to do "update-index --refresh" upfront.

Thanks. I wondered if since it was a plumbing command there might have been something I was missing but didn't know where to look.

Cheers.
-- 
Michael Brown
Civilized Discourse Construction Kit, Inc.
https://www.discourse.org/

← back to recent threads