我想使用 git 挂钩强制提交消息符合特定格式(它们应该以#number 结尾)。我试过安装这个钩子,也在这里引用,但我不断收到消息:
$ git commit -am "Test"
.git/hooks/commit-msg: line 1: sage_file: command not found
.git/hooks/commit-msg: line 2: syntax error near unexpected token `('
.git/hooks/commit-msg: line 2: `message = File.read(message_file)'
我使用的脚本与示例中的脚本完全相同,并且都给出了相同的错误。例如,我尝试过:
#!/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
有什么问题?