Skip to content

Clear worktree on git fetch failures

Tim requested to merge timmmm/gitlab-runner:fetch_fallback into main

What does this MR do?

When the GetSources build stage fails it deletes the entire project directory.

Why was this MR needed?

If you use

GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: recursive

then the fetch can fail in various fun ways due to Git's sub-par support for submodules. One example of this is if you convert a directory to a submodule. git clean will refuse to clean it (because it's a submodule) and git submodule update --init will refuse to populate the submodule because there are files already there. In this situation the only solution is to rm -rf the whole thing.

This isn't the only issue that submodules cause, so as a general solution this commit changes the runner behaviour so that between GetSources attempts it deletes the entire project directory.

What's the best way to test this MR?

I added an integration test so you can do:

make development_environment
make splitic
export CI=0
splitic test -tags=integration ./executors/shell

And you should see:

pass 5.73s gitlab.com/gitlab-org/gitlab-runner/executors/shell TestBuildGitFetchStrategyFallback/bash

You can also want to verify that this test fails on main by cherry picking just that test. It doesn't depend on the other changes in this commit.

What are the relevant issue numbers?

Edited by Tim

Merge request reports