git-commit hook: support multiline regex matching
I have a commit message similar to this
[foo] adds hello world text
This commit add hello world text to the foo module
Puppet-Syntax: Good
I want to validate the commit messages
- begins with
[$MODULE] $WORD
- contains the string
Puppet-Syntax: Good
I generated the following regex to match the above two conditions
^\[\S+\]\ \w+.*Puppet-Syntax: Good
Unfortunately this does not work because the data_valid()
function in ./app/modules/git_hook.rb
because is used Regexp.new(regex)
which by default does not do multiline matching.
The problem can be illustrated with this simple example
irb(main):001:0> "foo\nbar" =~ Regexp.new('foo.*bar')
=> nil
irb(main):002:0> "foo\nbar" =~ Regexp.new('foo.*bar', Regexp::MULTILINE)
=> 0