Track merged_commit_sha on merge
What does this MR do and why?
This ties together a couple of recent changes to ensure fast-forward merge trains merges use the correct SHAs on merge, and that the associated merge request gets updated with the correct values:
In !129311 (merged) we added
the column merged_commit_sha
, which represents the SHA of every merged
merge request, independently of the merge method.
In !129979 (merged), we
added train_ref
to merge_requests.merge_params
, which contains the
exact SHAs used to construct the ref, which should be written to the
merge request on merge.
This change is behind the existing feature flag
fast_forward_merge_trains_support
, see
#28244
Addresses both #422483 (closed) and #418822 (closed)
Screenshots or screen recordings
How to set up and validate locally
- Enable the following feature flags:
Feature.enable(:fast_forward_merge_trains_support) Feature.enable(:merge_trains_create_ref_service)
- Seed a project with a bunch of merge requests:
bin/rake gitlab:seed:merge_trains:project
- Visit the project, go to
Settings > Merge Requests
and change the Merge method to Fast-forward. - Visit a few of the open merge requests in separate tabs or windows
- Wait for the pipeline to finish on all of them (wait for the button
Set to auto-merge
to change toMerge
) - In rapid succession, press
Merge
for each of them to start a Fast-forward merge train - Navigate to
Build > Pipelines
in the sidebar - Verify that none of the started merge trains has a merge commit
- Verify that all of the merge trains get merged and that the train does not get re-created at any point
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
For database review
Example raw query after the change, see execution on postgres.ai (internal link):
SELECT
1 AS one
FROM
"merge_requests"
WHERE
"merge_requests"."id" IN (
SELECT
"merge_trains"."merge_request_id"
FROM
"merge_trains"
WHERE
"merge_trains"."target_project_id" = 7764
AND "merge_trains"."target_branch" = 'master'
AND ("merge_trains"."status" IN (1, 4))
ORDER BY
"merge_trains"."id" DESC
LIMIT 20)
AND (merge_commit_sha = '123'
OR in_progress_merge_commit_sha = '123'
OR squash_commit_sha = '123'
OR merged_commit_sha = '123')
LIMIT 1