Stop returning mr head diffs as regular diffs
Issue: Merge head commit set as `last_commit` in merge... (#578761)
What does this MR do and why?
References
This MR attempts to fix a bug that is related to a RFH.
gitlab-com/request-for-help#3510+
I believe there is some caching of merge_head diffs, due to the relation specification with the merge_request model. I do not believe the scope on the has_one is sufficent to distinguish between the two different kinds of diffs, to demonstrate how this bug could occur run via rails console:
mr = MergeRequest.find(mr_id) # find an MR with a merge_head diff
mr.merge_request_diff.diff_type # this should give "regular"
mr.merge_head_diff.head_commit # this call causes the mr.merge_request_diff to cache the `merge_head_diff` as the `merge_request_diff`
mr.merge_request_diff.diff_type # this would produce the merge_head_diff
Setting inverse_of to false is one way of preventing Rails from caching the merge_head diff, as the merge_request_diff.
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
mr = MergeRequest.find(mr_id) # find an MR with a merge_head diff
mr.merge_request_diff.diff_type # this should give "regular"
mr.merge_head_diff.head_commit # load a merge_head_diff
mr.merge_request_diff # this should still be the same regular diff, with the same ID
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Safwan Ahmed