Commit f913170e authored by Adam Niedzielski's avatar Adam Niedzielski

Do not create a MergeRequestDiff record when source branch is deleted

In order to have a valid MergeRequestDiff record when need head_commit_sha.
When a source branch is deleted head_commit_sha is nil.
This causes an exception in merge request "Changes" tab.
parent 37abb20c
...@@ -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