Skip to content

Commit

Permalink
Don't count newline against commit subject length
Browse files Browse the repository at this point in the history
When comparing the commit subject against the specified limit, trailing
newlines should not be considered part of a subject's character count.
  • Loading branch information
jdewyea authored and sds committed Dec 23, 2015
1 parent c7223dc commit 44fc645
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/overcommit/hook/commit_msg/text_width.rb
Expand Up @@ -7,7 +7,7 @@ def run

@errors = []

find_errors_in_subject(commit_message_lines.first)
find_errors_in_subject(commit_message_lines.first.chomp)
find_errors_in_body(commit_message_lines)

return :warn, @errors.join("\n") if @errors.any?
Expand Down
12 changes: 11 additions & 1 deletion spec/overcommit/hook/commit_msg/text_width_spec.rb
Expand Up @@ -6,7 +6,7 @@
subject { described_class.new(config, context) }

before do
context.stub(:commit_message_lines).and_return(commit_msg.split("\n"))
context.stub(:commit_message_lines).and_return(commit_msg.lines)
context.stub(:empty_message?).and_return(commit_msg.empty?)
end

Expand All @@ -28,6 +28,16 @@
it { should pass }
end

context 'when the subject is 60 characters followed by a newline' do
let(:commit_msg) { <<-MSG }
This is 60 characters, or 61 if the newline is counted
A reasonable line.
MSG

it { should pass }
end

context 'when a line in the message is 72 characters followed by a newline' do
let(:commit_msg) { <<-MSG }
Some summary
Expand Down

0 comments on commit 44fc645

Please sign in to comment.