mik*_*iku 11
有一个pre-commit-msg或commit-msg钩子,你可以使用:
Git repos带有样品钩,例如捕获commit-msg下的样品钩git/hooks/commit-msg.sample重复签名.
# This example catches duplicate Signed-off-by lines.
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 Duplicate Signed-off-by lines.
exit 1
}
Run Code Online (Sandbox Code Playgroud)
要启用挂钩,请不要忘记使其可执行.
这是一些虚构的例子,它只接受提交消息london|120|something ...等:
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
# $regex = /\[ref: (\d+)\]/
PAIRS = ["london", "paris", "moscow"] # only these names allowed
STORIES = "\d{2,4}" # story must be a 2, 3 or 4 digit number
MESSAGE = ".{5,}" # message must be at least 5 chars long
$regex = "( (#{PAIRS.join('|')})\|#{STORIES}\|#{MESSAGE} )"
if !$regex.match(message)
puts "[POLICY] Your message is not formatted correctly"
exit 1
end
Run Code Online (Sandbox Code Playgroud)
用法:
$ git ci -m "berlin|120"
[POLICY] Your message is not formatted correctly
$ git ci -m "london|120|XX"
[POLICY] Your message is not formatted correctly
$ git ci -m "london|120|Looks good."
[master 853e622] london|120|Looks good.
1 file changed, 1 insertion(+)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6065 次 |
| 最近记录: |