When deleting merged branches, ignore protected tags

In gitlab-org/gitlab-ce!13251 wildcard Protected Branches were handled
properly when deleting all merged branches. But this fix wasn't that
good. It also checked branch names against Protected Tags. That's not
correct.

This change will **only** check if there is a Protected Branch
matching the merged branch, and ignores Protected Tags.

Closes gitlab-org/gitlab-ce#39732.
This commit is contained in:
Toon Claes 2017-11-07 16:49:07 +01:00
parent dc1e6b4362
commit ca3c868567
3 changed files with 14 additions and 1 deletions

View file

@ -13,7 +13,7 @@ class DeleteMergedBranchesService < BaseService
# Prevent deletion of branches relevant to open merge requests
branches -= merge_request_branch_names
# Prevent deletion of protected branches
branches = branches.reject { |branch| project.protected_for?(branch) }
branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch)

View file

@ -0,0 +1,5 @@
---
title: When deleting merged branches, ignore protected tags
merge_request: 15252
author:
type: fixed

View file

@ -42,6 +42,14 @@ describe DeleteMergedBranchesService do
expect(project.repository.branch_names).to include('improve/awesome')
end
it 'ignores protected tags' do
create(:protected_tag, project: project, name: 'improve/*')
service.execute
expect(project.repository.branch_names).not_to include('improve/awesome')
end
context 'user without rights' do
let(:user) { create(:user) }