Class: Overcommit::HookContext::PostRewrite

Inherits:
Base
  • Object
show all
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

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`.


7
8
9
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 7

def amend?
  @args[0] == 'amend'
end

#modified_filesObject

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.


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 31

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`.


14
15
16
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 14

def rebase?
  @args[0] == 'rebase'
end

#rewritten_commitsArray<RewrittenCommit>

Returns the list of commits rewritten by the action that triggered this hook run.


22
23
24
25
26
# File 'lib/overcommit/hook_context/post_rewrite.rb', line 22

def rewritten_commits
  @rewritten_commits ||= input_lines.map do |line|
    RewrittenCommit.new(*line.split(' '))
  end
end