class Overcommit::HookContext::CommitMsg

Contains helpers related to contextual information used by commit-msg hooks.

Public Instance Methods

comment_character() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 35
def comment_character
  @comment_character ||= Overcommit::GitConfig.comment_character
end
commit_message() click to toggle source

User commit message stripped of comments and diff (from verbose output).

# File lib/overcommit/hook_context/commit_msg.rb, line 18
def commit_message
  commit_message_lines.join
end
commit_message_file() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 39
def commit_message_file
  @args[0]
end
commit_message_lines() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 29
def commit_message_lines
  raw_commit_message_lines.
    take_while { |line| !line.start_with?('diff --git') }.
    reject     { |line| line.start_with?(comment_character) }
end
empty_message?() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 13
def empty_message?
  commit_message.strip.empty?
end
post_fail_message() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 43
def post_fail_message
  "Failed commit message:\n#{commit_message_lines.join.chomp}\n\n" \
  "Try again with your existing commit message by running:\n" \
  "git commit --edit --file=#{commit_message_file}"
end
update_commit_message(message) click to toggle source

Updates the commit message to the specified text.

# File lib/overcommit/hook_context/commit_msg.rb, line 23
def update_commit_message(message)
  ::File.open(commit_message_file, 'w') do |file|
    file.write(message)
  end
end

Private Instance Methods

raw_commit_message_lines() click to toggle source
# File lib/overcommit/hook_context/commit_msg.rb, line 51
def raw_commit_message_lines
  ::IO.readlines(commit_message_file)
end