class Overcommit::HookContext::PostRewrite

Contains helpers for contextual information used by post-rewrite hooks.

Constants

RewrittenCommit

Struct encapsulating the old and new SHA1 hashes of a rewritten commit

Public Instance Methods

amend?() click to toggle source

Returns whether this post-rewrite was triggered by ‘git commit –amend`.

@return [true,false]

# File lib/overcommit/hook_context/post_rewrite.rb, line 9
def amend?
  @args[0] == 'amend'
end
modified_files() click to toggle source

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.

# 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?() click to toggle source

Returns whether this post-rewrite was triggered by ‘git rebase`.

@return [true,false]

# File lib/overcommit/hook_context/post_rewrite.rb, line 16
def rebase?
  @args[0] == 'rebase'
end
rewritten_commits() click to toggle source

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

@return [Array<RewrittenCommit>]

# 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