简体   繁体   English

如何使用Gitolite设置post-receive-email Git hook

[英]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 ). 我正在使用Git发行版的post-receive-email挂钩,在Git存储库更新时从某些用户发送电子邮件(从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. 现在,我得到了很多回购和许多用户和组,我必须升级到一些Git存储库管理系统。 I picked Gitolite. 我选了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? 第一个问题是:我应该把钩子放在哪里,我应该以某种方式改变它以便它可以与Gitolite一起使用?

Second question: 第二个问题:

The standard post-receive-email hook depends on three parameters in *.git/config : hooks.envelopesender , hooks.emailprefix and hooks.mailinglist . 标准的post-receive-email挂钩取决于*.git/config三个参数: hooks.envelopesenderhooks.emailprefixhooks.mailinglist

These parameters are, in general, different for each repository that I move under Gitolite. 对于我在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. 我想避免手动编辑每个存储库的config文件。 It would be much more fun if I could configure everything in the same, centralized, place for whole Gitolite. 如果我可以在整个Gitolite的同一个集中位置配置所有内容,那会更有趣。

So, any hints? 那么,有什么提示吗?

You can look at the doc hook for starters: 您可以查看初学者的doc hook

where do I (the admin) put the hooks? 我在哪里(管理员)挂钩?

In general, all hooks go into the hooks/common directory. 通常,所有挂钩都进入hooks/common目录。 Only the special post-update hook meant for the admin repo goes into hooks/gitolite-admin . 只有用于admin repo的特殊更新后挂钩才能进入hooks/gitolite-admin

But the GitoliteV3 doc on 'mirroring' provides an alternative to a custom hook. 但是关于'镜像'GitoliteV3 文档提供了自定义钩子的替代方案。


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. 如果我可以在整个Gitolite的同一个集中位置配置所有内容,那会更有趣。

The doc gitolite.conf is quite clear: doc gitolite.conf很清楚:

repo specific git config commands repo特定的git config命令

Sometimes you want to specify git config settings for some of your repos. 有时你想为你的一些仓库指定git config设置。
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. 例如,您可能有一个自定义的post-receive挂钩,在推送发生时发送电子邮件,此挂钩需要知道将电子邮件发送给谁,等等。

You can set git config values by specifying something like this within a "repo" paragraph: 您可以通过在“repo”段落中指定类似的内容来设置git config值:

example usage: if you placed a hook in hooks/common that requires configuration information that is specific to each repo, you could do this: 示例用法:如果您在hooks/common中放置了一个需要特定于每个repo的配置信息的hooks/common ,那么您可以这样做:

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). 这可以是一个简单的“ git config section.key value ”(对于上面的前三个例子)或“ git config --unset-all section.key ”(对于最后一个例子)。
Other forms ( --add , the value_regex , etc) are not supported. 不支持其他形式( - --addvalue_regex等)。

Note: this won't work unless the rc file has the right settings; 注意:除非rc文件具有正确的设置,否则这将不起作用; 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. $GIT_CONFIG_KEYS rc文件中的 $GIT_CONFIG_KEYS (现在在GitoliteV3或'g3'中 ),以获取详细信息和安全信息。

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 希望有帮助,并对@all的疏忽感到抱歉

The gitolite cookbook tells how to configure hooks: gitolite cookbook讲述了如何配置钩子:

1. Enable local non-core programs in gitolite 1.在gitolite中启用本地非核心程序

Edit the gitolite configuration file (usually ~git/.gitolite.rc ) and uncomment the following line: 编辑gitolite配置文件(通常是~git/.gitolite.rc )并取消注释以下行:

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

Ensure to read the security warnings. 确保阅读安全警告。

2. Enable repository specific hooks 2.启用特定于存储库的挂钩

Uncommenting the repo-specific-hooks line in the gitolite configuration file. 取消注释gitolite配置文件中的repo-specific-hooks行。

3. Add the email hook 3.添加电子邮件挂钩

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 . 将对应的post-receive hook可执行文件(我使用git-multimail )放在你的gitolite-admin存储库中作为文件/local/hooks/repo-specific/git-multimail

Commit and push it. 提交并推动它。

4. Configure settings for multimail hook 4.配置多邮件挂钩的设置

To allow adding config keys via the gitolite config file edit the gitolite config file ~git/.gitolite.rc and update the following line: 要允许通过gitolite配置文件添加配置密钥,请编辑gitolite配置文件~git/.gitolite.rc并更新以下行:

GIT_CONFIG_KEYS => ".*"

Ensure to read the security warning. 确保阅读安全警告。 You may want to narrow it down to GIT_CONFIG_KEYS => "multimailhook\\..*" . 您可能希望将其缩小到GIT_CONFIG_KEYS => "multimailhook\\..*"

5. Configure the multimail email hook 5.配置多邮件电子邮件挂钩

This is an example configuration of the gitolite.conf file in the gitolite-admin repository: 这是gitolite-admin存储库中gitolite.conf文件的示例配置:

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. 我决定使用repo特定的钩子并将它们存储在gitolite-admin存储库中。 Alternatively, you could use global hooks ( /local/hooks/common ) or store them somewhere else on the gitolite server and point LOCAL_CODE there. 或者,您可以使用全局挂钩( /local/hooks/common )或将它们存储在gitolite服务器上的其他位置,并在那里指向LOCAL_CODE

Here is a quick one liner to add descriptions to your gitolite.conf with the same name as the repo. 这是一个快速的单行程序,用于为您的gitolite.conf添加与repo同名的描述。 You need this if you are using this big @almostall approach and gitolite so that you have descriptions for each repo. 如果你正在使用这个大的@almostall方法和gitolite,你需要这个,以便你有每个回购的描述。 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! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM