Commit 63186cd9 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Allow the default branch as branch name

parent 1fd476a0
---
title: Always allow the default branch as a branch name
merge_request: 3154
author:
type: fixed
...@@ -185,6 +185,7 @@ module Gitlab ...@@ -185,6 +185,7 @@ module Gitlab
def branch_name_allowed_by_push_rule?(push_rule) def branch_name_allowed_by_push_rule?(push_rule)
return true unless push_rule return true unless push_rule
return true if @branch_name.blank? return true if @branch_name.blank?
return true if @branch_name == @project.default_branch
push_rule.branch_name_allowed?(@branch_name) push_rule.branch_name_allowed?(@branch_name)
end end
......
...@@ -266,6 +266,15 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -266,6 +266,15 @@ describe Gitlab::Checks::ChangeAccess do
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "Branch name does not follow the pattern '^(w*)$'") expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "Branch name does not follow the pattern '^(w*)$'")
end end
end end
context 'when the default branch does not match the push rules' do
let(:push_rule) { create(:push_rule, branch_name_regex: 'not-master') }
let(:ref) { "refs/heads/#{project.default_branch}" }
it 'allows the default branch even if it does not match push rule' do
expect { subject }.not_to raise_error
end
end
end end
context 'existing member rules' do context 'existing member rules' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment