// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
constlockPaths=[
path.join(repositoryPath,'.git','index.lock'),
path.join(repositoryPath,'.git','shallow.lock')
]
for(constlockPathoflockPaths){
try{
awaitio.rmRF(lockPath)
}catch(error){
core.debug(`Unable to delete '${lockPath}'. ${error.message}`)
}
}
// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
constlockPaths=[
path.join(repositoryPath,'.git','index.lock'),
path.join(repositoryPath,'.git','shallow.lock')
]
for(constlockPathoflockPaths){
try{
awaitio.rmRF(lockPath)
// Checkout detached HEAD
if(!(awaitgit.isDetached())){
awaitgit.checkoutDetach()
}
// Remove all refs/heads/*
letbranches=awaitgit.branchList(false)
for(constbranchofbranches){
awaitgit.branchDelete(false,branch)
}
// Remove all refs/remotes/origin/* to avoid conflicts
branches=awaitgit.branchList(true)
for(constbranchofbranches){
awaitgit.branchDelete(true,branch)
}
// Clean
if(clean){
if(!(awaitgit.tryClean())){
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}'.`
)
remove=true
}elseif(!(awaitgit.tryReset())){
remove=true
}
if(remove){
core.warning(
`Unable to clean or reset the repository. The repository will be recreated instead.`
)
}
}
}catch(error){
core.debug(`Unable to delete '${lockPath}'. ${error.message}`)
}
}
try{
// Checkout detached HEAD
if(!(awaitgit.isDetached())){
awaitgit.checkoutDetach()
}
// Remove all refs/heads/*
letbranches=awaitgit.branchList(false)
for(constbranchofbranches){
awaitgit.branchDelete(false,branch)
}
// Remove all refs/remotes/origin/* to avoid conflicts
branches=awaitgit.branchList(true)
for(constbranchofbranches){
awaitgit.branchDelete(true,branch)
}
}catch(error){
core.warning(
`Unable to prepare the existing repository. The repository will be recreated instead.`
)
returnfalse
}
// Clean
if(clean){
letsucceeded=true
if(!(awaitgit.tryClean())){
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}'.`
)
succeeded=false
}elseif(!(awaitgit.tryReset())){
succeeded=false
}
if(!succeeded){
core.warning(
`Unable to clean or reset the repository. The repository will be recreated instead.`
`Unable to prepare the existing repository. The repository will be recreated instead.`
)
remove=true
}
returnsucceeded
}
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}'`)