diff options
author | Stan Hu <stanhu@gmail.com> | 2017-04-17 06:51:16 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-04-19 17:56:08 +0300 |
commit | 11fd2f80b0500736a9df0befbd371bfec9549138 (patch) | |
tree | 269a8c30300679e41a4bf73346beebe56e327314 /app/services/delete_merged_branches_service.rb | |
parent | a9da37434af6d44c5f851affd4bd69b370760e8e (diff) |
Don't delete a branch involved in an open merge request in "Delete all merged branches" service
Customers were surprised by the previous behavior, which destroyed branches
even though an open merge request existed for it.
Closes #29427
Diffstat (limited to 'app/services/delete_merged_branches_service.rb')
-rw-r--r-- | app/services/delete_merged_branches_service.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/services/delete_merged_branches_service.rb b/app/services/delete_merged_branches_service.rb index 1b5623baebe..3b611588466 100644 --- a/app/services/delete_merged_branches_service.rb +++ b/app/services/delete_merged_branches_service.rb @@ -8,9 +8,20 @@ class DeleteMergedBranchesService < BaseService branches = project.repository.branch_names 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 branches.each do |branch| DeleteBranchService.new(project, current_user).execute(branch) end end + + private + + def merge_request_branch_names + # reorder(nil) is necessary for SELECT DISTINCT because default scope adds an ORDER BY + source_names = project.origin_merge_requests.opened.reorder(nil).uniq.pluck(:source_branch) + target_names = project.merge_requests.opened.reorder(nil).uniq.pluck(:target_branch) + (source_names + target_names).uniq + end end |