My website reports on the Git status (current commit and branch, mostly, and also git ls-files --modified to show any files which have been modified directly on the server) so I can check at a glance whether it's up to date. This used to work, but the latest Git does not allow these things to be read by a user which does not own the repo.
The command git config --global --add safe.directory {$dir} works in principle, but does not work for www-data, because it has no $HOME, so there's nowhere for the .gitconfig file to be created. The response is fatal: $HOME not set.
Is there any straightforward way to allow Apache to read a few facts about the Git repo? This is all PHP code using exec() to run commands such as git branch --show-current and git log -1 --pretty=%H, among others.