Class: Overcommit::HookContext::PreRebase

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

Overview

Contains helpers related to contextual information used by pre-rebase hooks.

Instance Method Summary collapse

Methods inherited from Base

#cleanup_environment, #execute_hook, #hook_class_name, #hook_script_name, #hook_type_name, #initialize, #input_lines, #input_string, #modified_files, #setup_environment

Constructor Details

This class inherits a constructor from Overcommit::HookContext::Base

Instance Method Details

#detached_head?Boolean

Returns whether we are rebasing a detached HEAD rather than a branch

Returns:

  • (Boolean)


18
19
20
# File 'lib/overcommit/hook_context/pre_rebase.rb', line 18

def detached_head?
  rebased_branch.empty?
end

#fast_forward?Boolean

Returns whether this rebase is a fast-forward

Returns:

  • (Boolean)


23
24
25
# File 'lib/overcommit/hook_context/pre_rebase.rb', line 23

def fast_forward?
  rebased_commits.empty?
end

#rebased_branchObject

Returns the name of the branch being rebased. Empty if rebasing a detached HEAD.



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

def rebased_branch
  @rebased_branch ||=
    @args[1] || `git symbolic-ref --short --quiet HEAD`.chomp
end

#rebased_commitsObject

Returns the SHA1-sums of the series of commits to be rebased in reverse topological order.



29
30
31
32
33
34
# File 'lib/overcommit/hook_context/pre_rebase.rb', line 29

def rebased_commits
  rebased_ref = detached_head? ? 'HEAD' : rebased_branch
  @rebased_commits ||=
    `git rev-list --topo-order --reverse #{upstream_branch}..#{rebased_ref}`.
      split("\n")
end

#upstream_branchObject

Returns the name of the branch we are rebasing onto.



6
7
8
# File 'lib/overcommit/hook_context/pre_rebase.rb', line 6

def upstream_branch
  @args[0]
end