Skip to content

Add check for existing MR with for same branch combo

What does this MR do and why?

Since we don't allow for multiple MRs with the same target and source branch combination, add a check for any before we get to the MR details creation page.This also will render the branch selection view when the user attempts to create an MR by accessing the creation page directly via url (/-/merge_requests/new?merge_request[source_branch]=my_new_branch for example)

We do this by extracting the logic from MergeRequest#validate_branches which is used in a validator, and run that check when attempting to render the "New merge request" edit/details page.

Screenshots or screen recordings

Existing MR

_Wget2___GitLab_2023-08-04_11-07-55

Note the flash message displayed when conflict is detected after pressing [Compare branches and continue]. This messaging is identical to the existing validation error found on the MergeRequest model.

_Wget2___GitLab_2023-08-04_11-07-07

How to set up and validate locally

  1. Create a merge request targeting the project's default branch (usually master or main)
  2. Return to Branches page and attempt to create a new MR using the same source and target branch combination
  3. Attempt to go directly to "New merge request" edit page using URL /-/merge_requests/new?merge_request[source_branch]=[whatever your source branch was named]

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #22015 (closed)

Edited by Kerri Miller

Merge request reports