Weirdness with git diff-index showing 1 file changed, 0 insertions(+), 0 deletions(-)

Featured image for sharing metadata for article

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 $?

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 $?

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!

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #command-line #git.

Also on:

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.