// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
constlockPaths=[
constlockPaths=[
path.join(repositoryPath,'.git','index.lock'),
path.join(repositoryPath,'.git','index.lock'),
@ -190,35 +209,40 @@ async function tryPrepareExistingDirectory(
for(constbranchofbranches){
for(constbranchofbranches){
awaitgit.branchDelete(true,branch)
awaitgit.branchDelete(true,branch)
}
}
}catch(error){
core.warning(
`Unable to prepare the existing repository. The repository will be recreated instead.`
)
returnfalse
}
// Clean
// Clean
if(clean){
if(clean){
letsucceeded=true
if(!(awaitgit.tryClean())){
if(!(awaitgit.tryClean())){
core.debug(
core.debug(
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
)
)
succeeded=false
remove=true
}elseif(!(awaitgit.tryReset())){
}elseif(!(awaitgit.tryReset())){
succeeded=false
remove=true
}
}
if(!succeeded){
if(remove){
core.warning(
core.warning(
`Unable to clean or reset the repository. The repository will be recreated instead.`
`Unable to clean or reset the repository. The repository will be recreated instead.`
)
)
}
}
}
returnsucceeded
}catch(error){
core.warning(
`Unable to prepare the existing repository. The repository will be recreated instead.`
)
remove=true
}
}
}
returntrue
if(remove){
// Delete the contents of the directory. Don't delete the directory itself
// since it might be the current working directory.
core.info(`Deleting the contents of '${repositoryPath}'`)