水银预提交钩 [英] Mercurial pre commit hook

查看:40
本文介绍了水银预提交钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置预提交钩子,该钩子将在已提交文件中搜索字符串,如果找到,则停止提交?

How can I setup a pre-commit hook , that will search for a string in the committed files and If found stop the commit ?

推荐答案

汞书的第10章"完全涵盖了这一点:

Chapter 10 of the mercurial book covers this exactly:

$ cat .hg/hgrc
[hooks]
pretxncommit.whitespace = hg export tip | (! egrep -q '^\+.*[ \t]$')
$ echo 'a ' > a
$ hg commit -A -m 'test with trailing whitespace'
adding a
transaction abort!
rollback completed
abort: pretxncommit.whitespace hook exited with status 1
$ echo 'a' > a
$ hg commit -A -m 'drop trailing whitespace and try again'

在此示例中,我们介绍一个简单的 pretxncommit钩子,用于检查 尾随空格.这个钩子是 简短,但不是很有帮助.它退出 如果更改增加,则显示错误状态 尾随空白的行 文件,但不打印任何文件 可能有助于我们的信息 标识有问题的文件或行. 它也有不错的特性 注意未修改的行; 仅介绍新尾随的行 空格会引起问题.

In this example, we introduce a simple pretxncommit hook that checks for trailing whitespace. This hook is short, but not very helpful. It exits with an error status if a change adds a line with trailing whitespace to any file, but does not print any information that might help us to identify the offending file or line. It also has the nice property of not paying attention to unmodified lines; only lines that introduce new trailing whitespace cause problems.

只需将正则表达式从'^\+.*[ \t]$'更改为您要查找的任何字符串即可.

Just change the regular expression from '^\+.*[ \t]$' to whatever string you're looking for.

这篇关于水银预提交钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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