diff --git a/lib/overcommit/hook_context/base.rb b/lib/overcommit/hook_context/base.rb index ecdd349f..9d01ff2f 100644 --- a/lib/overcommit/hook_context/base.rb +++ b/lib/overcommit/hook_context/base.rb @@ -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) diff --git a/lib/overcommit/hook_context/commit_msg.rb b/lib/overcommit/hook_context/commit_msg.rb index c161131d..ed97bbdc 100644 --- a/lib/overcommit/hook_context/commit_msg.rb +++ b/lib/overcommit/hook_context/commit_msg.rb @@ -31,6 +31,10 @@ def commit_message_file @args[0] end + def post_fail_message + "Failed commit message:\n" + commit_message_lines.join + end + private def raw_commit_message_lines diff --git a/lib/overcommit/hook_runner.rb b/lib/overcommit/hook_runner.rb index 11b7d2d0..ed757082 100644 --- a/lib/overcommit/hook_runner.rb +++ b/lib/overcommit/hook_runner.rb @@ -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 diff --git a/lib/overcommit/printer.rb b/lib/overcommit/printer.rb index 58c5550a..cd4593c4 100644 --- a/lib/overcommit/printer.rb +++ b/lib/overcommit/printer.rb @@ -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) diff --git a/spec/overcommit/hook_context/base_spec.rb b/spec/overcommit/hook_context/base_spec.rb index 97695f90..d5028379 100644 --- a/spec/overcommit/hook_context/base_spec.rb +++ b/spec/overcommit/hook_context/base_spec.rb @@ -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 diff --git a/spec/overcommit/hook_context/commit_msg_spec.rb b/spec/overcommit/hook_context/commit_msg_spec.rb index 53b8312d..ac11aa90 100644 --- a/spec/overcommit/hook_context/commit_msg_spec.rb +++ b/spec/overcommit/hook_context/commit_msg_spec.rb @@ -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