Merge request diff/changes show older commit if source branch was not rebased prior to creating the MR

Summary

MR Changes show older version of the target branch if the source branch was not updated (rebase) before creating the MR.

Steps to reproduce

  1. Create a project and in main branch add a file named VERSION with content 0.1.
  2. Create a branch branch-1. Update VERSION file to have content 1.0.
  3. Update VERSION file in main branch with content 0.2.
  4. Create a new merge request from branch-1 to main. Scroll down and click Changes tab. It will show change from 0.1 to 1.0 instead of 0.2 to 1.0

Example Project

https://gitlab.com/test5881/test-mr-diff/-/merge_requests/new/diffs?merge_request%5Bsource_project_id%5D=46336512&merge_request%5Bsource_branch%5D=branch-1&merge_request%5Btarget_project_id%5D=46336512&merge_request%5Btarget_branch%5D=main

What is the current bug behavior?

MR diff shows the version of target branch (I believe) from the time branch-1 was last rebased. It doesn't show the latest version of the target branch.

What is the expected correct behavior?

MR diff should show correct version of the target branch files.

Relevant logs and/or screenshots

Screenshot_2023-05-25_at_2.15.05_PM

Output of checks

This bug happens on GitLab.com /label reproduced on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

  • If the project is not a fork, before creating the MR, update source branch to get changes from target branch (ex rebase).
  • If this is happening in a forked project, update your fork before creating the MR.
Edited by Elif Munn