Repository navigation
fix(train): retarget stacked MRs to the train target before rebase - #111
Merged
Merged
Conversation
An MR stacked on another MR of the train (targeting its source branch) kept that branch as its target after the base merged: GitLab retargets dependent MRs only when the base's source branch is deleted on merge, and does it asynchronously. glmt deletes no branches, so the stacked MR was rebased onto and merged into the stale base branch, and the final pipeline wait on the train target timed out looking for its merge commit. The runner now retargets such an MR to the train target branch through the new Client.UpdateMergeRequestTargetBranch before rebasing it. An MR whose base was skipped is skipped too, since merging it would land its commits in a branch that never reached the target. A failed retarget skips the MR.
The rebase step label used the MR's original target branch, which reads "Rebase onto feature-a" for a stacked MR the runner has just retargeted to main.
Runs as a subtest on the GitLab instance of TestTrainMergesMRs, since a second container boot would not fit the 25-minute CI timeout. main is moved after the stack is created so the base MR's rebase rewrites its commits; the stacked MRs then carry stale copies of them. The test asserts each commit lands on main exactly once, i.e. GitLab's rebase drops the copies already merged.
sairus2k
enabled auto-merge (rebase)
October 15, 2026 15:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Merging a stack of MRs (
feature-b → feature-a → main) in one train merged the second MR intofeature-a, notmain.GitLab retargets dependent MRs only when the base MR's source branch is deleted on merge, and does it asynchronously. glmt deletes no branches, so after the base merged, the stacked MR still targeted
feature-a: the runner rebased it ontofeature-aand merged it there. The final pipeline wait then polledmainfor that merge commit until it timed out.Fix
Before rebasing an MR, the runner checks whether its target branch is the source branch of an MR already merged by this train. If so, it retargets the MR to the train's target branch via the new
Client.UpdateMergeRequestTargetBranch(PUT /merge_requests/:iidwithtarget_branch), then rebases and merges as usual.base branch X was not merged, instead of merging into a branch that never reachedmain.Retarget to mainstep, and the rebase label names the new target.Commits
fix(train)— client method (API, demo, logging, mocks) and runner logicfix(tui)— retarget step and rebase labeltest(e2e)— stack of three MRsdocs— README note on stacked MRsVerification
go test -tags e2e, passed in 499s): astacked MRssubtest reuses theTestTrainMergesMRscontainer, since a second boot would not fit the 25-minute CI timeout. It movesmainafter creating the stack so the base rebase rewrites its commits, then asserts all three MRs are merged intomainand each commit appears onmainexactly once — GitLab's rebase drops the stale copies of the base's commits.Not covered
A stacked MR queued before its base still merges into the base branch, as before. The README now says to select the base first.