Skip to content

Commit e1fea15

Browse files
ncrisds
authored andcommittedMar 30, 2019
CommitMsg MessageFormat: multiline match
Add m flag to regexp check to allow matching over multiple lines.
1 parent 764d9a1 commit e1fea15

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎lib/overcommit/hook/commit_msg/message_format.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def validate_pattern(message)
1919
expected_pattern_message = config['expected_pattern_message']
2020
sample_message = config['sample_message']
2121

22-
unless message =~ /#{pattern}/
22+
unless message =~ /#{pattern}/m
2323
[
2424
'Commit message pattern mismatch.',
2525
"Expected : #{expected_pattern_message}",

‎spec/overcommit/hook/commit_msg/message_format_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@
3939

4040
it { should fail_hook expected_message }
4141
end
42+
43+
context 'when multiline message matches the pattern' do
44+
let(:config) do
45+
super().merge(Overcommit::Configuration.new(
46+
'CommitMsg' => {
47+
'MessageFormat' => {
48+
'pattern' => '^Some .* Message$'
49+
}
50+
}
51+
))
52+
end
53+
54+
let(:commit_msg) { "Some \n multiline \n Message" }
55+
56+
it { should pass }
57+
end
4258
end

0 commit comments

Comments
 (0)
Please sign in to comment.