Whenever I try to commit to a particular Git repo, I'm getting the error "Insufficient Permission For Adding An Object To Repository Database .git/objects." Initially, this seems like the same question that's already been asked & answered countless times (i.e. here, here, here, etc). However, the solution that's always given - which seems quite obvious from the error message itself - is that it's one of file permissions and/or ownership. Yet even when I recursively set the owner for the entire directory tree, and recursively set permissions to the most "permissive" 777...I still can't seem to resolve the error.
More details: the Git commits are actually taking place by a service running in a Docker container. The repo is on a filesystem on the host machine, that's mapped into the container. I know that the uid/gid used by the container when it invokes Git is 2999, so in order to test/debug the issue more easily from the host machine, I can use docker exec
. First, just to confirm how to use docker exec
to run commands as a specific user:
docker exec -u 2999:2999 containerName sh -c "id"
...Yup, as expected, this prints uid=2999 and gid=2999.
So first I'll set the recursive permissions & ownership, per all the solutions given elsewhere to this error:
docker exec containerName sh -c "chmod 777 /path/to/repo -R"
docker exec containerName sh -c "chown 2999:2999 /path/to/repo -R"
I can then confirm that they were set properly:
docker exec containerName sh -c "ls -la /path/to/repo"
Now, let's try to run some git commands:
docker exec -u 2999:2999 containerName sh -c "cd /path/to/repo && git add -A"
docker exec -u 2999:2999 containerName sh -c "cd /path/to/repo && git commit -m 'testcomit'"
The result:
error: insufficient permission for adding an object to repository database .git/objects
error: testfile: failed to insert into database
error: unable to index file testfile
fatal: adding files failed
At this point, I'm at a total loss. If I've explicitly set the ownership/permissions and am explicitly running the commit as the same user...why would this error still arise? Note that I can definitely write to the repo itself as user 2999, so it only seems to be Git that's failing. For example, this works, & the file does appear as expected:
docker exec -u 2999:2999 containerName sh -c "echo sometext > /path/to/repo/testfile"