Class: Overcommit::HookContext::PostCommit

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook_context/post_commit.rb

Overview

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

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

#initial_commit?true, false

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

Returns:

  • (true, false)


28
29
30
31
# 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_filesObject

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.



10
11
12
13
# 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) ⇒ Object

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



17
18
19
20
21
22
# 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