Skip to content

Track merged_commit_sha on merge

Hordur Freyr Yngvason requested to merge track-merged-commit-sha-on-merge into master

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

Before After
Without this change, the merge train gets re-created on each non-squashed fast-forward merge After this change, the merge train does not get re-created on each merge (each passed pipeline implies a merge. You can verify this too by checking the commits. The seeded project has no pipeline on main)
Screenshot_2023-09-08_at_1.02.22_PM Screenshot_2023-09-08_at_1.06.53_PM

How to set up and validate locally

  1. Enable the following feature flags:
    Feature.enable(:fast_forward_merge_trains_support)
    Feature.enable(:merge_trains_create_ref_service)
  2. Seed a project with a bunch of merge requests:
    bin/rake gitlab:seed:merge_trains:project
  3. Visit the project, go to Settings > Merge Requests and change the Merge method to Fast-forward.
  4. Visit a few of the open merge requests in separate tabs or windows
  5. Wait for the pipeline to finish on all of them (wait for the button Set to auto-merge to change to Merge)
  6. In rapid succession, press Merge for each of them to start a Fast-forward merge train
  7. Navigate to Build > Pipelines in the sidebar
  8. Verify that none of the started merge trains has a merge commit
  9. 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.

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
Edited by Hordur Freyr Yngvason

Merge request reports