Git钩子检测包含特定字符串的文件更改 [英] Git hook to detect file changes that contain a certain string

查看:369
本文介绍了Git钩子检测包含特定字符串的文件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想警告用户他们的代码是否包含特定的字符串,并通过电子邮件提醒他人。



现在我使用post-receive hook,因为检测需要在服务器端完成。



我正在更新服务器端存储库并运行类似于 git diff-tree -r - -name-only --no-commit-id $ 2 | xargs grep foo 检测到坏字符串foo。



这种方法存在问题:


  • 我不喜欢维护和存储库服务器端的整个工作版本

  • 它扫描整个文件,而不仅仅是更改。 编辑我解决了这个问题: git show $ 2 | grep ^ + ...



有没有更好的方法来做到这一点?

$如果您使用的是gitolite V3(或'g3'),请尝试改为将您的支票放在

sitaramc.github.com/gitolite/vref.htmlrel =nofollow> VREF


对于适用于此用户的规则中的每个以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 called FOO 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆