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.



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

def args
  @args
end

Instance Method Details

#merge_commit?Boolean

Returns whether this merge was made without –squash

Returns:

  • (Boolean)


33
34
35
# File 'lib/overcommit/hook_context/post_merge.rb', line 33

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.



11
12
13
14
15
# File 'lib/overcommit/hook_context/post_merge.rb', line 11

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.



19
20
21
22
23
24
25
# File 'lib/overcommit/hook_context/post_merge.rb', line 19

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/overcommit/hook_context/post_merge.rb', line 28

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