Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/overcommit/hook_context/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def input_lines
@input_lines ||= input_string.split("\n")
end

# Returns a message to display on failure.
#
# @return [String]
def post_fail_message
nil
end

private

def filter_modified_files(modified_files)
Expand Down
4 changes: 4 additions & 0 deletions lib/overcommit/hook_context/commit_msg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def commit_message_file
@args[0]
end

def post_fail_message
"Failed commit message:\n" + commit_message_lines.join
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define a default post_fail_message method in the base HookContext class so we don't need to do the @context.respond_to?(:post_fail_message) below. We can have a contract where returning nil results in nothing being printed.


private

def raw_commit_message_lines
Expand Down
9 changes: 8 additions & 1 deletion lib/overcommit/hook_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ def run_hooks

print_results

!(@failed || @interrupted)
hook_failed = @failed || @interrupted

if hook_failed
message = @context.post_fail_message
@printer.after(message) unless message.nil?
end

!hook_failed
else
@printer.nothing_to_run
true # Run was successful
Expand Down
6 changes: 6 additions & 0 deletions lib/overcommit/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def run_succeeded
end
end

def after(message)
log.newline
log.log message
log.newline
end

private

def print_header(hook)
Expand Down
6 changes: 6 additions & 0 deletions spec/overcommit/hook_context/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@

it { should == ['line 1', 'line 2'] }
end

describe '#post_fail_message' do
subject { context.post_fail_message }

it { should be_nil }
end
end
8 changes: 8 additions & 0 deletions spec/overcommit/hook_context/commit_msg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@
it { should == false }
end
end

describe '#post_fail_message' do
subject { context.post_fail_message }

it 'returns printable log of commit message' do
subject.should == "Failed commit message:\nSome commit message\n"
end
end
end