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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5055190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:08:34  来源:igfitidea点击:

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

gitgitolitepost-receive-email

提问by Alexander Gladysh

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

我正在使用post-receive-emailGit 发行版中的钩子在更新 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. I picked Gitolite.

我所有的存储库都是手动管理的。现在,我得到了如此多的存储库以及如此多的用户和组,我不得不升级到某些 Git 存储库管理系统。我选择了 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-emailhook depends on three parameters in *.git/config: hooks.envelopesender, hooks.emailprefixand hooks.mailinglist.

标准post-receive-email挂钩取决于三个参数*.git/confighooks.envelopesenderhooks.emailprefixhooks.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.

一般来说,对于我在 Gitolite 下移动的每个存储库,这些参数都是不同的。实际上,对于相同的权限组,它们是相同的——用户,可以访问存储库,接收通知,其他人——不是。

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

我想避免config手动编辑每个存储库的文件。如果我可以在同一个集中的地方为整个 Gitolite 配置所有内容,那将会更有趣。

So, any hints?

那么,有什么提示吗?

回答by VonC

You can look at the doc hookfor starters:

您可以查看初学者的doc hook

where do I (the admin) put the hooks?

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

我(管理员)把钩子放在哪里?

通常,所有钩子都进入hooks/common目录。只有用于admin回购的特殊更新后挂钩进入hooks/gitolite-admin.

But the GitoliteV3doc 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.confis quite clear:

文档gitolite.conf是很清楚的:

repo specific git config commands

Sometimes you want to specify git configsettings 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 configvalues by specifying something like this within a "repo" paragraph:

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

回购特定的 git 配置命令

有时您想git config为某些存储库指定设置。
例如,您可能有一个自定义的 post-receive 钩子,它会在推送发生时发送电子邮件,并且该钩子需要知道将电子邮件发送给谁等。

您可以git config通过在“repo”段落中指定类似的内容来设置值:

用法示例:如果您在hooks/common其中放置了一个需要特定于每个存储库的配置信息的钩子,您可以这样做:

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 rcfile has the right settings; please see comments around the variable $GL_GITCONFIG_KEYS$GIT_CONFIG_KEYS(now in GitoliteV3 or 'g3') in gitolite rcfilefor details and security information.

这可以执行普通的“ git config section.key value”(对于上面的前 3 个示例)或“ git config --unset-all section.key”(对于最后一个示例)。不支持
其他形式(--add、 thevalue_regex等)。

注意:除非rc文件具有正确的设置,否则这将不起作用;请查看变量周围的注释$GL_GITCONFIG_KEYS$GIT_CONFIG_KEYS(现在在GitoliteV3 或 'g3')在gitoliterc文件中以获取详细信息和安全信息。

回答by Sitaram

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 的疏忽感到抱歉

回答by Sitaram

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:

这是一个快速的单行代码,用于向您的 gitolite.conf 中添加与 repo 同名的描述。如果您正在使用这种大的 @almostall 方法和 gitolite,那么您需要这个,以便您对每个 repo 进行描述。这为我节省了一个小时的打字时间,因此必须分享:

Try first:

先试试:

sed 's/^\(repo *\)\(.*\)/\n\t\t = ""/' 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 *\)\(.*\)/\n\t\t = ""/' gitolite.conf

Cheers!

干杯!

回答by romor

The gitolite cookbooktells how to configure hooks:

gitolite菜谱介绍如何配置挂钩:

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"

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

Ensure to read the security warnings.

确保阅读安全警告。

2. Enable repository specific hooks

2. 启用存储库特定挂钩

Uncommenting the repo-specific-hooksline in the gitolite configuration file.

取消注释repo-specific-hooksgitolite 配置文件中的行。

3. Add the email hook

3. 添加邮件钩子

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

把correspondig后收到钩可执行文件(我用的git-的MultiMail在您)gitolite管理员库作为文件/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.rcand update the following line:

要允许通过 gitolite 配置文件添加配置键,请编辑 gitolite 配置文件~git/.gitolite.rc并更新以下行:

GIT_CONFIG_KEYS => ".*"

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.conffile in the gitolite-adminrepository:

这是gitolite-admin存储库中gitolite.conf文件的示例配置:

repo @all
    config multimailhook.environment      = gitolite
    config multimailhook.from             = [email protected]
    config multimailhook.mailinglist      = [email protected]

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_CODEthere.

我决定使用 repo 特定的钩子并将它们存储在 gitolite-admin 存储库中。或者,您可以使用全局钩子 ( /local/hooks/common) 或将它们存储在 gitolite 服务器上的其他位置并指向LOCAL_CODE那里。