当提交包含某些关键字时如何将 git 存储库配置为 warn/reject
How to configure git repository to warn/reject when commits contain certain keywords
假设有人在做我的一个项目,他有时非常愚蠢,在推送给 master 时留下 byebug 调用(可能是也可能不是我)
有什么方法可以将 gitlab 存储库配置为 warn/reject 包含某些关键字的推送?我已经看到拒绝强制推送的配置选项,是否有关键字过滤器配置选项,或者可以用来执行此操作的东西?
您需要添加钩子才能做到这一点。
您的钩子应该验证代码和 ACCEPT/REJECT 根据结果提交。
你应该使用 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
您可以创建服务器端hook
要在 Gitlab 中这样做,您需要一些 tweaks。
您必须在
中放置一个脚本
/home/git/repositories/<group>/<project>.git
创建 custom_hooks 目录
然后将你的钩子放在一个名为 "pre-receive" 的文件中,并赋予它执行权限
记住,这样做,你必须是 Gitlab 管理员 - 或者他的朋友。
显示了一个用于开始的钩子示例 here。
为了做你想做的事,我认为这个脚本(经过一些修复,它只是一个骨架)可能会起作用。
#!/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)
假设有人在做我的一个项目,他有时非常愚蠢,在推送给 master 时留下 byebug 调用(可能是也可能不是我)
有什么方法可以将 gitlab 存储库配置为 warn/reject 包含某些关键字的推送?我已经看到拒绝强制推送的配置选项,是否有关键字过滤器配置选项,或者可以用来执行此操作的东西?
您需要添加钩子才能做到这一点。 您的钩子应该验证代码和 ACCEPT/REJECT 根据结果提交。
你应该使用 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
您可以创建服务器端hook
要在 Gitlab 中这样做,您需要一些 tweaks。 您必须在
中放置一个脚本/home/git/repositories/<group>/<project>.git
创建 custom_hooks 目录 然后将你的钩子放在一个名为 "pre-receive" 的文件中,并赋予它执行权限
记住,这样做,你必须是 Gitlab 管理员 - 或者他的朋友。
显示了一个用于开始的钩子示例 here。 为了做你想做的事,我认为这个脚本(经过一些修复,它只是一个骨架)可能会起作用。
#!/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)