fix: drop unnecessary fetch with unshallow on push-to-fork (#2849)

This commit is contained in:
Peter Evans 2024-04-12 18:18:19 +09:00 committed by GitHub
parent 6ce4eca6b6
commit c55203cfde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 26 deletions

View file

@ -173,24 +173,12 @@ export async function createOrUpdateBranch(
// Stash any uncommitted tracked and untracked changes
const stashed = await git.stashPush(['--include-untracked'])
// Perform fetch and reset the working base
// Reset the working base
// Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) {
core.info(`Resetting working base branch '${workingBase}'`)
if (branchRemoteName == 'fork') {
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
await git.fetch(
[`${workingBase}:${workingBase}`],
baseRemote,
['--force'],
true
)
} else {
// If the remote is 'origin' we can git reset
await git.checkout(workingBase)
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
}
await git.checkout(workingBase)
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
}
// If the working base is not the base, rebase the temp branch commits