Git recently made a security fix. Unfortunately, it broke things for a lot of people, including me. Just in case anyone else has a similar obscure setup (and for my own notes), here's how I solved my issue.
My configuration is a bit off the beaten path.
- I am working on a Mac
- I have my git repos in Dropbox
- I use Parallels to build and test on Windows
- I use make to run my go build
- make is using msys sh as its shell
As of 1.18 Go includes vcs info in builds. So when I ran a Go build on Windows, it would fail with:
# cd x:\gsuneido; git status --porcelain fatal: unsafe repository ('//Mac/Dropbox/gsuneido' is owned by someone else) To add an exception for this directory, call: git config --global --add safe.directory '%(prefix)///Mac/Dropbox/gsuneido' error obtaining VCS status: exit status 128 Use -buildvcs=false to disable VCS stamping.
Adding -buildvcs=false did get the builds working, but it seemed ugly to disable a Go feature to work around a Git issue. It also didn't help if I wanted to do other Git commands.
I struggled with adding the safe.directory. I wasn't sure if %(prefix) was literal or was a variable. I also wasn't sure about whether it should be forward slashes or back slashes and how many (a perpetual issue on Windows). And I wasn't sure about the quoting. Eventually, I just edited my .gitconfig with a text editor.
Here's what worked:
[safe] directory = %(prefix)///Mac/Dropbox/gsuneido
Now I could do git commands.
But my build still failed with the same error!?
make is using msys sh as its shell. And sure enough, from within sh, I was back to the same error. git config --global --list didn't show my safe directory. That turned out to be because my home directory from inside sh was different. If I ran git config --global --add safe.directory from within sh, then it created another .gitconfig in /home/andrew. Now I could run git commands from sh, and now my build works.
I'm a little nervous about having multiple .gitconfig files, one on Mac, one for Windows, and one for sh on Windows but I don't have anything critical in there, so hopefully it'll be ok.
I'm all for security fixes, and I try to keep up to date, but it's definitely frustrating when it breaks stuff.