{"thread":{"id":"18908","subject":"git for local web development","startedAt":"2009-04-16T23:04:10Z","lastAt":"2009-04-17T22:00:15Z","messageCount":6,"participants":["William DiNoia","Jeff King","Martin Langhoff"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"111468","messageId":"135754252540163221910297561025355826788-Webmail@me.com","threadId":"18908","inReplyTo":null,"subject":"git for local web development","fromName":"William DiNoia","fromEmail":"william.dinoia@mac.com","sentAt":"2009-04-16T23:04:10Z","receivedAt":"2009-04-16T23:04:10Z","isPatch":false,"sender":{"key":"william.dinoia@mac.com","avatar":null},"body":"Hello,\n\nI am having a bit of trouble trying to setup git for web development. I would like to have a git repository in /var/www/sites which I can clone and work on from my ~/Desktop. Working from the desktop clone, I would like to be able to git-push and have the work tree updated. It seems this is a common request as it is in the FAQ, Why won't I see changes in the remote repo after \"git push\"?\n\nThis is what I've done...\n\nas www-data from /var/www/sites/\n\n$mkdir test.com\n$cd test.com\n$git-init\n$git-config core.worktree /var/www/sites/test.com\n$vim .git/hooks/post-receive\n #!/bin/sh\n git-checkout -f\n$chmod +x .git/hooks/post-receive\n\nThen as william from /home/william/Desktop/\n\n$git-clone /var/www/sites/test.com\n$cd test.com\n$vim index.html\n testing, testing, 1,2\n$git-add index.html\n$git-commit\n$git-push origin master\n\nSomething like the following is returned, and the work tree at /var/www/sites/test.com is not updated\n\nCounting objects: 5, done.\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (3/3), 277 bytes, done.\nTotal 3 (delta 1), reused 0 (delta 0)\nUnpacking objects: 100% (3/3), done.\nTo /var/www/sites/test.com/.git\n   9b490a2..5e5cc63  master -> master\nerror: unable to unlink old 'index.html' (Permission denied)\nerror: hooks/post-receive exited with error code 1\n\nThe interesting part is that if I change to /var/www/sites/test.com and run \"git-checkout -f\" it updates the work tree...\nShould I be using a different hook? \nIs there something wrong with the script?\nIs there a better, more elegant way to achieve updating of the work tree? \n"},{"id":"111481","messageId":"20090417115925.GB29121@coredump.intra.peff.net","threadId":"18908","inReplyTo":"135754252540163221910297561025355826788-Webmail@me.com","subject":"Re: git for local web development","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-17T11:59:25Z","receivedAt":"2009-04-17T11:59:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 16, 2009 at 07:04:10PM -0400, William DiNoia wrote:\n\n> I would like to be able to git-push and have the work tree updated.\n>\n> [...]\n>\n> $vim .git/hooks/post-receive\n>  #!/bin/sh\n>  git-checkout -f\n> $chmod +x .git/hooks/post-receive\n>\n> [...]\n>\n> Counting objects: 5, done.\n> Compressing objects: 100% (2/2), done.\n> Writing objects: 100% (3/3), 277 bytes, done.\n> Total 3 (delta 1), reused 0 (delta 0)\n> Unpacking objects: 100% (3/3), done.\n> To /var/www/sites/test.com/.git\n>    9b490a2..5e5cc63  master -> master\n> error: unable to unlink old 'index.html' (Permission denied)\n> error: hooks/post-receive exited with error code 1\n\nWell, your post-receive hook is running, and checkout is barfing with a\npermission denied error. Probably the repo directory is owned by\nwww-data, and you are pushing as user \"william\"? What are the directory\npermissions like?\n\n-Peff\n"},{"id":"111499","messageId":"loom.20090417T153819-898@post.gmane.org","threadId":"18908","inReplyTo":"20090417115925.GB29121@coredump.intra.peff.net","subject":"Re: git for local web development","fromName":"William DiNoia","fromEmail":"william.dinoia@mac.com","sentAt":"2009-04-17T15:44:43Z","receivedAt":"2009-04-17T15:44:43Z","isPatch":false,"sender":{"key":"william.dinoia@mac.com","avatar":null},"body":"Jeff King <peff <at> peff.net> writes:\n\n> \n> On Thu, Apr 16, 2009 at 07:04:10PM -0400, William DiNoia wrote:\n> \n> > I would like to be able to git-push and have the work tree updated.\n> >\n> > [...]\n> >\n> > $vim .git/hooks/post-receive\n> >  #!/bin/sh\n> >  git-checkout -f\n> > $chmod +x .git/hooks/post-receive\n> >\n> > [...]\n> >\n> > Counting objects: 5, done.\n> > Compressing objects: 100% (2/2), done.\n> > Writing objects: 100% (3/3), 277 bytes, done.\n> > Total 3 (delta 1), reused 0 (delta 0)\n> > Unpacking objects: 100% (3/3), done.\n> > To /var/www/sites/test.com/.git\n> >    9b490a2..5e5cc63  master -> master\n> > error: unable to unlink old 'index.html' (Permission denied)\n> > error: hooks/post-receive exited with error code 1\n> \n> Well, your post-receive hook is running, and checkout is barfing with a\n> permission denied error. Probably the repo directory is owned by\n> www-data, and you are pushing as user \"william\"? What are the directory\n> permissions like?\n> \n> -Peff\n\nI have since switched to using the post-update hook which now looks like:\n\ngit-checkout -f\nexec git-update-server-info\n\nHowever upon git-push from /home/william/Desktop I receive the following:\n\nCounting objects: 5, done.\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (3/3), 281 bytes, done.\nTotal 3 (delta 1), reused 0 (delta 0)\nUnpacking objects: 100% (3/3), done.\nTo /var/www/sites/test.com/.git\n   e337c9b..581228f  master -> master\nerror: unable to unlink old 'index.html' (Permission denied)\n\nThe repo is owned by \"www-data\" and I am pushing as user \"william\". \"william\"\nis in the \"www-data\" group. I also ran\n\ngit-config core.sharedrepository group\n\nas \"www-data\", but no change...\n"},{"id":"111514","messageId":"20090417183046.GB30240@coredump.intra.peff.net","threadId":"18908","inReplyTo":"loom.20090417T153819-898@post.gmane.org","subject":"Re: git for local web development","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-17T18:30:46Z","receivedAt":"2009-04-17T18:30:46Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Apr 17, 2009 at 03:44:43PM +0000, William DiNoia wrote:\n\n> I have since switched to using the post-update hook which now looks like:\n> \n> git-checkout -f\n> exec git-update-server-info\n\nThat will ignore any error code from git-checkout; you probably want\n\n  git checkout -f && git update-server-info\n\n> However upon git-push from /home/william/Desktop I receive the following:\n> \n> Counting objects: 5, done.\n> Compressing objects: 100% (2/2), done.\n> Writing objects: 100% (3/3), 281 bytes, done.\n> Total 3 (delta 1), reused 0 (delta 0)\n> Unpacking objects: 100% (3/3), done.\n> To /var/www/sites/test.com/.git\n>    e337c9b..581228f  master -> master\n> error: unable to unlink old 'index.html' (Permission denied)\n\nSo this is the same error as before, because it is coming from the\n\"git-checkout -f\" invocation.\n\n> The repo is owned by \"www-data\" and I am pushing as user \"william\". \"william\"\n> is in the \"www-data\" group. I also ran\n> \n> git-config core.sharedrepository group\n> \n> as \"www-data\", but no change...\n\nThe error is in the permissions of the working tree that already exists.\ncore.sharedrepository is about the settings that git uses for files within\n$GIT_DIR. The working tree files that already exist are not changed.\n\nI suspect if you \"ls -ld /var/www/sites/test.com\" you will see that it\ndoes not have group write permissions.  If that is the case, it is\nprobably simplest to just add group write permissions to the whole\ntree:\n\n  find /var/www/sites/test.com -name .git -prune -o -print0 |\n    xargs -0 chmod g+w\n\nI don't recall offhand whether newly created files in the working tree\nwill have the group and permissions set according to\ncore.sharedrepository (I think sharedrepository is usually about users\nsharing a common repo for pushing into).\n\nIf you are just going to push as \"william\", is there a reason that the\nrepo and working tree are not owned by \"william\"? As long as www-data,\npresumably the webserver could still serve it.\n\n-Peff\n"},{"id":"111524","messageId":"46a038f90904171148xefb2085yc47e58c62cd3bbaf@mail.gmail.com","threadId":"18908","inReplyTo":"20090417183046.GB30240@coredump.intra.peff.net","subject":"Re: git for local web development","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2009-04-17T18:48:13Z","receivedAt":"2009-04-17T18:48:13Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On Fri, Apr 17, 2009 at 8:30 PM, Jeff King <peff@peff.net> wrote:\n> repo and working tree are not owned by \"william\"? As long as www-data,\n> presumably the webserver could still serve it.\n\nAlso, as long as they are owned by www-data, the setup is more\nvulnerable to security problems.\n\nFiles served by Apache (or any other webserver) should _not_ be owned\nby the same user that the webserver runs under. The www-data ownership\nis exclusively for files that you expect the webserver to be able to\n_modify_: files uploaded by users, session data files, sqlite\ndatabases and such.\n\nYou don't really want your webserver changing executable files such as PHP.\n\nIt is a valid thing to create a user to own those files, and in\nservers where a team was maintaining the code, we have often used\n'www-code'.\n\ncheers,\n\n\n\nm\n-- \n martin.langhoff@gmail.com\n martin@laptop.org -- School Server Architect\n - ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n - http://wiki.laptop.org/go/User:Martinlanghoff\n"},{"id":"111539","messageId":"loom.20090417T215435-430@post.gmane.org","threadId":"18908","inReplyTo":"20090417183046.GB30240@coredump.intra.peff.net","subject":"Re: git for local web development","fromName":"William DiNoia","fromEmail":"william.dinoia@mac.com","sentAt":"2009-04-17T22:00:15Z","receivedAt":"2009-04-17T22:00:15Z","isPatch":false,"sender":{"key":"william.dinoia@mac.com","avatar":null},"body":"Jeff King <peff <at> peff.net> writes:\n\n> If you are just going to push as \"william\", is there a reason that the\n> repo and working tree are not owned by \"william\"? As long as www-data,\n> presumably the webserver could still serve it.\n> \n> -Peff\n> \n\nSolved...\n\nI took your advice and changed the owner of /var/www/var/sites to \"william\".\nIt pushes and the post-update hook checks out the pushed files to adjacent work\ntree. I was mistakenly under the impression that Apache could only read files\nowned by \"www-data\".\n\nThank you for your help,\nWilliam\n"}]}