Class: Overcommit::Hook::PrepareCommitMsg::Base

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/overcommit/hook/prepare_commit_msg/base.rb

Overview

Functionality common to all prepare-commit-msg hooks.

Direct Known Subclasses

ReplaceBranch

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#modify_commit_messageObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/overcommit/hook/prepare_commit_msg/base.rb', line 13

def modify_commit_message
  raise 'This expects a block!' unless block_given?

  # NOTE: this assumes all the hooks of the same type share the context's
  # memory. If that's not the case, this won't work.
  lock.synchronize do
    contents = File.read(commit_message_filename)
    File.open(commit_message_filename, 'w') do |f|
      f << (yield contents)
    end
  end
end