Class: Overcommit::HookContext::PostMerge

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

Overview

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

Instance Attribute Summary collapse

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 Attribute Details

#argsObject

Returns the value of attribute args


5
6
7
# File 'lib/overcommit/hook_context/post_merge.rb', line 5

def args
  @args
end

Instance Method Details

#merge_commit?Boolean

Returns whether this merge was made without –squash


31
32
33
# File 'lib/overcommit/hook_context/post_merge.rb', line 31

def merge_commit?
  !squash?
end

#modified_filesObject

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


9
10
11
12
13
# File 'lib/overcommit/hook_context/post_merge.rb', line 9

def modified_files
  staged = squash?
  refs = 'HEAD^ HEAD' if merge_commit?
  @modified_files ||= Overcommit::GitRepo.modified_files(staged: staged, refs: refs)
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
23
# File 'lib/overcommit/hook_context/post_merge.rb', line 17

def modified_lines_in_file(file)
  staged = squash?
  refs = 'HEAD^ HEAD' if merge_commit?
  @modified_lines ||= {}
  @modified_lines[file] ||=
    Overcommit::GitRepo.extract_modified_lines(file, staged: staged, refs: refs)
end

#squash?Boolean

Returns whether this merge was made using –squash


26
27
28
# File 'lib/overcommit/hook_context/post_merge.rb', line 26

def squash?
  @args[0].to_i == 1
end