16

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?

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160

4 Answers4

18

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 = gitolite-commits@example.tld
    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.

merlin2011
  • 71,677
  • 44
  • 195
  • 329
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • OK, seems that it should work. Is there a nice way to centralize hook configuration parameters for all repositories (`hooks.envelopesender`, `hooks.emailprefix`, `hooks.envelopesender`)? – Alexander Gladysh Feb 21 '11 at 11:27
  • @Alexander: all hooks are centralized in `hooks/common` within your local copy of `gitolite`. Script `easy-install` will update it to the remote `gitolite-admin` and copy those hooks to each repos. – VonC Feb 21 '11 at 11:40
  • @VonC: That I understand. But post-receive-email hook has its own configuration parameters (living in `*.git/config`). I understand that now I have to manually edit `config` file for each repository. This does not sound like much fun. I would like to do this from the one central place, just like I do with repository permissions. – Alexander Gladysh Feb 21 '11 at 11:48
  • 1
    @Alexander: git config`` has three levels of configuration: the global config (in the homedir of `gitadmin`: `~/.gitconfig`) should be a natural spot for... 'global' (as in 'valid for all repos') config – VonC Feb 21 '11 at 11:53
  • @VonC: No, that would not work: these parameters are, obviously, different for each gitolite access group — e-mail notifications are sent only to the participants. – Alexander Gladysh Feb 21 '11 at 12:08
  • 1
    @Alexander: right, so that means you need to change the classic email notification hook in order to get the list of participants based on what gitolite has compiled in its own config admin file. – VonC Feb 21 '11 at 12:12
  • @VonC: and that is the main point of my question (sorry for not being clear): how to do this? – Alexander Gladysh Feb 21 '11 at 12:16
  • @VonC: Thank you! Almost there. Is there a way to configure this per access group and not per repository? (If not, I guess, I can always generate `gitolite.conf`) – Alexander Gladysh Feb 21 '11 at 13:05
  • @Alexander: I didn't se that kind of level for gitconfig parameter. – VonC Feb 21 '11 at 13:44
6

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

Sitaram
  • 61
  • 1
  • Yes, that would be cool and will make my config much prettier. But this does not solve all my problems, as I would like to be able to auto-configure hooks.mailinglist so it would be composed from e-mails of the users who have access to the each repo. – Alexander Gladysh Mar 03 '11 at 12:03
1

The gitolite cookbook tells how to configure hooks:

1. Enable local non-core programs in gitolite

Edit the gitolite configuration file (usually ~git/.gitolite.rc) and uncomment the following line:

LOCAL_CODE => "$rc{GL_ADMIN_BASE}/local"

Ensure to read the security warnings.

2. Enable repository specific hooks

Uncommenting the repo-specific-hooks line in the gitolite configuration file.

3. Add the email hook

Put the correspondig post-receive hook executable (I use git-multimail) in your gitolite-admin repository as the file /local/hooks/repo-specific/git-multimail.

Commit and push it.

4. Configure settings for multimail hook

To allow adding config keys via the gitolite config file edit the gitolite config file ~git/.gitolite.rc and update the following line:

GIT_CONFIG_KEYS => ".*"

Ensure to read the security warning. You may want to narrow it down to GIT_CONFIG_KEYS => "multimailhook\..*".

5. Configure the multimail email hook

This is an example configuration of the gitolite.conf file in the gitolite-admin repository:

repo @all
    config multimailhook.environment      = gitolite
    config multimailhook.from             = git@gitserver.com
    config multimailhook.mailinglist      = your@email.com

repo xyz
    option hook.post-receive = git-multimail

I decided to use repo specific hooks and store them in the gitolite-admin repository. Alternatively, you could use global hooks (/local/hooks/common) or store them somewhere else on the gitolite server and point LOCAL_CODE there.

romor
  • 1,181
  • 15
  • 22
1

Here is a quick one liner to add descriptions to your gitolite.conf with the same name as the repo. You need this if you are using this big @almostall approach and gitolite so that you have descriptions for each repo. This saved me an hour of typing, so had to share:

Try first:

sed 's/^\(repo *\)\(.*\)/\1\2\n\t\t\2 = "\2"/' gitolite.conf

Then try with edit in place, but still make a backup prior:

cp gitolite.conf gitolite.conf.backup

Then do edit in place:

sed -i 's/^\(repo *\)\(.*\)/\1\2\n\t\t\2 = "\2"/' gitolite.conf

Cheers!

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356