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

落爺英雄遲暮 提交于 2019-11-28 17:58:53
VonC

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.

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

rejon

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!