Create a merge request link in Git shell doesn't work for forks (error 500)

Summary

When pushing a new branch to a fork, something like this is displayed:

remote: To create a merge request for fork-branch, visit:
remote:   http://localhost:3000/arvid-group/foo/merge_requests/new?merge_request%5Bsource_branch%5D=fork-branch

The provided link leads to error 500.

Steps to reproduce

  • clone fork (doesn't happen with non-forked projects)
  • create new branch
  • commit and push
  • click link to create a new merge request

What is the current bug behavior?

Error 500 with the following happening in the backend:

Object not found - no match for id (...) at merge_base inside the Repository model. The commit with the given id can be accessed through the web interface and is displayed without problems.

What is the expected correct behavior?

A new merge request is created.

Possible fixes

Inside merge_base, @path_to_repo doesn't point to the fork. So the commit may be looked up in the wrong project.