From e0f106ae97334d622c6eb7580e72e17181fddd6e Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 4 Jul 2017 11:51:00 +0200 Subject: [PATCH] DeleteMergedBranchesService should not delete protected branches When deleting all the branches that are merged, the protected branches should not be deleted. --- app/services/delete_merged_branches_service.rb | 2 ++ .../unreleased/tc-no-delete-protected-merged-branches.yml | 4 ++++ spec/services/delete_merged_branches_service_spec.rb | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 changelogs/unreleased/tc-no-delete-protected-merged-branches.yml diff --git a/app/services/delete_merged_branches_service.rb b/app/services/delete_merged_branches_service.rb index 3b611588466..5c9e2a16c71 100644 --- a/app/services/delete_merged_branches_service.rb +++ b/app/services/delete_merged_branches_service.rb @@ -10,6 +10,8 @@ class DeleteMergedBranchesService < BaseService branches = branches.select { |branch| project.repository.merged_to_root_ref?(branch) } # 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.each do |branch| DeleteBranchService.new(project, current_user).execute(branch) diff --git a/changelogs/unreleased/tc-no-delete-protected-merged-branches.yml b/changelogs/unreleased/tc-no-delete-protected-merged-branches.yml new file mode 100644 index 00000000000..663a0349bac --- /dev/null +++ b/changelogs/unreleased/tc-no-delete-protected-merged-branches.yml @@ -0,0 +1,4 @@ +--- +title: Do not delete protected branches when deleting all merged branches +merge_request: 12624 +author: diff --git a/spec/services/delete_merged_branches_service_spec.rb b/spec/services/delete_merged_branches_service_spec.rb index cae74df9c90..fe21ca0b3cb 100644 --- a/spec/services/delete_merged_branches_service_spec.rb +++ b/spec/services/delete_merged_branches_service_spec.rb @@ -24,6 +24,14 @@ describe DeleteMergedBranchesService, services: true do expect(project.repository.branch_names).to include('master') end + it 'keeps protected branches' do + create(:protected_branch, project: project, name: 'improve/awesome') + + service.execute + + expect(project.repository.branch_names).to include('improve/awesome') + end + context 'user without rights' do let(:user) { create(:user) }