I have following Git hook in Ruby, which uses a regular expression to check for a Jira ticket like IPS-56981
in the commit message. If not found, then the commit is aborted.
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /\A\IPS-(\d+)\s\w+/
if !$regex.match(message)
puts "[POLICY] Your message is not formatted correctly. You need to specify a Jira ticket."
exit 1
end
In some cases, I want to ignore the check and commit anyway. How can I realize that in Ruby?
My ideas were to pass an additional argument to Git commit and to check in the Ruby script for that or directly to wait in the Ruby script for ignore
message to ignore the Jira ticket check. But my tries are failed. Maybe I need to use another Git hook?
I tried:
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /\A\IPS-(\d+)\s\w+/
if !$regex.match(message)
puts "[POLICY] Your message is not formatted correctly. You need to specify a Jira ticket."
ignore=$stdin.gets.chomp
if ignore == "ignore"
exit 0
end
exit 1
end
but I get the error message:
.git/hooks/commit-msg:9:in `<main>': undefined method `chomp' for nil:NilClass (NoMethodError)
It also does not wait to give me the chance to enter ignore
.