git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* "git diff-files" command reports differences that don't exist
@ 2021-03-05 19:28 Michael Brown
  2021-03-05 21:49 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Brown @ 2021-03-05 19:28 UTC (permalink / raw)
  To: git

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/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "git diff-files" command reports differences that don't exist
  2021-03-05 19:28 "git diff-files" command reports differences that don't exist Michael Brown
@ 2021-03-05 21:49 ` Junio C Hamano
  2021-03-05 22:18   ` Eric Sunshine
  2021-03-05 22:20   ` Michael Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2021-03-05 21:49 UTC (permalink / raw)
  To: Michael Brown; +Cc: git

Michael Brown <michael.brown@discourse.org> writes:

> 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.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "git diff-files" command reports differences that don't exist
  2021-03-05 21:49 ` Junio C Hamano
@ 2021-03-05 22:18   ` Eric Sunshine
  2021-03-05 22:28     ` Junio C Hamano
  2021-03-05 22:20   ` Michael Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Sunshine @ 2021-03-05 22:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michael Brown, Git List

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...

?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "git diff-files" command reports differences that don't exist
  2021-03-05 21:49 ` Junio C Hamano
  2021-03-05 22:18   ` Eric Sunshine
@ 2021-03-05 22:20   ` Michael Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Brown @ 2021-03-05 22:20 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "git diff-files" command reports differences that don't exist
  2021-03-05 22:18   ` Eric Sunshine
@ 2021-03-05 22:28     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2021-03-05 22:28 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Michael Brown, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-05 22:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 19:28 "git diff-files" command reports differences that don't exist Michael Brown
2021-03-05 21:49 ` Junio C Hamano
2021-03-05 22:18   ` Eric Sunshine
2021-03-05 22:28     ` Junio C Hamano
2021-03-05 22:20   ` Michael Brown

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).