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
, h开发者_StackOverflowooks.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?
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 theadmin
repo goes intohooks/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
, thevalue_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 gitoliterc
file for details and security information.
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
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!
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.
精彩评论