require "ruby_git_hooks"
class NonAsciiCharactersCheckHook < RubyGitHooks::Hook
Hook = RubyGitHooks::Hook
def initialize(options = {})
end
def check
if !commit_message || commit_message.length == 0
STDERR.puts "Commit message is missing or empty!"
return false
end
count = 0
valid_control_chars = [13, 10, 9]
commit_message.each_byte do |b|
if b > 127 || (b < 32 && !valid_control_chars.include?(b))
count = count + 1
end
end
if count > 0
STDERR.puts "Commit message has #{count} non-ASCII characters"
end
return count == 0 ? true : false
end
end