Commit d4b0f2d2 authored by Rubén Dávila's avatar Rubén Dávila

Fix a bug where branch could not be delete due to a push rule config

Push Rule for branch name should be ignored when deleting a branch
otherwise deleting some existing branches will not be possible.
parent 3f54d5d6
---
title: Fix a bug where branch could not be delete due to a push rule config
merge_request: 3900
author:
type: fixed
......@@ -195,13 +195,18 @@ module Gitlab
end
def branch_name_allowed_by_push_rule?(push_rule)
return true unless push_rule
return true if @branch_name.blank?
return true if @branch_name == @project.default_branch
return true if skip_branch_name_push_rule?(push_rule)
push_rule.branch_name_allowed?(@branch_name)
end
def skip_branch_name_push_rule?(push_rule)
push_rule.nil? ||
deletion? ||
@branch_name.blank? ||
@branch_name == @project.default_branch
end
def tag_deletion_denied_by_push_rule?(push_rule)
push_rule.try(:deny_delete_tag) &&
!updated_from_web? &&
......
......@@ -6,20 +6,24 @@ describe DeleteBranchService do
let(:user) { create(:user) }
let(:service) { described_class.new(project, user) }
shared_examples 'a deleted branch' do |branch_name|
it 'removes the branch' do
expect(branch_exists?(branch_name)).to be true
result = service.execute(branch_name)
expect(result[:status]).to eq :success
expect(branch_exists?(branch_name)).to be false
end
end
describe '#execute' do
context 'when user has access to push to repository' do
before do
project.add_developer(user)
end
it 'removes the branch' do
expect(branch_exists?('feature')).to be true
result = service.execute('feature')
expect(result[:status]).to eq :success
expect(branch_exists?('feature')).to be false
end
it_behaves_like 'a deleted branch', 'feature'
end
context 'when user does not have access to push to repository' do
......@@ -33,6 +37,15 @@ describe DeleteBranchService do
expect(branch_exists?('feature')).to be true
end
end
context 'when there is a push rule matching the branch name' do
before do
project.add_developer(user)
create(:push_rule, branch_name_regex: '^(w*)$')
end
it_behaves_like 'a deleted branch', 'add-pdf-file'
end
end
def branch_exists?(branch_name)
......
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