Tweak clean: false when there's no .git dir

If the checkout directory doesn't contain .git, previously the action
always erased the entire directory: now, it only does it if the clean
input is true (which is the default).

This means that files set-up _before_ actions/checkout is used do not
get erased before cloning and checkout the repository.
This commit is contained in:
David Allsopp 2021-08-03 14:46:53 +01:00
parent 25a956c84d
commit 44b7815b62
2 changed files with 9 additions and 7 deletions

View file

@ -24,10 +24,10 @@ export async function prepareExistingDirectory(
remove = true
}
// Fetch URL does not match
else if (
!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) ||
repositoryUrl !== (await git.tryGetFetchUrl())
) {
else if (!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git'))) {
remove = clean
}
else if (repositoryUrl !== (await git.tryGetFetchUrl())) {
remove = true
} else {
// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process