Commit d20a28c4 authored by Stan Hu's avatar Stan Hu

Clear merge request error on push to source branch

If a merge error happens for some reason to a merge request, that error
will persist even after a new push to the repository. This makes it
impossible for a user to merge a merge request. The only workaround is
to close the existing merge request and open a new one.

If a user pushes to the source branch, we should clear out the merge
error since the diff would likely have changed. If a user pushes to the
target branch, we still want to keep the error present so the user can
take action. Clearing it out in that case would likely lead to confusion
because the error would disappear on unrelated changes.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/34186
parent 19a8a50e
......@@ -115,6 +115,10 @@ module MergeRequests
filter_merge_requests(merge_requests).each do |merge_request|
if branch_and_project_match?(merge_request) || @push.force_push?
merge_request.reload_diff(current_user)
# Clear existing merge error if the push were directed at the
# source branch. Clearing the error when the target branch
# changes will hide the error from the user.
merge_request.merge_error = nil
elsif merge_request.merge_request_diff.includes_any_commits?(push_commit_ids)
merge_request.reload_diff(current_user)
end
......
---
title: Clear merge request error on push to source branch
merge_request: 32001
author:
type: fixed
......@@ -94,6 +94,31 @@ describe MergeRequests::RefreshService do
expect(@fork_build_failed_todo).to be_done
end
context 'when a merge error exists' do
let(:error_message) { 'This is a merge error' }
before do
@merge_request = create(:merge_request,
source_project: @project,
source_branch: 'feature',
target_branch: 'master',
target_project: @project,
merge_error: error_message)
end
it 'clears merge errors when pushing to the source branch' do
expect { refresh_service.execute(@oldrev, @newrev, 'refs/heads/feature') }
.to change { @merge_request.reload.merge_error }
.from(error_message)
.to(nil)
end
it 'does not clear merge errors when pushing to the target branch' do
expect { refresh_service.execute(@oldrev, @newrev, 'refs/heads/master') }
.not_to change { @merge_request.reload.merge_error }
end
end
it 'reloads source branch MRs memoization' do
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
......
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