5

I've setup GitLab and am using it to host my Git repositories. Now what I'm trying to do is setup a post-receive hook so that I can develop in a folder called site_dev then push my changes so they're automatically pulled into the site folder.

All morning I've been trying to get this hook to work however I've not had any luck executing any commands with GitLab running on Ubuntu Server, I know that the resque service is running and my workers are active.

Currently I have:

#!/bin/bash
LIVE="/var/www/teamnet"
# read oldrev newrev refname
# if [ $refname = "refs/heads/master" ]; then
  echo "===== DEPLOYING TO LIVE SITE ====="
  cd $LIVE || exit
  unset GIT_DIR
  git pull
  echo "===== DONE ====="
# fi

Attempting to pull my changes.

I'm not sure whether I've done something wrong here... All folders are in the same location /var/www/ on the same server. And yes, I have ran chmod +x on the hook.

Yes, I've ran git init --bare for the live folder and set the origin to the Git repository. I'm a little confused however as to where this hook should live, the live/dev folder?

James
  • 5,137
  • 5
  • 40
  • 80

1 Answers1

2

With Gitolite, which is used by GitLab, you must declare your post-receive hook as VREF (that I detail here).

That supposes that your .gitolite.rc contains a LOCAL_CODE variable (see this script) in order to store your VREFs in a directory of your choice.

Then you can associate that VREF (which is just an hook executable) to one or many repo in the gitolite.conf of the gitolite-admin repo. (manually, since there is no interface for that through GitLab)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is there a walkthrough for doing this with regards to GitLab? :) – James Dec 11 '12 at 14:59
  • @James not that I know of: I clone myself the gitolite-admin repo on the gitlab server (anywhere), make my modif and push back. – VonC Dec 11 '12 at 15:03
  • Okay, but I'm still none-the-wiser as to how I set this hook up? Does it go on the dev repository or the live one, or neither and instead the server? – James Dec 11 '12 at 15:06
  • Right, now I've managed to find `.gitolite.rc` I don't see the `LOCAL_CODE` variable, so if I follow your link and add it in, where do I go from there? – James Dec 11 '12 at 15:21
  • That kind of Vref is set on the device repo, managed by gitolite & gitlab. Its action is to switch to the live repo and pull. – VonC Dec 11 '12 at 15:29
  • So I'd go into the `*.git` repo and add the action there? – James Dec 11 '12 at 15:33
  • Is it safe to delete the `post-receive` hook that's already been created and symlinked? – James Dec 11 '12 at 15:34
  • Wahey! Now I just need to fix the permissions as I'm getting "The remote end hung up unexpectedly" which I assume is because the `git` user is trying to pull? – James Dec 11 '12 at 15:40
  • If it is one you have created, yes. – VonC Dec 11 '12 at 15:49
  • Yes, you need to be sure the user git is authorized to pull. – VonC Dec 11 '12 at 16:00
  • How do I do this? I can't login as the git user to get the ssh key? – James Dec 11 '12 at 16:04
  • Yet git becomes a user like any other, which must be granted access to the project in order to pull. – VonC Dec 11 '12 at 16:09