Weirdness with git diff-index
showing 1 file changed, 0 insertions(+), 0 deletions(-)
Last week I was writing some automation that would validate that my Git repo had no uncommitted changes after running go generate
, to make sure all source files were up to date.
I thought it was running fine locally, but CI was telling me that no, it was not working when running in docker-compose
as part of the pipeline.
What I was seeing was:
$ go generate ./... && git diff-index --quiet HEAD --
$ echo $?
1
This was very odd, because when I would run git diff
or git status
, nothing would show as changed when run after git diff-index
, but if I ran git diff --shortstat
I would get the following output:
I spent a good day fighting this, trying to look into debugging information in Git but no luck.
Contrary to most StackOverflow responses, it was not related to file permissions, and setting that config changed nothing.
My hacky workaround solution was to instead run:
$ go generate ./... && git status; git diff-index --quiet HEAD --
$ echo $?
1
Sorry I don't have a fix for it, or a reproducible case, but hopefully if you have this issue in the past you know a workaround!