Sha256: b8923ef0ce4fb6045763ecaee3bb99b5ea56320f67229ad88409a7909b0ddbf2

Contents?: true

Size: 610 Bytes

Versions: 22

Compression:

Stored size: 610 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Prevents commits to branches matching one of the configured patterns.
  class ForbiddenBranches < Base
    def run
      return :pass unless forbidden_commit?

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

    private

    def forbidden_commit?
      forbidden_branch_patterns.any? { |p| File.fnmatch(p, current_branch) }
    end

    def forbidden_branch_patterns
      @forbidden_branch_patterns ||= Array(config['branch_patterns'])
    end

    def current_branch
      @current_branch ||= Overcommit::GitRepo.current_branch
    end
  end
end

Version data entries

22 entries across 20 versions & 2 rubygems

Version Path
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/forbidden_branches.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/forbidden_branches.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/forbidden_branches.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.46.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.45.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.44.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.43.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.42.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.41.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.40.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.39.1 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.39.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.38.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.37.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.36.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.35.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.34.2 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.34.1 lib/overcommit/hook/pre_commit/forbidden_branches.rb
overcommit-0.34.0 lib/overcommit/hook/pre_commit/forbidden_branches.rb