class Overcommit::HookContext::PostCommit

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

Public Instance Methods

initial_commit?() click to toggle source

Returns whether the commit that triggered this hook is the first commit on the branch.

@return [true,false]

# File lib/overcommit/hook_context/post_commit.rb, line 28
def initial_commit?
  return @initial_commit unless @initial_commit.nil?
  @initial_commit = !Overcommit::Utils.execute(%w[git rev-parse HEAD~]).success?
end
modified_files() click to toggle source

Get a list of files that were added, copied, or modified in the last commit. Renames and deletions are ignored, since there should be nothing to check.

# File lib/overcommit/hook_context/post_commit.rb, line 10
def modified_files
  subcmd = 'show --format=%n'
  @modified_files ||= Overcommit::GitRepo.modified_files(subcmd: subcmd)
end
modified_lines_in_file(file) click to toggle source

Returns the set of line numbers corresponding to the lines that were changed in a specified file.

# File lib/overcommit/hook_context/post_commit.rb, line 17
def modified_lines_in_file(file)
  subcmd = 'show --format=%n'
  @modified_lines ||= {}
  @modified_lines[file] ||=
    Overcommit::GitRepo.extract_modified_lines(file, subcmd: subcmd)
end