如何在提交包含特定关键字

时间:2015-06-30 19:04:03

标签: git gitlab

让我们说有人在我的某个项目上工作,有时候非常愚蠢,并且在推送给主人(可能是也可能不是我)的时候留下了被打扰的电话。

有没有办法配置gitlab存储库来警告/拒绝包含某些关键字的推送?我已经看到了拒绝强制推送的配置选项,是否有关键字过滤器配置选项,或者可以用来执行此操作的内容?

2 个答案:

答案 0 :(得分:2)

你需要添加钩子来做到这一点。 你的钩子应该验证代码并根据结果接受/拒绝提交。

您应该使用pre-commit挂钩
http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/

有关钩子的更多信息:

https://www.atlassian.com/git/tutorials/git-hooks/
http://git-scm.com/docs/githooks

答案 1 :(得分:2)

You can create a server-side hook

To do so in the Gitlab, you need some tweaks. You must place a script in

/home/git/repositories/<group>/<project>.git

create the custom_hooks directory then place your hook in a file with the name "pre-receive" on it, and give it execution permission

Remember, for doing so, you must be the Gitlab admin - or a friend of him.

An example of a hook for starting with is shown here. For doing what you want, I think this script ( with some fixing, it is just a skeleton), may work.

#!/usr/bin/python from commands import getoutput as cmd
import sys
improper_words = ["byebug","bye", for line in sys.stdin:
words = cmd("git log " + line).split(" ")
for improper in improper_words:
    if improper in words:
       sys.exit(1) sys.exit(0)