Skip to content

Commit 44fc645

Browse files
jdewyeasds
authored andcommitted
Don't count newline against commit subject length
When comparing the commit subject against the specified limit, trailing newlines should not be considered part of a subject's character count.
1 parent c7223dc commit 44fc645

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/overcommit/hook/commit_msg/text_width.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def run
77

88
@errors = []
99

10-
find_errors_in_subject(commit_message_lines.first)
10+
find_errors_in_subject(commit_message_lines.first.chomp)
1111
find_errors_in_body(commit_message_lines)
1212

1313
return :warn, @errors.join("\n") if @errors.any?

spec/overcommit/hook/commit_msg/text_width_spec.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
subject { described_class.new(config, context) }
77

88
before do
9-
context.stub(:commit_message_lines).and_return(commit_msg.split("\n"))
9+
context.stub(:commit_message_lines).and_return(commit_msg.lines)
1010
context.stub(:empty_message?).and_return(commit_msg.empty?)
1111
end
1212

@@ -28,6 +28,16 @@
2828
it { should pass }
2929
end
3030

31+
context 'when the subject is 60 characters followed by a newline' do
32+
let(:commit_msg) { <<-MSG }
33+
This is 60 characters, or 61 if the newline is counted
34+
35+
A reasonable line.
36+
MSG
37+
38+
it { should pass }
39+
end
40+
3141
context 'when a line in the message is 72 characters followed by a newline' do
3242
let(:commit_msg) { <<-MSG }
3343
Some summary

0 commit comments

Comments
 (0)