{"thread":{"id":"31750","subject":"sharedRepository derived from file permissions","startedAt":"2012-10-08T09:07:30Z","lastAt":"2012-10-17T12:25:32Z","messageCount":5,"participants":["Mark Hills","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"200745","messageId":"1210080955590.12283@wes.ijneb.com","threadId":"31750","inReplyTo":null,"subject":"sharedRepository derived from file permissions","fromName":"Mark Hills","fromEmail":"mark@pogo.org.uk","sentAt":"2012-10-08T09:07:30Z","receivedAt":"2012-10-08T09:07:30Z","isPatch":false,"sender":{"key":"mark@pogo.org.uk","avatar":null},"body":"We make extensive use of unix permissions and core.sharedRepository -- \nmultiple developers push to the same repo.\n\nI have often wondered why core.sharedRepository is needed at all as a \nseparate configuration?\n\nIt looks like it might be easier (and less confusing to users) to derive \nthis attribute from the top-level .git directory?\n\nFor many years in our organisation we have been using the scripts below to \nmake it easier for users to configure a repository -- a one-time \noperation.\n\nIs there a reason why Git doesn't just follow (and echo) the top-level \npermissions?\n\nMany thanks\n\n-- \nMark\n\n\n#!/bin/bash\n#\n# Propagate permissions of the top-level directory through a repository,\n# and configure it for use.\n#\n\nif [ \"$1\" = \"--help\" ]; then\n\techo \"Usage: $0 <bare_git_repo>.git\"\n\techo \"Fix permissions on a Git repository, based on the permissions\"\n\techo \"at the top level directory.\"\n\texit 0\nfi\n\nif [ -z \"$1\" ]; then\n\techo \"Repository argument is mandatory (see --help); aborting.\"\n\texit 1\nfi\n\nREPO=\"$1\"\n\nif [ ! -d \"$REPO/objects\" -o ! -f \"$REPO/config\" -o ! -f \"$REPO/HEAD\" ]; then\n\techo \"$REPO does not look like a bare Git repository; aborting.\"\n\texit 1\nfi\n\n# Fix ownership\nchown -cR --reference=\"$REPO\" \"$REPO\"/*\n\n# Fix all the directory permissions after ownership (setting ownership\n# removes setgid bit)\nfind \"$REPO\" -type d | xargs chmod -c --reference=\"$REPO\"\n\n# Fix files\nfind \"$REPO\" -type f | xargs chmod --reference=\"$REPO\"\nfind \"$REPO\" -type f | xargs chmod a-sx\n\n# Tidy up; permissions on object files are always 444\nfind \"$REPO/objects\" -type f | xargs chmod 0444\n\n# Configure the repository to remove the need for further fixes\n# by basing core.SharedRepository on the top level permissions\nPERM=0`stat -c '%a' \"$REPO\"`\nMODE=`printf %04o $(($PERM&0666))` # bash required\nif [ \"$MODE\" = \"0660\" ]; then\n\tMODE=group\nelif [ \"$MODE\" = \"0666\" ]; then\n\tMODE=all\nfi\ngit --git-dir \"$REPO\" repo-config core.sharedRepository \"$MODE\"\nchmod --reference=\"$REPO\" \"$REPO/config\"\nchmod a-sx \"$REPO/config\"\n"},{"id":"200757","messageId":"7vhaq4nc7g.fsf@alter.siamese.dyndns.org","threadId":"31750","inReplyTo":"1210080955590.12283@wes.ijneb.com","subject":"Re: sharedRepository derived from file permissions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-08T16:46:43Z","receivedAt":"2012-10-08T16:46:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Hills <mark@pogo.org.uk> writes:\n\n> We make extensive use of unix permissions and core.sharedRepository -- \n> multiple developers push to the same repo.\n>\n> I have often wondered why core.sharedRepository is needed at all as a \n> separate configuration?\n>\n> It looks like it might be easier (and less confusing to users) to derive \n> this attribute from the top-level .git directory?\n\nHrm, clever ;-)\n\n> Is there a reason why Git doesn't just follow (and echo) the top-level \n> permissions?\n\nOther than \"we did not trust that all the end users are capable of\ndoing the right 'chmod 2775 .git && chgrp project .git\", with a\nlittle bit of \"we didn't think of that when we wrote the system\", I\ndo not recall any.\n"},{"id":"201411","messageId":"1210170009180.2113@vega","threadId":"31750","inReplyTo":"7vhaq4nc7g.fsf@alter.siamese.dyndns.org","subject":"Re: sharedRepository derived from file permissions","fromName":"Mark Hills","fromEmail":"mark@pogo.org.uk","sentAt":"2012-10-16T23:20:56Z","receivedAt":"2012-10-16T23:20:56Z","isPatch":false,"sender":{"key":"mark@pogo.org.uk","avatar":null},"body":"On Mon, 8 Oct 2012, Junio C Hamano wrote:\n\n> Mark Hills <mark@pogo.org.uk> writes:\n> \n> > We make extensive use of unix permissions and core.sharedRepository -- \n> > multiple developers push to the same repo.\n> >\n> > I have often wondered why core.sharedRepository is needed at all as a \n> > separate configuration?\n> >\n> > It looks like it might be easier (and less confusing to users) to derive \n> > this attribute from the top-level .git directory?\n> \n> Hrm, clever ;-)\n> \n> > Is there a reason why Git doesn't just follow (and echo) the top-level \n> > permissions?\n> \n> Other than \"we did not trust that all the end users are capable of\n> doing the right 'chmod 2775 .git && chgrp project .git\", with a\n> little bit of \"we didn't think of that when we wrote the system\", I\n> do not recall any.\n\nThanks. If I understand, you mean it might be worth a try to implement \nthis. For us it would certainly simplify, and reduce mistakes/confusion.\n\nI've yet to look into the code, but I will try and do this. If you have \nany hints or recommendations where to begin then that'd be good.\n\nI think I did peek some years ago to find out that it was non-trivial, and \nthen came up with the script!\n\nI wonder if there are any users who are granting permission to specific \nbranchs or tags or tag directories. I'm not sure if this is really a valid \nuse case, but there might need to be a way to ignore the top-level \nattributes too for some special cases?\n\nThanks\n\n-- \nMark\n"},{"id":"201412","messageId":"7vfw5dpmkv.fsf@alter.siamese.dyndns.org","threadId":"31750","inReplyTo":"1210170009180.2113@vega","subject":"Re: sharedRepository derived from file permissions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-17T07:46:56Z","receivedAt":"2012-10-17T07:46:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Hills <mark@pogo.org.uk> writes:\n\n>> > It looks like it might be easier (and less confusing to users) to derive \n>> > this attribute from the top-level .git directory?\n>> \n>> Hrm, clever ;-)\n>> \n>> > Is there a reason why Git doesn't just follow (and echo) the top-level \n>> > permissions?\n>> \n>> Other than \"we did not trust that all the end users are capable of\n>> doing the right 'chmod 2775 .git && chgrp project .git\", with a\n>> little bit of \"we didn't think of that when we wrote the system\", I\n>> do not recall any.\n>\n> Thanks. If I understand, you mean it might be worth a try to implement \n> this.\n\nNot really.\n\nI still do not think that all the end users are capable of doing the\nright 'chmod 2775 .git && chgrp project .git' themselves.\n"},{"id":"201422","messageId":"1210171258060.22876@wes.ijneb.com","threadId":"31750","inReplyTo":"7vfw5dpmkv.fsf@alter.siamese.dyndns.org","subject":"Re: sharedRepository derived from file permissions","fromName":"Mark Hills","fromEmail":"mark@pogo.org.uk","sentAt":"2012-10-17T12:25:32Z","receivedAt":"2012-10-17T12:25:32Z","isPatch":false,"sender":{"key":"mark@pogo.org.uk","avatar":null},"body":"On Wed, 17 Oct 2012, Junio C Hamano wrote:\n\n> Mark Hills <mark@pogo.org.uk> writes:\n> \n> >> > It looks like it might be easier (and less confusing to users) to derive \n> >> > this attribute from the top-level .git directory?\n> >> \n> >> Hrm, clever ;-)\n> >> \n> >> > Is there a reason why Git doesn't just follow (and echo) the top-level \n> >> > permissions?\n> >> \n> >> Other than \"we did not trust that all the end users are capable of\n> >> doing the right 'chmod 2775 .git && chgrp project .git\", with a\n> >> little bit of \"we didn't think of that when we wrote the system\", I\n> >> do not recall any.\n> >\n> > Thanks. If I understand, you mean it might be worth a try to implement \n> > this.\n> \n> Not really.\n> \n> I still do not think that all the end users are capable of doing the\n> right 'chmod 2775 .git && chgrp project .git' themselves.\n\nBut with the current method, users still have to do this _and_ set \nsharedRepository=.\n\nIt would make things hard or impossible if we assume that a user wanting \nto share a repository does not understand file modes or groups.\n\n-- \nMark\n"}]}