Fetch from the source project for as-if-jh pipeline so it works for forks
This is discovered at !107925 (comment 1245626938) where the failing job showed this: https://gitlab.com/gitlab-org/gitlab/-/jobs/3627286974
$ git fetch --unshallow --filter=tree:0 origin "${CI_COMMIT_REF_NAME}"
fatal: couldn't find remote ref admin-mode-for-api
That happened because the pipeline is running in the canonical project because it's triggered by a team member, however, the canonical project doesn't have the branch for the merge request, thus it cannot fetch from origin
for that branch.
We need to fetch from the source project of the merge request, rather than from the pipeline project.
Workaround
A very simple workaround is, fetch the branch from the fork locally, and push it to the canonical project, so that the branch does exist in the canonical project. I did this like:
git fetch git@gitlab.com:siemens/gitlab.git admin-mode-for-api
git checkout FETCH_HEAD
git checkout -b admin-mode-for-api
git push ee admin-mode-for-api
And then retry the job prepare-as-if-jh-branch
.