Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup post-receive-email Git hook with Gitolite

I'm using post-receive-email hook from the Git distribution to send e-mails to certain users when Git repository is updated (hook invoked from post-receive).

All my repositories were managed manually. Now, I get so many repos and so many users and groups that I have to upgrade to some Git repository management system. I picked Gitolite.

But I am a bit at loss on how to configure the e-mail notifications.

Update: I will elaborate the question a bit:

First question is: Where should I put the hook and should I change it somehow so it would work with Gitolite?

Second question:

The standard post-receive-email hook depends on three parameters in *.git/config: hooks.envelopesender, hooks.emailprefix and hooks.mailinglist.

These parameters are, in general, different for each repository that I move under Gitolite. In practice, they are the same for the same permission groups — users, which have access to the repository, receive notifications, others — not.

I would like to avoid editing config file for each repository manually. It would be much more fun if I could configure everything in the same, centralized, place for whole Gitolite.

So, any hints?

like image 730
Alexander Gladysh Avatar asked Feb 20 '11 04:02

Alexander Gladysh


2 Answers

You can look at the doc hook for starters:

where do I (the admin) put the hooks?

In general, all hooks go into the hooks/common directory. Only the special post-update hook meant for the admin repo goes into hooks/gitolite-admin.

But the GitoliteV3 doc on 'mirroring' provides an alternative to a custom hook.


For the second question:

I would like to avoid editing config file for each repository manually.
It would be much more fun if I could configure everything in the same, centralized, place for whole Gitolite.

The doc gitolite.conf is quite clear:

repo specific git config commands

Sometimes you want to specify git config settings for some of your repos.
For example, you may have a custom post-receive hook that sends an email when a push happens, and this hook needs to know whom to send the email to, etc.

You can set git config values by specifying something like this within a "repo" paragraph:

example usage: if you placed a hook in hooks/common that requires configuration information that is specific to each repo, you could do this:

repo gitolite
    config hooks.mailinglist = [email protected]
    config hooks.emailprefix = "[gitolite] "
    config foo.bar = ""
    config foo.baz =

The syntax is simple:

config sectionname.keyname = [optional value_string]

This does either a plain "git config section.key value" (for the first 3 examples above) or "git config --unset-all section.key" (for the last example).
Other forms (--add, the value_regex, etc) are not supported.

Note: this won't work unless the rc file has the right settings; please see comments around the variable $GL_GITCONFIG_KEYS $GIT_CONFIG_KEYS (now in GitoliteV3 or 'g3') in gitolite rc file for details and security information.

like image 134
VonC Avatar answered Nov 15 '22 23:11

VonC


at the moment, this does not work:

repo @all
    config foo.bar = "baz"

I presume you would like it to work, but it's kinda low on my list right now due to other pressures, and the fact that there is a workaround:

@almostall = repo1 repo2 repo3
@almostall = repo4 repo5 repo6 [add as many more as you like]

[... later ...]
repo @almostall
    config foo.bar = "baz"

Hope that helps, and sorry about the oversight on the @all

like image 37
Sitaram Avatar answered Nov 15 '22 22:11

Sitaram