Anil Kumar
Anil Kumar

Reputation: 546

Is it possible to implement repo based hooks in Gitolite?

I want to implements repo based hooks in gitolite.

Is it Possible ?

I am using gitolite 3 (g3).

Upvotes: 3

Views: 550

Answers (2)

Andy J
Andy J

Reputation: 1545

Here's how I set up a post-receive hook (gitolite3 (3.6.12-1) on debian bullseye):

Ensure LOCAL_CODE is set in /etc/gitolite3/gitolite.rc:

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

Next, go to the ENABLE section of your gitolite.rc file, and uncomment repo-specific-hooks:

# allow repo-specific hooks to be added
'repo-specific-hooks',

Change to gitolite3 user, and make the hook dir:

sudo su gitolite3
cd ~
mkdir -p local/hooks/repo-specific

And this is the setup which I think other tutorials miss; you need to (or at least I needed to), re-run setup:

sudo su gitolite3
gitolite setup

If you didn't set up something right, now's the time you'll see the error message:

FATAL: repo-specific-hooks: '/git/local/hooks/repo-specific' does not exist or is not a directory

Then fix whatever it is, and re-run gitolite setup.

Next, inside the repo-specific directory you just created, add your hook script:

sudo su gitolite3
echo "#!/bin/bash" >> ~/local/hooks/repo-specific/hello
echo "echo hello world" >> ~/local/hooks/repo-specific/hello
chmod +x hello

Modify gitolite.conf:

cd gitolite-admin
vim conf/gitolite.conf

Add the hooks to each repo like so:

repo linux
option hook.post-receive = hello
...

Push the changes to the gitolite-admin repo and enjoy.

Upvotes: 0

VonC
VonC

Reputation: 1324887

Since Gitolite 3.6+, it is possible with "repo-specific hooks":

  • add this line in the rc file, within the %RC block, if it's not already present, or uncomment it if it's already present and commented out:
LOCAL_CODE => "$rc{GL_ADMIN_BASE}/local",
  • uncomment the 'repo-specific-hooks' line in the rc file or add it to the ENABLE list if it doesn't exist.

  • If your rc file does not have an ENABLE list, you need to add this to the POST_COMPILE and the POST_CREATE lists. Click here for more on all this.

  • put your hooks into your gitolite-admin clone, as follows:

# on your workstation
cd /path/to/your/gitolite-admin-clone
mkdir -p local/hooks/repo-specific
  • Now add your hooks to that directory, but instead of using the git "standard" names (pre-receive, post-receive, post-update), you use descriptive names (e.g. "deploy", "RSS-post", etc).

  • add them to the repos you want them to be active in, in your conf file. For example:

repo foo
    option hook.post-update     =   jenkins
repo bar @baz
    option hook.post-update     =   deploy RSS-post
  • add, commit, and push the admin repo.

Upvotes: 3

Related Questions