Skip to content

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

  1. Create a project
  2. Create a fork of this project
  3. Push to my-feature branch in the fork
  4. Submit a merge request to the original project
  5. Manually merge my-feature branch to master
  6. Push master branch to the fork in GitLab
  7. Push master branch 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:

  1. push to fork
  2. run UpdateMergeRequestsWorker for push to fork
  3. push to original project
  4. run UpdateMergeRequestsWorker for push to original project

However, if the job queue is long then we can get the following flow:

  1. push to fork
  2. push to original project
  3. run UpdateMergeRequestsWorker for push to fork
  4. run UpdateMergeRequestsWorker for 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.

Relevant logs and/or screenshots

Screen_Shot_2016-12-02_at_16.05.32