Skip to content

Only add to merge train if not already there

What does this MR do and why?

Rails has_one associations have the somewhat surprising property of destroying a previously associated record on assignment. This could cause a merge train to end up in an inconsistent state.

See #396414

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

In a rails console:

mr = MergeRequest.last # arbitrary open MR
service = AutoMerge::MergeTrainService.new(mr.target_project, User.first, {})
service.execute(mr)
p mr.merge_train_car.id

mr.reload
service.execute(mr)
p mr.merge_train_car.id # should be the same as before
Edited by Hordur Freyr Yngvason

Merge request reports