Fix create merge request button for forked projects
What does this MR do and why?
On a forked project, when there is an open merge request from the fork branch targeting the upstream project, the commits page incorrectly shows "Create merge request" instead of "View open merge request". Clicking "Create merge request" in that state errors. This MR fixes the bug.
Root cause. project.mergeRequests in GraphQL is scoped to the target project: MergeRequest.of_projects filters on target_project_id. When the frontend queries the fork for open merge requests, fork-to-upstream MRs are invisible because they live on the upstream project, not the fork.
The two GraphQL fields this MR consumes were added in now-merged backend MRs: sourcedMergeRequests in !255737 (merged) and defaultMergeRequestTarget in !260053 (merged).
Sourced detection applies to forks only. Non-forked projects deliberately keep the existing lookup: a branch there can legitimately have a second merge request toward a different target branch, so sourced detection would incorrectly hide the create button.
References
- Backend MR adding
sourcedMergeRequests: !255737 (merged) - Backend MR adding
defaultMergeRequestTarget: !260053 (merged) - Regression introduced by: !252846 (merged)
- Bug reported at: !252846 (comment 3822676573)
- Consistent test failure tracking: https://gitlab.com/gitlab-org/quality/test-failure-issues/-/work_items/44545
- Blocker for [Feature flag] clean up `project_commits_refactor` (#603171)
- Resolves #598206 (closed)
Screenshots or screen recordings
Edge cases from the first review round
Both are cases where mr_can_target_upstream? is false, so defaultMergeRequestTarget resolves to the fork itself: the button gates on the fork's own permissions and the create URL carries no merge_request[target_project_id].
How to set up and validate locally
- In GDK, fork a project under a second user account.
- Push a branch to the fork.
- Open a merge request from that fork branch targeting the upstream project's default branch.
- Visit the fork's commits page for that branch. The button should read "View open merge request" and link to the MR. Any open merge request sourced from the branch counts now, not only ones targeting the upstream default branch.
- Close or delete the MR and reload the commits page. "Create merge request" should appear only if the user has
createMergeRequestInpermission on the upstream project, and the link should carrymerge_request[target_project_id]pointing at the upstream project ID. - Optionally, enable the fork's "merge requests target this project" setting (Settings > Merge requests > Default target). Verify that the "Create merge request" button reappears based on the fork's own permissions and that the link no longer carries
merge_request[target_project_id].
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.







