Mercurial 预提交挂钩 - 根据文件内容停止提交?
如何设置预提交挂钩,它将在提交的文件中搜索字符串,如果找到则停止提交?
How can I setup a pre-commit hook , that will search for a string in the committed files and If found stop the commit ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第 10 章 of mercurial 书 准确地涵盖了这一点:
只需将正则表达式从
'^\+.*[ \t]$'
更改为您要查找的任何字符串即可。Chapter 10 of the mercurial book covers this exactly:
Just change the regular expression from
'^\+.*[ \t]$'
to whatever string you're looking for.Ry4an 的答案几乎是正确的:)
但您需要将“hg导出提示”替换为“hg diff”。
Tip 是最后提交的更改集,但对本地未提交的更改感兴趣 - 所以 diff 是您所需要的。
为了我的需要,我将以下内容添加到我的 hgrc 中,
-S 包括子存储库(可能不需要,并且可能仍然有错误)。
grep -v '^-' 从 diff 中删除指示已删除行的行。
我删除了 -q,所以我至少知道要删除什么,但不幸的是,此方法无法打印发生的文件和行号(因为它是通过管道传输的)。也许有人有更好的方法来做到这一点。
Ry4an's answer is almost correct :)
but you need to replace "hg export tip" with "hg diff".
tip is the last commited changeset, but are interested in local uncommited changes - so diff is what u need.
for my needs i added the following to my hgrc
the -S includes subrepos (maye not need, and may be still buggy).
the grep -v '^-' removes lines from the diff that indicate lines that were removed.
i removed the -q so i at least have a idea what to remove, but unfortunatly this method cannot print you the file and linenumber of the occurence (as it is piped). maybe someone has a better way to do it.
顺便说一句,在 Windows 上您可以使用
如果您的源包含字符串“NOCOMMIT”,此挂钩将失败
BTW, on Windows you can use
This hook will fail if your sources contains string "NOCOMMIT"