Sha256: 7ae563ae33b5a7773201c8aa5fb57ec124218af55fceda3ceecb1eff930b82ca

Contents?: true

Size: 1.05 KB

Versions: 31

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Overcommit::HookContext
  # Contains helpers related to contextual information used by pre-rebase
  # hooks.
  class PreRebase < Base
    # Returns the name of the branch we are rebasing onto.
    def upstream_branch
      @args[0]
    end

    # Returns the name of the branch being rebased. Empty if rebasing a
    # detached HEAD.
    def rebased_branch
      @rebased_branch ||=
        @args[1] || `git symbolic-ref --short --quiet HEAD`.chomp
    end

    # Returns whether we are rebasing a detached HEAD rather than a branch
    def detached_head?
      rebased_branch.empty?
    end

    # Returns whether this rebase is a fast-forward
    def fast_forward?
      rebased_commits.empty?
    end

    # Returns the SHA1-sums of the series of commits to be rebased
    # in reverse topological order.
    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
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
overcommit-0.67.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.66.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.65.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.64.1 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.64.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.63.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.62.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.61.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.60.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.59.1 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.59.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-jeygeethanmedia-0.58.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.58.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.57.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.56.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.55.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.54.1 lib/overcommit/hook_context/pre_rebase.rb
overcommit-0.54.0 lib/overcommit/hook_context/pre_rebase.rb
overcommit-jeygeethanmedia-0.53.1.2 lib/overcommit/hook_context/pre_rebase.rb
overcommit-jeygeethanmedia-0.53.1.1 lib/overcommit/hook_context/pre_rebase.rb