gitlab-org/gitlab-ee#7380 will introduce building combined refs for merge request pipelines.
GitLab will need to schedule jobs for refs/merge-requests/:iid:/merge ref that is outside of the default cloning ref-spec.
Today users can control how they retrieve source code (clone, fetch, or none). Given there's no way to clone outside of the default ref-spec, we will force a fetch mode in case of merge request pipeline.
Or git fetch the differs only in lack of rm -rf repo.
I don't think that we need this distinction, as our git clone strategy effectively says: wipe-out git repository every time.
Also, the GIT_DEPTH just becomes git fetch --depth $GIT_DEPTH :)
If we could effectively detect the type of refs to fetch (or not detect and be dumb?) (but rather pass full ref spec to runner? this would be cool) we could fix that problem in slightly different way and very consistient too:
remove if wipe is set (our todays git clone),
git init,
git fetch origin <use-refspec-if-specified-by-gitlab|otherwise do not pass>,
I will not take the risk of breaking the default cloning method, I'll prefer ship the new one only for perspective merge pipeline and then extend it to the clone strategy.
I'm quite sure it will work on docker with our helper image, but what about non-disposable environments like shell, and ssh? We have no control over the git version there.
Then prefer to use refspec and depth (where depth is taken from GIT_DEPTH variable):
And refspec looks like follows:
if depth>0: - for tag: +refs/tags/v1.0:refs/tags/v1.0 - for branch or detached MR: +refs/heads/master:refs/origin/heads/master - for merge request merge: +refs/merge_requests/iid/merge:refs/origin/merge_requests/iid/mergeelse: - for tag or branch or detached MR: +refs/heads/*:refs/origin/heads/* +refs/tags/*:refs/tags/* - for merge request merge: +refs/merge_requests/iid/merge:refs/origin/merge_requests/iid/merge
This makes us remove some of the logic from runner and prefer refspec to be GitLab controlled and fully flexible.
I like this, this will also solve my concerns about changing the way we fetch/clone as we can implement a new method and apply it only when the new API is available. That way we can control this with a feature flag at gitlab level but we still retain backward compatibility with old gitlab instances.
I wish we could set default GIT_DEPTH: set for all clones, and disable if not needed.
I prefer if we could set it in Runner API and push default from GitLab, with like depth=100.