git hook以获得合法提交消息(#123好消息) [英] git hook for legit commit message (#123 good message)
问题描述
我需要确保提交消息是其他合法拒绝的消息。提交消息应该像#123修复丢失的括号
I need to make sure commit messages are some what legit else reject it. The commit message should be like "#123 fixing missing bracket"
我要确保它以哈希开头,有一个整数(无123a),并且该消息至少有10个字。
I want to make sure it begins with hash, there is an integer (no 123a), and the message is at least 10 words.
很高兴:消息不会连续完全相同
Nice to have: the message would not be the exact same in a row
我正在使用此Trac插件进行更改集,它更详细地描述了提交消息格式 http://trac-hacks.org/ wiki / TracTicketChangelogPlugin
I am using this Trac plugin for change set, it describes the commit message format in more detail http://trac-hacks.org/wiki/TracTicketChangelogPlugin
谢谢
推荐答案
I使用以下命令创建了一个commit-msg钩子:
I created a commit-msg hook with:
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
#starts with # then number, space, and at least 5 words no more than 200
$regex = /(^#[0-9]+ \W*(\w+(\W+|$)){5,200})/
if !$regex.match(message)
puts "Your message is not formatted correctly (example: #XXX at least 5 words)"
exit 1
end
我从此博客帖子中借来的
http://fhopf.blogspot.com/2011/01/git-hook-for-redmine -messages.html
I borrowed from this blog post http://fhopf.blogspot.com/2011/01/git-hook-for-redmine-messages.html
这篇关于git hook以获得合法提交消息(#123好消息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!