gpt4 book ai didi

Mercurial pre commit hook - 根据文件内容停止提交?

转载 作者:行者123 更新时间:2023-12-03 14:39:37 25 4
gpt4 key购买 nike

如何设置预提交 Hook ,它将在提交的文件中搜索字符串,如果找到则停止提交?

最佳答案

Chapter 10the mercurial book准确地涵盖了这一点:

$ 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'

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]$' 更改到您正在寻找的任何字符串。

关于Mercurial pre commit hook - 根据文件内容停止提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4162384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com