Class: Overcommit::HookContext::PostRewrite
- Defined in:
- lib/overcommit/hook_context/post_rewrite.rb
Overview
Contains helpers for contextual information used by post-rewrite hooks.
Defined Under Namespace
Classes: RewrittenCommit
Instance Method Summary collapse
-
#amend? ⇒ true, false
Returns whether this post-rewrite was triggered by ‘git commit –amend`.
-
#modified_files ⇒ Object
Get a list of files that have been added or modified as part of a rewritten commit.
-
#rebase? ⇒ true, false
Returns whether this post-rewrite was triggered by ‘git rebase`.
-
#rewritten_commits ⇒ Array<RewrittenCommit>
Returns the list of commits rewritten by the action that triggered this hook run.
Methods inherited from Base
#all_files, #cleanup_environment, #execute_hook, #hook_class_name, #hook_script_name, #hook_type_name, #initialize, #input_lines, #input_string, #post_fail_message, #setup_environment
Constructor Details
This class inherits a constructor from Overcommit::HookContext::Base
Instance Method Details
#amend? ⇒ true, false
Returns whether this post-rewrite was triggered by ‘git commit –amend`.
9 10 11 |
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 9 def amend? @args[0] == 'amend' end |
#modified_files ⇒ Object
Get a list of files that have been added or modified as part of a rewritten commit. Renames and deletions are ignored, since there should be nothing to check.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 33 def modified_files @modified_files ||= begin @modified_files = [] rewritten_commits.each do |rewritten_commit| refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}" @modified_files |= Overcommit::GitRepo.modified_files(refs: refs) end filter_modified_files(@modified_files) end end |
#rebase? ⇒ true, false
Returns whether this post-rewrite was triggered by ‘git rebase`.
16 17 18 |
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 16 def rebase? @args[0] == 'rebase' end |
#rewritten_commits ⇒ Array<RewrittenCommit>
Returns the list of commits rewritten by the action that triggered this hook run.
24 25 26 27 28 |
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 24 def rewritten_commits @rewritten_commits ||= input_lines.map do |line| RewrittenCommit.new(*line.split(' ')) end end |