Question

I don't understand how do I create a post-receive hook for a specific repository in gitolite (non-root install)

My bare repository contains a website that should copy the working directory to the docRoot (GIT_WORK_TREE=/path/htdocs git checkout -f) on update

Before gitolite, I would just update the hook for the specific repository.
Gitolite documentation mentions that all hooks should be at hooks/common so I don't understand how it works.

What should be the name of hooks, where it should be located and how it's structure should be changed (if it should)?

Was it helpful?

Solution

Update July 2013: what follows is for gitolite V2 (or 'g2'), which was the version used by the OP at the time (November 2011).

Update August 2013, with the latest gitolite 3.x: You now have official specific repo hook:

it's basically just creating a symlink in <repo.git>/hooks pointing to some file inside $rc{LOCAL_CODE}/hooks/repo-specific (except the gitolite-admin repo)


All hooks in gitolite/hooks/common are replicated in all repositories managed by Gitolite, as detailed in the hook propagation documentation.
That means your hook script must take specific action depending on the repo which execute said hook.

You can either use the $GL_REPO variable (which gitolite set and pass to all its scripts for any git command it receives).

Or you can use some git configuration registered on the gitolite server, like the mirroring hook does. See the post-receive.mirrorpush hook.

The OP Eyal R adds in the comments:

But I still don't understand how it is done (I understand that $GL_REPO is used to determine which repo I am updating but I'm missing the practical part).
I have created a file called post-receive.test with echo "test", put it in $HOME/gitolite/hooks/common, ran gl-setup, ran push from workstation - nothing happens (no "test" output)

To which I replied:

The hook should appear in the hook directory of your repo on the gitolite server as a link, linking back to the .gitolite/common/hook. Note that it should be in $HOME/.gitolite/common/hook, not /gitolite.

The OP confirms the missing dot was the issue.

The process to add an hook is detailed in Hook propagation in gitolite, and their usage in "Using Hooks".

OTHER TIPS

This is a fairly common need for someone using gitolite, and appears to be a little difficult to tie up loose ends when being not a very advanced user (at leas it was for me).

Following stackoverflow's and gitolite's links back and forth can be a little confusing. These are my conclusions and the path I followed to be able to achieve this.

As @VonC mentioned creating repository specific hooks is already possible since version 3.5.3.1 (github link)

Update/Upgrade Gitolite

The first thing you should do is update your gitolite repo. So ssh into your server that is hosting gitolite and move to the location where gitolite is installed (usually /home/git/gitolite) as the git user (usually git)

Example:

$ ssh myusername@devserver.com
$ sudo su - git
$ pwd
/home/git
$ cd gitolite

Then we have to upgrade gitolite. To do so, first we need to update the gitolite repository

$ git pull

Then we have to repeat the install command (make sure you use the same arguments as before)

$ ./install

And finally run the setup again.

$ gitolite setup

If that doesn't work, you probably haven't set up gitolite executable in your PATH, so you could do something like this:

$ src/gitolite setup

Gitolite Settings (The "RC" file)

This was one of the parts that confused me the most, but it ended up it was pretty straight forward.

The famous "rc" file is located at git's home directory /home/git/.gitolite.rc. There make sure you have a variable called LOCAL_CODE, you should see something like this on that file, if not, add it.

LOCAL_CODE => "$ENV{HOME}/.gitolite/local"

And in the "commands an feature to enable" section you should make sure that repo-specific-hooks is available, if not, add it.

ENABLE => [

    # COMMANDS

        # These are the commands enabled by default
        'help',
        'desc',
        'info',
        ...,
        ...,
        ...,
        'repo-specific-hooks'
        ...,
        ...,
        ...
]

Here is the link to the documentation

Writing Repository Specific Hooks

Finally, in your local gitolite-admin repository create the following directories hooks/repo-specific under the directory you just set in the LOCAL_CODE variable, for example:

gitolite_admin/local/hooks/repo-specific

After that you can actually add your hooks scripts to that location and manage them through the gitolite conf file as stated in the documentation. Make sure the scripts are executable.

repo foo
RW+                       =   @all
option hook.post-receive  =   deploy

Again, I hope this helps some of you guys.

Cheers!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top