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
何が間違っている可能性がありますか?