Commit f7d30c20 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-merge-request-screen-deleted-source-branch' into 'master'

Do not create a MergeRequestDiff record when source branch is deleted

Fixes #23413 
Fixes #23897

See merge request !7481
parents 506f6bce f913170e
...@@ -60,15 +60,7 @@ module MergeRequests ...@@ -60,15 +60,7 @@ module MergeRequests
merge_requests = filter_merge_requests(merge_requests) merge_requests = filter_merge_requests(merge_requests)
merge_requests.each do |merge_request| merge_requests.each do |merge_request|
if merge_request.source_branch == @branch_name || force_push? reload_diff(merge_request) unless branch_removed?
merge_request.reload_diff
else
mr_commit_ids = merge_request.commits.map(&:id)
push_commit_ids = @commits.map(&:id)
matches = mr_commit_ids & push_commit_ids
merge_request.reload_diff if matches.any?
end
merge_request.mark_as_unchecked merge_request.mark_as_unchecked
end end
end end
...@@ -173,5 +165,16 @@ module MergeRequests ...@@ -173,5 +165,16 @@ module MergeRequests
def branch_removed? def branch_removed?
Gitlab::Git.blank_ref?(@newrev) Gitlab::Git.blank_ref?(@newrev)
end end
def reload_diff(merge_request)
if merge_request.source_branch == @branch_name || force_push?
merge_request.reload_diff
else
mr_commit_ids = merge_request.commits.map(&:id)
push_commit_ids = @commits.map(&:id)
matches = mr_commit_ids & push_commit_ids
merge_request.reload_diff if matches.any?
end
end
end end
end end
---
title: Do not create a MergeRequestDiff record when source branch is deleted
merge_request: 7481
author:
...@@ -227,6 +227,16 @@ describe MergeRequests::RefreshService, services: true do ...@@ -227,6 +227,16 @@ describe MergeRequests::RefreshService, services: true do
end end
end end
context 'when the source branch is deleted' do
it 'does not create a MergeRequestDiff record' do
refresh_service = service.new(@project, @user)
expect do
refresh_service.execute(@oldrev, Gitlab::Git::BLANK_SHA, 'refs/heads/master')
end.not_to change { MergeRequestDiff.count }
end
end
def reload_mrs def reload_mrs
@merge_request.reload @merge_request.reload
@fork_merge_request.reload @fork_merge_request.reload
......
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