setgid bit not preserved by git on new directory in `.git` folder?

不问归期 提交于 2019-12-04 17:42:56

It turns out that when you specify the core.sharedrepository config, git does chmod()s on the files it creates. That way, the result is correct despite filesystem types and mount options, except in your one case where the repository owner isn't a member of the group it's shared with.

That bad result happens because git's chmod() appears to succeed -- you can see it in an strace -- but ignores anything the issuing user isn't authorized to ask for.

So to avoid that weirdity, the thing to do is

git config --unset core.sharedrepository

(or not specify --shared at all on the init) so git doesn't touch the filesystem's default permissions at all. Amusingly enough that makes everything work:

~/sandbox/75276/s$ find ../s.git -ls
12193569    4 drwxrws---   4 jthill   mail         4096 Apr  9 13:52 ../s.git
12193571    4 -rw-rw----   1 jthill   mail           73 Apr  8 20:40 ../s.git/description
12193572    4 -rw-rw----   1 jthill   mail           23 Apr  8 20:40 ../s.git/HEAD
12721086    4 drwxrws---   2 jthill   mail         4096 Apr  9 13:52 ../s.git/objects
12193570    4 drwxrws---   2 jthill   mail         4096 Apr  9 13:52 ../s.git/refs
12193578    4 -rw-rw----   1 jthill   mail          104 Apr  9 13:37 ../s.git/config
~/sandbox/75276/s$ cat ../s.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
[receive]
        denyNonFastforwards = true
~/sandbox/75276/s$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 198 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/jthill/sandbox/75276/s.git
 * [new branch]      master -> master
~/sandbox/75276/s$ find ../s.git -ls
12193569    4 drwxrws---   4 jthill   mail         4096 Apr  9 13:52 ../s.git
12193571    4 -rw-rw----   1 jthill   mail           73 Apr  8 20:40 ../s.git/description
12193572    4 -rw-rw----   1 jthill   mail           23 Apr  8 20:40 ../s.git/HEAD
12721086    4 drwxrws---   5 jthill   mail         4096 Apr  9 13:53 ../s.git/objects
16777964    4 drwxrwsr-x   2 jthill   mail         4096 Apr  9 13:53 ../s.git/objects/58
16777965    4 -r--r--r--   1 jthill   mail           17 Apr  9 13:53 ../s.git/objects/58/7be6b4c3f93f93c489c0111bba5596147a26cb
16777962    4 drwxrwsr-x   2 jthill   mail         4096 Apr  9 13:53 ../s.git/objects/ab
16777963    4 -r--r--r--   1 jthill   mail           46 Apr  9 13:53 ../s.git/objects/ab/69b4abf3bb84d4e268bd42d84e4a9a5e242bd3
16777960    4 drwxrwsr-x   2 jthill   mail         4096 Apr  9 13:53 ../s.git/objects/81
16777961    4 -r--r--r--   1 jthill   mail          120 Apr  9 13:53 ../s.git/objects/81/210f2df9629e5df5f6dfa0923a2cf72369314d
12193570    4 drwxrws---   3 jthill   mail         4096 Apr  9 13:53 ../s.git/refs
12193573    4 drwxrwsr-x   2 jthill   mail         4096 Apr  9 13:53 ../s.git/refs/heads
12193574    4 -rw-rw-r--   1 jthill   mail           41 Apr  9 13:53 ../s.git/refs/heads/master
12193578    4 -rw-rw----   1 jthill   mail          104 Apr  9 13:37 ../s.git/config
~/sandbox/75276/s$ 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!