Git钩子检测包含特定字符串的文件更改 [英] Git hook to detect file changes that contain a certain string
问题描述
我想警告用户他们的代码是否包含特定的字符串,并通过电子邮件提醒他人。
现在我使用post-receive hook,因为检测需要在服务器端完成。
我正在更新服务器端存储库并运行类似于 git diff-tree -r - -name-only --no-commit-id $ 2 | xargs grep foo
检测到坏字符串foo。
这种方法存在问题:
git show $ 2 | grep ^ + ...
有没有更好的方法来做到这一点?
$如果您使用的是gitolite V3(或'g3'),请尝试改为将您的支票放在
对于适用于此用户的规则中的每个以VREF /
FOO
/开头的refex,调用名为FOO
被触发(存储在$ LOCAL_CODE / VREF code>
)。
请注意,如果VREF规则不适用于该用户,则甚至不会调用该程序。
您可以准确地控制要应用此警告的哪个(一组)用户。
如果您的条件(无错误字符串)不符合。然而,仍然需要更新工作目录。
首先(因为Gitolite默认只管理裸露的回购)
I want to warn a user if their code includes a certain string and alert people via email.
Right now I'm using a post-receive hook because the detection needs to be done on the server side.
I am updating a server-side repository and running something like git diff-tree -r --name-only --no-commit-id $2 | xargs grep foo
to detect bad string "foo."
Problems with this approach:
- I don't like maintaining and entire working version of the repository server-side
- It scans the entire file, not just the changes. edit I solved this problem replacing the above with:
git show $2 | grep ^+ ...
Is there a better way to do this?
If you are using gitolite V3 (or 'g3'), try instead to put your check in a VREF.
For every refex starting with VREF/
FOO
/ in a rule that applies to this user, a call to a program calledFOO
is triggered (stored in$LOCAL_CODE/VREF
).
Note that the program isn't even called if the VREF rule doesn't apply to that user.
You can control exactly to which (group of) users you want to apply this warning.
You can reject the push if your condition (no bad string) isn't met.
however, that still requires updating a working directory first (since Gitolite only manages bare repo by default)
这篇关于Git钩子检测包含特定字符串的文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!