refs/merge-requests not updated in target repo when source branch is updated
The problem
When an update is made to a branch that is the source branch for an open merge request, the corresponding ref in .git/refs/merge-requests
in the target repository is not updated.
Explanation
Whenever a new merge request is created a new ref is created in the target repository under .git/refs/merge-requests
that points to the current head of the source branch for the merge.
Gitlab does the equivalent of the following from the target repository:
git fetch source_repo refs/heads/my_new_feature:refs/merge-requests/X/head
where the X
would be replaced with the ID of the merge request within the target repo.
If changes are now added to branch my_new_feature
the new objects automatically get fetched to the target repository (and in the web UI the merge request is updated), but the refs/merge-requests/X/head
is not updated.
This is due to the fact that in
merge_requests_controller.rb
the method ensure_ref_fetched
of the MergeRequest
model is used. This means that the ref is only fetched from the source repo if refs/merge-requests/X/head
does not exist.
Expected behaviour
I would expect that refs/merge-requests/X/head
always points to the most up-to date version of the source branch. This seems reasonable, as otherwise anyone using a CLI workflow will not have the most up-to date version of the merge request. In addition, if the target repo is pruned at any point, then the commits added after the merge request was opened will disappear from the target repo.