diff --git a/app/models/project.rb b/app/models/project.rb index 32b0145ca24df983129242ebf5a5102faa85bf2d..80f1c0d598aba81b1d308e1eec2534928575d29c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -470,6 +470,10 @@ class Project < ActiveRecord::Base protected_branches_names.include?(branch_name) end + def developers_can_push_to_protected_branch?(branch_name) + protected_branches.map{ |pb| pb.developers_can_push if pb.name == branch_name }.compact.first + end + def forked? !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) end diff --git a/lib/gitlab/git_access.rb b/lib/gitlab/git_access.rb index 875f8d8b3a3149fcda4717eea9777ef52a073548..09724ae2e9215aff9efe3eae548ac98918220eb9 100644 --- a/lib/gitlab/git_access.rb +++ b/lib/gitlab/git_access.rb @@ -85,6 +85,8 @@ module Gitlab # and we dont allow remove of protected branch elsif newrev == Gitlab::Git::BLANK_SHA :remove_protected_branches + elsif project.developers_can_push_to_protected_branch?(branch_name(ref)) + :push_code else :push_code_to_protected_branches end