{"thread":{"id":"2898","subject":"How to set up a shared repository","startedAt":"2005-12-21T18:27:19Z","lastAt":"2005-12-21T21:36:47Z","messageCount":3,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"13878","messageId":"Pine.LNX.4.63.0512211919040.16640@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2898","inReplyTo":null,"subject":"How to set up a shared repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-21T18:27:19Z","receivedAt":"2005-12-21T18:27:19Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nI installed a shared git repository in the last few days and this is the \nresult. May it be useful!\n\nCiao,\nDscho\n\n---\n\n[Note: this text assumes you have applied the core.umask patch]\n\nSo, there you are. You know CVS (or at least its concepts), and you want \nto set up a shared repository.\n\nA. Setting up the umask\n\n1. Separate repository box\n\nIf you are lucky enough that you can afford a separate machine for the \nshared repository: Good. Just make sure that the umask is set group \nfriendly, either by ensuring that (assuming the login shell is bash) \n$HOME/.bash_profile contains the line\n\n\tumask 0002\n\nor by using git-shell, which you have modified by inserting\n\n\tumask(0002);\n\nat the start of main().\n\n2. Some server accessible by ssh\n\nIf there are valid reasons not to set umask (maybe you want to allow other \nuses of that machine), or if you just do not want to go through the hassle \nto find out which scripts your login shell executes at startup, you just \nhave to\n\n\tgit-repo-config core.umask 0002\n\n\nB. Making sure the index is not corrupted by a push\n\n1. No checkout!\n\nYou can use the shared repository just like you use CVS: no working \ndirectory. To disallow a checkout, just do\n\n\ttouch .git/index\n\tchmod a-rwx .git/index\n\nEvery attempt to modify the index (which is invalid), will now result in \nan error.\n\n2. Ensure index and working directory consistency (no locking)\n\nIf you want to be able to work on the project in the shared repository, \ncreate hooks, as follows:\n\n\ttest -d .git/hooks || mkdir .git/hooks\n\n\tcat > .git/hooks/update << EOF\n\t#!/bin/sh\n\t\n\t# if the working directory contains modifications, do not allow push\n\tHEAD=$(git-symbolic-ref HEAD)\n\tcase \"$1\" in\n\t$HEAD)\n\t        unset GIT_DIR\n\t        cd .. && test -z \"$(git-diff-index --name-only HEAD)\";;\n\tesac\n\tEOF\n\n\tchmod a+x .git/hooks/update\n\n\tcat > .git/hooks/post-update << EOF\n\t#!/bin/sh\n\t\n\t# checkout HEAD, and build\n\tHEAD=$(git-symbolic-ref HEAD)\n\tcase \"$1\" in\n\t$HEAD)\n\t        unset GIT_DIR\n\t\tumask 0002\n\t\tcd .. && git checkout -f HEAD && make;;\n\tesac\n\tEOF\n\n\tchmod a+x .git/hooks/post-update\n\nThis assumes that your project contains a Makefile, and that the tools\nnecessary to build are installed on the repository server.\n\nNote that I did not check if a push locks another push.\n"},{"id":"13886","messageId":"7vy82e5ftx.fsf@assigned-by-dhcp.cox.net","threadId":"2898","inReplyTo":"Pine.LNX.4.63.0512211919040.16640@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: How to set up a shared repository","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-21T20:56:58Z","receivedAt":"2005-12-21T20:56:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> A. Setting up the umask\n>\n> 1. Separate repository box\n>\n> If you are lucky enough that you can afford a separate machine for the \n> shared repository: Good. Just make sure that the umask is set group \n> friendly, either by ensuring that (assuming the login shell is bash) \n> $HOME/.bash_profile contains the line\n>\n> \tumask 0002\n\nI suspect a bash started from ssh noninteractive session does\nnot read .bash_profile --- you may want to check.\n\n> 2. Some server accessible by ssh\n>\n> \tgit-repo-config core.umask 0002\n\nNot yet ;-)\n\n> B. Making sure the index is not corrupted by a push\n>\n> 1. No checkout!\n>\n> You can use the shared repository just like you use CVS: no working \n> directory. To disallow a checkout, just do\n>\n> \ttouch .git/index\n> \tchmod a-rwx .git/index\n>\n> Every attempt to modify the index (which is invalid), will now result in \n> an error.\n\nArrrgh....what a hack.  But it is a good hack.\n\n> 2. Ensure index and working directory consistency (no locking)\n>\n> If you want to be able to work on the project in the shared repository, \n\nI am very tempted to end this sentence with \"please don't\" ;-).\n\n> create hooks, as follows:\n\nYour update hook looks sane if too strict.  I do not think of\nany reason to push and fast forward a branch that is not pointed\nat by .git/HEAD.  Not that I encourage pushing into a non-naked\nrepository where an uncontrolled random development happens,\nthough.\n\n> Note that I did not check if a push locks another push.\n\nAlthough it does protect against stomping on each other by\nread/do-work/re-read-and-swap cycle, push does not lock. If you\nwant to run a build from the post-update hook you need to\nserialize the build yourself.\n"},{"id":"13891","messageId":"Pine.LNX.4.63.0512212222430.18118@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2898","inReplyTo":"7vy82e5ftx.fsf@assigned-by-dhcp.cox.net","subject":"Re: How to set up a shared repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-21T21:36:47Z","receivedAt":"2005-12-21T21:36:47Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 21 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > A. Setting up the umask\n> >\n> > 1. Separate repository box\n> >\n> > If you are lucky enough that you can afford a separate machine for the \n> > shared repository: Good. Just make sure that the umask is set group \n> > friendly, either by ensuring that (assuming the login shell is bash) \n> > $HOME/.bash_profile contains the line\n> >\n> > \tumask 0002\n> \n> I suspect a bash started from ssh noninteractive session does\n> not read .bash_profile --- you may want to check.\n\nYes, you're right. But after all, this section was meant to put a little \npressure on you to agree to core.umask ;-)\n\n> > 2. Some server accessible by ssh\n> >\n> > \tgit-repo-config core.umask 0002\n> \n> Not yet ;-)\n\nWell, it is a reality here ;-)\n\n> > B. Making sure the index is not corrupted by a push\n> >\n> > 1. No checkout!\n> >\n> > You can use the shared repository just like you use CVS: no working \n> > directory. To disallow a checkout, just do\n> >\n> > \ttouch .git/index\n> > \tchmod a-rwx .git/index\n> >\n> > Every attempt to modify the index (which is invalid), will now result in \n> > an error.\n> \n> Arrrgh....what a hack.  But it is a good hack.\n\nIt is the simplest way to achieve the goal (at least that I could think \nof). Thanks for the compliment!\n\n> > 2. Ensure index and working directory consistency (no locking)\n> >\n> > If you want to be able to work on the project in the shared repository, \n> \n> I am very tempted to end this sentence with \"please don't\" ;-).\n\nYou are very welcome to do so!\n\nOf course, the use case is git itself. I host a private version with all \nthe goodies I like so much, and which you unfortunately do not like as \nmuch.\n\nIt is a phantastic way to keep git up to date without having to login \nmanually. It is also a phantastic way to break the setup spectacularly \nwhen something goes wrong.\n\n> > create hooks, as follows:\n> \n> Your update hook looks sane if too strict.  I do not think of\n> any reason to push and fast forward a branch that is not pointed\n> at by .git/HEAD.  Not that I encourage pushing into a non-naked\n> repository where an uncontrolled random development happens,\n> though.\n\nIs it too strict?\n\n:        #!/bin/sh\n:        \n:        # if the working directory contains modifications, do not allow \n:        # push\n\nThis checks if the ref being pushed is the current HEAD:\n\n:        HEAD=$(git-symbolic-ref HEAD)\n:        case \"$1\" in\n:        $HEAD)\n\nOnly if it is, this check occurs\n\n:                unset GIT_DIR\n:                cd .. && test -z \"$(git-diff-index --name-only HEAD)\";;\n:        esac\n\nIMHO this does exactly the right thing: Fail only if the ref to push is \nthe current HEAD *and* something is not committed.\n\n> > Note that I did not check if a push locks another push.\n> \n> Although it does protect against stomping on each other by\n> read/do-work/re-read-and-swap cycle, push does not lock. If you\n> want to run a build from the post-update hook you need to\n> serialize the build yourself.\n\nYes, I feared that much. Also note that in my dangerous setup, something \ncould go awfully wrong because post-update is currently compiling git \nitself, while somebody else wants to use it.\n\nSo, more and more I think about it, I should not do it then. But for a few \ndays, I am the only user!\n\nThanks,\nDscho\n"}]}