Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't count newline against commit subject length #310

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
23 changes: 22 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,27 @@
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

This line has 72 characters, but with newline it has 73 characters
That shouldn't be a problem.
MSG

it { should pass }
end

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