class Overcommit::Hook::PreCommit::ForbiddenBranches

Prevents commits to branches matching one of the configured patterns.

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_commit/forbidden_branches.rb, line 6
def run
  return :pass unless forbidden_commit?

  [:fail, "Committing to #{current_branch} is forbidden"]
end

Private Instance Methods

current_branch() click to toggle source
# File lib/overcommit/hook/pre_commit/forbidden_branches.rb, line 22
def current_branch
  @current_branch ||= Overcommit::GitRepo.current_branch
end
forbidden_branch_patterns() click to toggle source
# File lib/overcommit/hook/pre_commit/forbidden_branches.rb, line 18
def forbidden_branch_patterns
  @forbidden_branch_patterns ||= Array(config['branch_patterns'])
end
forbidden_commit?() click to toggle source
# File lib/overcommit/hook/pre_commit/forbidden_branches.rb, line 14
def forbidden_commit?
  forbidden_branch_patterns.any? { |p| File.fnmatch(p, current_branch) }
end