{"thread":{"id":"60635","subject":"git diff-files bug","startedAt":"2023-12-19T16:54:08Z","lastAt":"2023-12-19T17:48:01Z","messageCount":2,"participants":["Josh Reed","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"485819","messageId":"CAELOy+5AsRyLEs-WdYw1spqkmMDKjKSQzbogAoRBFe-zGLjvXg@mail.gmail.com","threadId":"60635","inReplyTo":null,"subject":"git diff-files bug","fromName":"Josh Reed","fromEmail":"jriddy@gmail.com","sentAt":"2023-12-19T16:53:54Z","receivedAt":"2023-12-19T16:54:08Z","isPatch":false,"sender":{"key":"jriddy@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n> bash\n⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n0\n⬢[jreed@toolbox example-project]$ chmod g+w README.md\n⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n1\n⬢[jreed@toolbox example-project]$ git diff --exit-code --patch; echo $?\n0\n⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n0\n\n\nWhat did you expect to happen? (Expected behavior)\n\nGit diff-files should likely ignore group permissions changes, or at least\nits output should be stable across the same worktree/index state.\n\nWhat happened instead? (Actual behavior)\n\nThe command `git diff-files --exit-code --patch` fails with no exit code when\na file mode has changed in a way that the rest of git commands ignored.\nFurthermore, subsequent git commands seem to change the behavior of `git\ndiff-files` in this regard, so it's hard to tell what is the expected behavior.\n\nWhat's different between what you expected and what actually happened?\n\nThe `git diff-files --exit-code` command is inconsistent in how it behaves.\nI suspect it should ignore irrelavant mode changes like `g+w`, but even if\nit should report them, they should produce a patch or at least have stable\nresults when we re-run the command.\n\nAnything else you want to add:\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.41.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.5.10-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov  2\n19:59:55 UTC 2023 x86_64\ncompiler info: gnuc: 13.1\nlibc info: glibc: 2.37\n$SHELL (typically, interactive shell): /usr/bin/fish\n\n\n[Enabled Hooks]\npre-commit\npre-push\n"},{"id":"485824","messageId":"CABPp-BHYfZC65Wn9popF=61Y6xHQNKEW+xPNEz_e4fOQbKbiOg@mail.gmail.com","threadId":"60635","inReplyTo":"CAELOy+5AsRyLEs-WdYw1spqkmMDKjKSQzbogAoRBFe-zGLjvXg@mail.gmail.com","subject":"Re: git diff-files bug","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2023-12-19T17:47:47Z","receivedAt":"2023-12-19T17:48:01Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi,\n\nOn Tue, Dec 19, 2023 at 8:56 AM Josh Reed <jriddy@gmail.com> wrote:\n>\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n>\n> What did you do before the bug happened? (Steps to reproduce your issue)\n\nLet's extend your example a bit to point out when/if the index is updated...\n\n>\n> > bash\n> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n> 0\n\n$ stat --format=%y .git/index\n2023-12-19 09:30:55.867055501 -0800\n\nThis is the modification time of the index at the very beginning.\n\n> ⬢[jreed@toolbox example-project]$ chmod g+w README.md\n\n$ stat --format=%y .git/index\n2023-12-19 09:30:55.867055501 -0800\n\nAs expected, the index has not changed just because some file changed.\n\n> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n> 1\n\n$ stat --format=%y .git/index\n2023-12-19 09:30:55.867055501 -0800\n\nNote that the index still has not changed; diff-files will not update\nit when it notices differences.  But diff-files shows us differences\nbetween the working tree and index, and the working tree has changed.\nThose changes mean that the stat information in the index no longer\nmatches the working tree.  That alone is enough for diff-files to give\na non-zero exit status.  This does tend to trip up folks, though.\n\n> ⬢[jreed@toolbox example-project]$ git diff --exit-code --patch; echo $?\n> 0\n\n$ stat --format=%y .git/index\n2023-12-19 09:33:46.773896615 -0800\n\nNow the index _was_ updated.  So, not only are there no content\ndifferences, and no relevant filemode differences, but the stat\ninformation in the index now matches what is in the working tree.  So,\ndiff returns an exit code of 0.  (Note that this means \"git diff\" is\nnot a read-only operation, which sometimes trips up people in the\nother direction.)\n\n> ⬢[jreed@toolbox example-project]$ git diff-files --exit-code --patch; echo $?\n> 0\n\nRight, contents match, relelvant filemodes match, and the stat\ninformation in the index now matches what is in the working tree.\nAnd:\n\n$ stat --format=%y .git/index\n2023-12-19 09:33:46.773896615 -0800\n\n...no further changes to the index from this command, of course.\n\n> What did you expect to happen? (Expected behavior)\n>\n> Git diff-files should likely ignore group permissions changes, or at least\n> its output should be stable across the same worktree/index state.\n\nIt does ignore group permission changes; the problem was that stat\ninformation in the index did not match what was in the working tree.\nIf you run\n\n$ git update-index --refresh\n\nbefore calling diff-files, that'll make sure the stat information is up-to-date.\n\n> What happened instead? (Actual behavior)\n>\n> The command `git diff-files --exit-code --patch` fails with no exit code when\n> a file mode has changed in a way that the rest of git commands ignored.\n> Furthermore, subsequent git commands seem to change the behavior of `git\n> diff-files` in this regard, so it's hard to tell what is the expected behavior.\n>\n> What's different between what you expected and what actually happened?\n>\n> The `git diff-files --exit-code` command is inconsistent in how it behaves.\n> I suspect it should ignore irrelavant mode changes like `g+w`, but even if\n> it should report them, they should produce a patch or at least have stable\n> results when we re-run the command.\n\nThis has bit a few folks before; I wonder if there's a reasonable\nupdate we can make to the documentation to address this.\n"}]}