-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathbase.rb
More file actions
26 lines (21 loc) · 760 Bytes
/
base.rb
File metadata and controls
26 lines (21 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true
require 'forwardable'
module Overcommit::Hook::PrepareCommitMsg
# Functionality common to all prepare-commit-msg hooks.
class Base < Overcommit::Hook::Base
extend Forwardable
def_delegators :@context,
:commit_message_filename, :commit_message_source, :commit, :lock
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
end
end