diff options
Diffstat (limited to 'app/models/protected_branch.rb')
-rw-r--r-- | app/models/protected_branch.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index b4e2d17c3e5..96002c8668a 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -27,12 +27,17 @@ class ProtectedBranch < ApplicationRecord # Check if branch name is marked as protected in the system def self.protected?(project, ref_name) return true if project.empty_repo? && project.default_branch_protected? + return false if ref_name.blank? - Rails.cache.fetch("protected_ref-#{ref_name}-#{project.cache_key}") do + Rails.cache.fetch(protected_ref_cache_key(project, ref_name)) do self.matching(ref_name, protected_refs: protected_refs(project)).present? end end + def self.protected_ref_cache_key(project, ref_name) + "protected_ref-#{project.cache_key}-#{Digest::SHA1.hexdigest(ref_name)}" + end + def self.allow_force_push?(project, ref_name) project.protected_branches.allowing_force_push.matching(ref_name).any? end |