1

I've setup a development/testing server where developers can push repositories to a remote repo/webserver via gitolite/git. On the repository site everything works well and developers can use the server however:

Problem:

I want to deploy the code to an apache documentroot (chown'd apache:apcahe and chmod'd 755). I am following these instructions and when edit my post-receive hook as describe like so:

#!/bin/sh
echo "deploying to DocumentRoot"
GIT_WORK_TREE=/var/www/www.example.com git checkout -f

however now when I run git push from my local repo I get permissions errors like:

error: git checkout-index: unable to create file .gitignore (Permission denied)
error: git checkout-index: unable to create file .htaccess (Permission denied)

And my document root is empty...The post-receive hook is running as the user 'gitolite' (not sure whether that's important).

gitolite is already in the sudoers list so I want to run something like:

GIT_WORK_TREE=/var/www/www.example.com sudo git checkout -f

but this doesn't seem to work either, I want to avoid calling a separate shell script if possible.

Any ideas would be really appreciated.

Community
  • 1
  • 1
Alex
  • 3,732
  • 5
  • 37
  • 59
  • 1
    Any possibility to ensure `gitolite` user is in the same group than the `apache` account? – VonC Mar 14 '13 at 12:55
  • just added the gitolite user to the apache group and ran post-recieve hook with sudo now I get: fatal: You are on a branch yet to be born -- ps: how do you do the highlighting in comments? – Alex Mar 14 '13 at 13:39
  • thanks to @VonC I fixed this but the answer was to do "sudo GIT_WORK_TREE=..... git checkout -f" – Alex Mar 14 '13 at 14:03
  • 1
    By the way, using `\`` allows you to highlight within comments. – VonC Mar 14 '13 at 14:10

1 Answers1

3

First, make sure the git account is in the same group than the apache account.
(Or you need to go back to my previous answer that you want to avoid)

You report this works:

 sudo GIT_WORK_TREE=..... git checkout -f

But with a bare repo, you could also see get:

 fatal: You are on a branch yet to be born

(I wouldn't recommend trying to make your gitolite-managed bare repo a non-bare one as in this blog post

git config core.worktree /home/user/myproject
git config core.bare false
git config receive.denycurrentbranch ignore

)

I prefer making sure /var/www/www.example.com directory is a git repo, in which you can pull, instead of trying to checkout.
So the hook I like is more:

cd /var/www/www.example.com
git --git-dir=/var/www/www.example.com/.git --git-work-tree=/var/www/www.example.com pull

(with origin, the remote name which is used by default by git pull, refering to the gitolite bare repo)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • nice.. it turned out that what I was doing worked perfectly except that (a) permissions were a problem. (b) sudo was in the wrong place. Many thanks VonC – Alex Mar 14 '13 at 14:10