Empty diff after manual merge with pushing to fork
Summary
When manually merging a merge request submitted from a fork there is a chance of creating an empty merge request diff if a background job is not executed quick enough. This empty merge request diff prevents us from rendering "Discussion", "Pipelines", "Builds", "Changes", ... tabs so the context of the merge request is lost
Steps to reproduce
- Create a project
- Create a fork of this project
- Push to
my-featurebranch in the fork - Submit a merge request to the original project
- Manually merge
my-featurebranch tomaster - Push
masterbranch to the fork in GitLab - Push
masterbranch to the original project in GitLab
You won't be able to reproduce this bug in development without delaying the execution of your background jobs. See Description below.
Description
This commit https://gitlab.com/gitlab-org/gitlab-ce/commit/40a9b1ce00ed4e4f03431b731ca5a6716356d5a6 makes sure that we first close a merge request before attempting to reload it. We do not reload merge request diff if it is closed. We do not want to do that, because if changes are merged to master the merge request diff is empty.
If we follow the reproduction steps above the flow that we expect is:
- push to fork
- run
UpdateMergeRequestsWorkerfor push to fork - push to original project
- run
UpdateMergeRequestsWorkerfor push to original project
However, if the job queue is long then we can get the following flow:
- push to fork
- push to original project
- run
UpdateMergeRequestsWorkerfor push to fork - run
UpdateMergeRequestsWorkerfor push to original project
The problem with this flow is that UpdateMergeRequestsWorker for push to fork calls MergeRequest#reload_diff on merge requests in the original project (https://gitlab.com/gitlab-org/gitlab-ce/blob/90c0f610e29976608dbfeeb63bc4763982c5dbc3/app/services/merge_requests/refresh_service.rb#L59). The merge request is still open at this point. We perform comparison against master of the original project and the diff is empty, because we already pushed these commits.
