There's some sort of race inside git here, where the git diff-files command exits with different results some of the time when run in parallel with git ls-files or git diff (running either command was sufficient to trigger the race).
Run it separately to avoid the race.
I poked around the git source a little bit but quickly lost interest given that the issue seems fixed and this workaround is essentially reasonable.