Track commit SHAs that were fast-forward merged from merge train ref
Problem to solve
When merging directly from the merge train ref, we merge a SHA that is not directly associated with any model. This makes it
For example, the scope MergeRequests.by_related_commit_sha
is used to identify merge requests associated with a given commit SHA. At the time of writing, it was implemented as follows:
scope :by_related_commit_sha, -> (sha) do
from_union(
[
by_commit_sha(sha),
by_squash_commit_sha(sha),
by_merge_commit_sha(sha)
]
)
end
A similar column, squash_commit_sha
, was added for squash merges, for the same reason. See #21686 (closed) for details on that.
This is specifically necessary to track fast-forward non-squashed MRs, as those will not have a commit SHA on the train ref that coincides with any other already-tracked SHA.
Background
The following discussion from !125921 (merged) should be addressed:
-
@hfyngvason started a discussion: I know I wrote this bit, but I wonder if this is actually sufficient. The possible issue is that the merged commit will only exist on the train ref and not on the merge request's source branch.
Basically, we need to make sure that features tracking a merged commit back to a merge request still work, especially for merge trains with more than one car.
-
[ ... ] it makes me wonder why
squash_commit_sha
is needed. I suspect it's for tracking purposes, so maybe we need a similar field for tracking rebased merge requests.We should check if there's already enough bookkeeping being done or if a new column (and business logic) needs to be added.
Proposal
Add a new column, merged_commit_sha
, that should be the SHA of the commit of what was finally written to target_branch
for any type of merge. It will have some overlap with existing columns, but have the benefit of always being present and always tracking back to a merge request.
It would be a variation of squash_commit_sha
and merge_commit_sha
that supports any type of merge, including ones that preprocesses the source out-of-band prior to the merge.
This is important for fast-forward merge trains, but also for fast-forward merges, which are currently implicitly tracked via their diff head SHA. This happens to coincide with the target branch commit SHA for true fast-froward merges, but won't match when merging out of band, e.g. from a merge train ref.
Definition of done
Required:
- Database column is in place (the proposed name is not set in stone, feel free to change it)
- The SHA of the merged commit is tracked
-
MergeTrains::Train#sha_exists_in_history?
uses the new column behind thefast_forward_merge_trains_support
feature flag
Nice to have (create follow ups for whatever is not done within this issue):
- Database indexes similar to those for
squash_commit_sha
andmerge_commit_sha
are in place (the#sha_exists_in_history?
query is not affected by this) - Other relevant queries, such as
by_related_commit_sha
, have been updated to include the new column
Backfilling is not expected.