Re: git diff-files bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, Dec 19, 2023 at 8:56 AM Josh Reed <jriddy@xxxxxxxxx> wrote:
>
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)

Let's extend your example a bit to point out when/if the index is updated...

>
> > bash
> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?
> 0

$ stat --format=%y .git/index
2023-12-19 09:30:55.867055501 -0800

This is the modification time of the index at the very beginning.

> ⬢[jreed@toolbox example-project]$ chmod g+w README.md

$ stat --format=%y .git/index
2023-12-19 09:30:55.867055501 -0800

As expected, the index has not changed just because some file changed.

> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?
> 1

$ stat --format=%y .git/index
2023-12-19 09:30:55.867055501 -0800

Note that the index still has not changed; diff-files will not update
it when it notices differences.  But diff-files shows us differences
between the working tree and index, and the working tree has changed.
Those changes mean that the stat information in the index no longer
matches the working tree.  That alone is enough for diff-files to give
a non-zero exit status.  This does tend to trip up folks, though.

> ⬢[jreed@toolbox example-project]$ git diff --exit-code --patch; echo $?
> 0

$ stat --format=%y .git/index
2023-12-19 09:33:46.773896615 -0800

Now the index _was_ updated.  So, not only are there no content
differences, and no relevant filemode differences, but the stat
information in the index now matches what is in the working tree.  So,
diff returns an exit code of 0.  (Note that this means "git diff" is
not a read-only operation, which sometimes trips up people in the
other direction.)

> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?
> 0

Right, contents match, relelvant filemodes match, and the stat
information in the index now matches what is in the working tree.
And:

$ stat --format=%y .git/index
2023-12-19 09:33:46.773896615 -0800

...no further changes to the index from this command, of course.

> What did you expect to happen? (Expected behavior)
>
> Git diff-files should likely ignore group permissions changes, or at least
> its output should be stable across the same worktree/index state.

It does ignore group permission changes; the problem was that stat
information in the index did not match what was in the working tree.
If you run

$ git update-index --refresh

before calling diff-files, that'll make sure the stat information is up-to-date.

> What happened instead? (Actual behavior)
>
> The command `git diff-files --exit-code --patch` fails with no exit code when
> a file mode has changed in a way that the rest of git commands ignored.
> Furthermore, subsequent git commands seem to change the behavior of `git
> diff-files` in this regard, so it's hard to tell what is the expected behavior.
>
> What's different between what you expected and what actually happened?
>
> The `git diff-files --exit-code` command is inconsistent in how it behaves.
> I suspect it should ignore irrelavant mode changes like `g+w`, but even if
> it should report them, they should produce a patch or at least have stable
> results when we re-run the command.

This has bit a few folks before; I wonder if there's a reasonable
update we can make to the documentation to address this.





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux