summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@iotcl.com>2017-08-02 14:40:17 +0200
committerToon Claes <toon@iotcl.com>2017-08-02 14:45:54 +0200
commit35081a77b0527e606c0835a979403ec4d55564d5 (patch)
treee3d5841cf0f0f8807b659e055ca9f618016f28a9
parent1b117e7f2d8cf4c2793bd2234688ad8739056894 (diff)
downloadgitlab-ce-35081a77b0527e606c0835a979403ec4d55564d5.tar.gz
Make Delete Merged Branches handle wildcard protected branches correctly
The "Delete Merged Branches" button should filter out protected branches matching the wildcard patterns. Closes gitlab-org/gitlab-ce#35592.
-rw-r--r--app/services/delete_merged_branches_service.rb2
-rw-r--r--changelogs/unreleased/tc-fix-wildcard-protected-delete-merged.yml4
-rw-r--r--spec/services/delete_merged_branches_service_spec.rb8
3 files changed, 13 insertions, 1 deletions
diff --git a/app/services/delete_merged_branches_service.rb b/app/services/delete_merged_branches_service.rb
index 5c9e2a16c71..ff11bd59d29 100644
--- a/app/services/delete_merged_branches_service.rb
+++ b/app/services/delete_merged_branches_service.rb
@@ -11,7 +11,7 @@ class DeleteMergedBranchesService < BaseService
# Prevent deletion of branches relevant to open merge requests
branches -= merge_request_branch_names
# Prevent deletion of protected branches
- branches -= project.protected_branches.pluck(:name)
+ branches = branches.reject { |branch| project.protected_for?(branch) }
branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch)
diff --git a/changelogs/unreleased/tc-fix-wildcard-protected-delete-merged.yml b/changelogs/unreleased/tc-fix-wildcard-protected-delete-merged.yml
new file mode 100644
index 00000000000..9ca5f81cf79
--- /dev/null
+++ b/changelogs/unreleased/tc-fix-wildcard-protected-delete-merged.yml
@@ -0,0 +1,4 @@
+---
+title: Make Delete Merged Branches handle wildcard protected branches correctly
+merge_request: 13251
+author:
diff --git a/spec/services/delete_merged_branches_service_spec.rb b/spec/services/delete_merged_branches_service_spec.rb
index 4b872d667cf..03c682ae0d7 100644
--- a/spec/services/delete_merged_branches_service_spec.rb
+++ b/spec/services/delete_merged_branches_service_spec.rb
@@ -32,6 +32,14 @@ describe DeleteMergedBranchesService do
expect(project.repository.branch_names).to include('improve/awesome')
end
+ it 'keeps wildcard protected branches' do
+ create(:protected_branch, project: project, name: 'improve/*')
+
+ service.execute
+
+ expect(project.repository.branch_names).to include('improve/awesome')
+ end
+
context 'user without rights' do
let(:user) { create(:user) }