Class: Overcommit::HookContext::CommitMsg
- Defined in:
- lib/overcommit/hook_context/commit_msg.rb
Overview
Contains helpers related to contextual information used by commit-msg hooks.
Instance Method Summary collapse
- #comment_character ⇒ Object
-
#commit_message ⇒ Object
User commit message stripped of comments and diff (from verbose output).
- #commit_message_file ⇒ Object
- #commit_message_lines ⇒ Object
- #empty_message? ⇒ Boolean
- #post_fail_message ⇒ Object
-
#update_commit_message(message) ⇒ Object
Updates the commit message to the specified text.
Methods included from Helpers::FileModifications
#amendment?, #modified_files, #modified_lines_in_file
Methods included from Helpers::StashUnstagedChanges
#cleanup_environment, #initial_commit?, #setup_environment
Methods inherited from Base
#all_files, #cleanup_environment, #execute_hook, #hook_class_name, #hook_script_name, #hook_type_name, #initialize, #input_lines, #input_string, #modified_files, #setup_environment
Constructor Details
This class inherits a constructor from Overcommit::HookContext::Base
Instance Method Details
#comment_character ⇒ Object
35 36 37 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 35 def comment_character @comment_character ||= Overcommit::GitConfig.comment_character end |
#commit_message ⇒ Object
User commit message stripped of comments and diff (from verbose output).
18 19 20 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 18 def .join end |
#commit_message_file ⇒ Object
39 40 41 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 39 def @args[0] end |
#commit_message_lines ⇒ Object
29 30 31 32 33 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 29 def . take_while { |line| !line.start_with?('diff --git') }. reject { |line| line.start_with?(comment_character) } end |
#empty_message? ⇒ Boolean
13 14 15 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 13 def .strip.empty? end |
#post_fail_message ⇒ Object
43 44 45 46 47 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 43 def "Failed commit message:\n#{.join.chomp}\n\n" \ "Try again with your existing commit message by running:\n" \ "git commit --edit --file=#{}" end |
#update_commit_message(message) ⇒ Object
Updates the commit message to the specified text.
23 24 25 26 27 |
# File 'lib/overcommit/hook_context/commit_msg.rb', line 23 def () ::File.open(, 'w') do |file| file.write() end end |