class Overcommit::Hook::PreRebase::MergedCommits

Prevents rebasing commits that have already been merged into one of a specified set of branches.

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_rebase/merged_commits.rb, line 7
def run
  # Allow rebasing a detached HEAD since no refs are changed.
  return :pass if detached_head? || illegal_commits.empty?

  message = 'Cannot rebase commits that have already been merged into ' \
            "one of #{branches.join(', ')}"

  [:fail, message]
end

Private Instance Methods

branches() click to toggle source
# File lib/overcommit/hook/pre_rebase/merged_commits.rb, line 19
def branches
  @branches ||= config['branches']
end
illegal_commits() click to toggle source
# File lib/overcommit/hook/pre_rebase/merged_commits.rb, line 23
def illegal_commits
  @illegal_commits ||= rebased_commits.select do |commit_sha1|
    branches_containing_commit =
      Overcommit::GitRepo.branches_containing_commit(commit_sha1)
    (branches_containing_commit & branches).any?
  end
end