Preserve a remote reference for merged MRs
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Proposal
At the moment, it can be difficult to reliably correlate commits that land in a branch to the commits that were in the merge request. This is because commits can be mutated as they land, chiefly due to squash merges. This can cause difficult-to-solve problems; for example:
- reliably identifying MRs that commits came from (e.g. #22694)
- identifying commits for cherry-picking across branches (e.g.
git cherry
) - even identifying whether specific commits have landed (e.g.
git branch --contains
)
Today, gitlab maintains one or two long-lived refs for each MR:
-
refs/merge-requests/:iid/head
(the head of the MR branch) -
refs/merge-requests/:iid/merge
(if using merge pipelines, the merge commit)
There's also a short-lived one refs/merge-requests/:iid/train
to close a merge-train race condition.
My proposal is to add a third long-lived MR ref, refs/merge-requests/:iid/completed
which points at the post-merge merge commit (post-squash) (or the last commit in the branch, if the fast-forwarding). I'm not tied to completed
, I probably would have used merged
if merge
wasn't already in use.
Some examples of commands that I'd like to work (assume for these examples I have this fetch refspec in .git/config
: fetch = +refs/merge-requests/*:refs/remotes/origin/mr/*
) (forgive me for minor errors here, I'm writing them in this buffer)
- List MRs that have landed on a branch:
completed=($(git branch --merged origin/develop | grep 'mr/.*/completed' | cut -d / -f 2 ))
) - Retrieve original commits given an mr:
for i in "${completed[@]}; do git diff $(git merge-base origin/develop mr/$i/head)..mr/$i/head
- find downstream branches from the landed MR:
git branch -r --contains mr/12345/completed