MacOS – Git not working over AFP

afpgitmacos

I've got a git repository on my file server which I'm connecting to via AFP. Whenever I try to do a git operation on the shared repository, such as staging a file, I get the following error message:

fatal: Unable to write new index file

If I execute the git command on the server it works fine, so there's something about sharing the repository via AFP that's not working.

I'm using Mountain Lion on both the server and the client.

UPDATE

I seem to have write permission for both .git and .git/index:

$ ls -ld .git
drwxr-xr-x  1 david  staff  364 Nov 29 22:38 .git/
$ ls -l .git/index
-rw-r--r--  1 david  staff  2232 Nov 29 21:45 .git/index
$ cp .git/index backup
$ echo change >> .git/index

I tried recursively applying permissions to .git as suggested by an answer below, but that didn't help:

$ chmod -Rv +w .git
$ git add deploy.js 
fatal: Unable to write new index file

Hmm, it looks like someone else is using the index file:

$ cp .git/index backup; mv backup .git/index
mv: rename backup to .git/index: Resource busy

But fuser and lsof aren't of any help:

$ fuser -fu .git/index
.git/index: 
$ lsof .git/index

Weird workaround: If I do the following command on the server, it allows me to write a new index file on the client over AFP.

$ cp .git/index backup; mv backup .git/index

I'm totally lost at this point; any new theories?

Best Answer

We've run into the same issue repeatedly, especially as we try to use XCode 6. I'm currently changing over my connect to our server to WebDAV (connecting to our server via Finder > Go (menubar) > Connect to Server... > https://localnetworkIP/userfolder/).

This is working for us (so far).

UPDATE: After a few days, I noticed a new issue using WebDAV: files would disappear from view in the Finder causing XCode/Git to think that the file had been deleted. Looking at the server showed that the files were still there.

I then changed my connection type to SMB. This has worked well for me: Git no longer encounters file permission errors, and Finder (OSX 10.10 Yosemite) doesn't "loose" files.