Class: Overcommit::HookContext::PostCheckout

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

Overview

Contains helpers related to contextual information used by post-checkout 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

#branch_checkout?Boolean

Returns whether this checkout was the result of changing/updating a branch.


19
20
21
# File 'lib/overcommit/hook_context/post_checkout.rb', line 19

def branch_checkout?
  @args[2].to_i == 1
end

#file_checkout?Boolean

Returns whether this checkout was for a single file.


24
25
26
# File 'lib/overcommit/hook_context/post_checkout.rb', line 24

def file_checkout?
  !branch_checkout?
end

#modified_filesObject

Get a list of files that have been added or modified between `previous_head` and `new_head`. Renames and deletions are ignored, since there should be nothing to check.


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

def modified_files
  @modified_files ||=
    Overcommit::GitRepo.modified_files(refs: "#{previous_head} #{new_head}")
end

#new_headObject

Returns the ref of the new current HEAD.


13
14
15
# File 'lib/overcommit/hook_context/post_checkout.rb', line 13

def new_head
  @args[1]
end

#previous_headObject

Returns the ref of the HEAD that we transitioned from.


8
9
10
# File 'lib/overcommit/hook_context/post_checkout.rb', line 8

def previous_head
  @args[0]
end