Git over samba cannot fetch/add/commit anymore
Asked Answered
M

2

1

I have used git trough samba for several times without any issue.

In the last days however, it seems impossible to git all/fetch/commit

The error is :

error: insufficient permission for adding an object to repository database .git/objects

Using strace I can see that error is due to a call on open:

[pid 31303] open(".git/objects/b7/tmp_obj_6wi717", O_RDWR|O_CREAT|O_EXCL, 0444) = -1 EACCES (Permission denied)
[pid 31303] write(2, "error: insufficient permission f"..., 88error: insufficient permission for adding an object to repository database .git/objects

I cannot understand what has changed nor why git is trying to open a file in 444 (read for everybody) with the flag RDRW (read/write ?).

I use git 1.8.5.1 and samba 4.1.3-1 on archlinux, the samba server is a windows (git 1.8.4-1 does not solve the issue even if I used it while it was still working)

I have read other SO questions such as Git over samba - unable to write sha1 filename | Permission denied without finding any hint on how to solve the issue.

Meristic answered 13/12, 2013 at 13:10 Comment(1)
The mode argument is specifying the permissions to create the file with. It sounds like .git/objects is no longer writable by your user. what are the permissions and ownership on it? If you run git config --list |grep shared in the shared repository do you see core.sharedrepository=true?Spitsbergen
D
1

You can see various way to debug this in "Debugging git repo permissions on samba share":

  • setting different permissions for share
  • mounting manually
  • downgrading samba and git to earlier versions
  • sudo - this works but I wouldn't want to use it unless absolutely necessary
  • changing owner and group after using sudo

Andrew Myers suggests making sure your bare repo has core.sharedRepository set to group.
If not, set it and run

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

If nothing works, make sure it isn't an issue related to the kernel version:

I've downgraded kernel to 3.11.6 and git add/commit as user started working again.


Update: The OP kamaradclimber reports (or tried to) that is was a kernel issue (bug 66251):

Git doesn't work correctly on samba share after upgrading kernel from 3.11.6 to 3.12.1

Fixed by this patch.

Dinesh answered 14/12, 2013 at 8:47 Comment(5)
I had already tried to rollback git and samba versions without any luck but never though of trying another kernelMeristic
@Meristic what was the kernel version you had? And what version did you downgrade to?Dinesh
@Meristic I have included in the answer your (rejected) edit, by the way.Dinesh
(non related question) what does OP mean ?Meristic
@Meristic urbandictionary.com/define.php?term=op or acronyms.thefreedictionary.com/original+poster: "Original Poster" (can also refer to the question: "Original Post").Dinesh
B
3

In my case, it looks like Git (v 2.6.3) tried to create its own read/write permissions on the Samba drive. This would prevent the pack files and/or objects from getting written (unpack error)

remote: error: unable to write sha1 filename ./objects/pack/pack-<some_hex_string>.pack: Permission denied
remote: fatal: cannot store pack file
error: unpack failed: index-pack abnormal exit
To z:\git\<repo name>
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs

I went back and forth on trying to fix. Finally, since I had control of the Samba machine, I added a line to the samba drive config, which says "inherit permissions = yes". I restarted Samba and tried to push. It worked!

This worked for me since I'm the only person using the Samba server. For others, you may have the play around with "force directory mode" or "force create mode". You can find the man pages for those over here:

https://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/AccessControls.html

Buncombe answered 13/12, 2015 at 8:56 Comment(2)
I've been trying to figure it out for quite a while already. Your answer was the only thing that actually worked for my FreeNAS Samba Share. THANK YOU!Hangout
You are welcome. Glad it worked for you. :)Buncombe
D
1

You can see various way to debug this in "Debugging git repo permissions on samba share":

  • setting different permissions for share
  • mounting manually
  • downgrading samba and git to earlier versions
  • sudo - this works but I wouldn't want to use it unless absolutely necessary
  • changing owner and group after using sudo

Andrew Myers suggests making sure your bare repo has core.sharedRepository set to group.
If not, set it and run

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

If nothing works, make sure it isn't an issue related to the kernel version:

I've downgraded kernel to 3.11.6 and git add/commit as user started working again.


Update: The OP kamaradclimber reports (or tried to) that is was a kernel issue (bug 66251):

Git doesn't work correctly on samba share after upgrading kernel from 3.11.6 to 3.12.1

Fixed by this patch.

Dinesh answered 14/12, 2013 at 8:47 Comment(5)
I had already tried to rollback git and samba versions without any luck but never though of trying another kernelMeristic
@Meristic what was the kernel version you had? And what version did you downgrade to?Dinesh
@Meristic I have included in the answer your (rejected) edit, by the way.Dinesh
(non related question) what does OP mean ?Meristic
@Meristic urbandictionary.com/define.php?term=op or acronyms.thefreedictionary.com/original+poster: "Original Poster" (can also refer to the question: "Original Post").Dinesh

© 2022 - 2024 — McMap. All rights reserved.