From b4a55f7767ae794b1352cc54ca3fe608eaf4f4ff Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sun, 3 May 2015 04:13:43 -0400 Subject: [PATCH 1/2] Add EmptyMessage commit-msg hook This hook will fail if the commit message is empty or contains only whitespace. --- config/default.yml | 4 +++ .../hook/commit_msg/empty_message.rb | 10 +++++++ .../hook/commit_msg/empty_message_spec.rb | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/overcommit/hook/commit_msg/empty_message.rb create mode 100644 spec/overcommit/hook/commit_msg/empty_message_spec.rb diff --git a/config/default.yml b/config/default.yml index 2dd4911e..6d6a06a7 100644 --- a/config/default.yml +++ b/config/default.yml @@ -26,6 +26,10 @@ CommitMsg: enabled: true description: 'Checking subject capitalization' + EmptyMessage: + enabled: true + description: 'Checking for empty commit message' + GerritChangeId: enabled: false description: 'Ensuring Gerrit Change-Id is present' diff --git a/lib/overcommit/hook/commit_msg/empty_message.rb b/lib/overcommit/hook/commit_msg/empty_message.rb new file mode 100644 index 00000000..b0cd0310 --- /dev/null +++ b/lib/overcommit/hook/commit_msg/empty_message.rb @@ -0,0 +1,10 @@ +module Overcommit::Hook::CommitMsg + # Checks that the commit message is not empty + class EmptyMessage < Base + def run + return :pass unless empty_message? + + [:fail, 'Commit message should not be empty'] + end + end +end diff --git a/spec/overcommit/hook/commit_msg/empty_message_spec.rb b/spec/overcommit/hook/commit_msg/empty_message_spec.rb new file mode 100644 index 00000000..b7a6d79a --- /dev/null +++ b/spec/overcommit/hook/commit_msg/empty_message_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Overcommit::Hook::CommitMsg::EmptyMessage do + let(:config) { Overcommit::ConfigurationLoader.default_configuration } + let(:context) { double('context') } + subject { described_class.new(config, context) } + + before do + subject.stub(:empty_message?).and_return(commit_msg.strip.empty?) + end + + context 'when commit message is empty' do + let(:commit_msg) { '' } + + it { should fail_hook } + end + + context 'when commit message contains only whitespace' do + let(:commit_msg) { ' ' } + + it { should fail_hook } + end + + context 'when commit message is not empty' do + let(:commit_msg) { 'Some commit message' } + + it { should pass } + end +end From ba3df1c978d2a92fd4343450231a591a814a960d Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sun, 3 May 2015 13:44:45 -0400 Subject: [PATCH 2/2] Make EmptyMessage commit-msg hook quiet by default --- config/default.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/default.yml b/config/default.yml index 6d6a06a7..d6a57994 100644 --- a/config/default.yml +++ b/config/default.yml @@ -29,6 +29,7 @@ CommitMsg: EmptyMessage: enabled: true description: 'Checking for empty commit message' + quiet: true GerritChangeId: enabled: false