Skip to content

Commit 7000124

Browse files
authored
fix: Handle remote prune failures gracefully (#4295)
Wrap the git remote prune command in a try-catch block to prevent the action from failing if the prune operation fails. Instead, log a warning message and allow the action to continue. Fixes edge cases where the prune command may fail on self-hosted runners but shouldn't block the pull request creation workflow.
1 parent 34aa40e commit 7000124

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

dist/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,12 @@ function createPullRequest(inputs) {
458458
// deleted after being merged or closed. Without this the push using
459459
// '--force-with-lease' fails due to "stale info."
460460
// https://github.com/peter-evans/create-pull-request/issues/633
461-
yield git.exec(['remote', 'prune', branchRemoteName]);
461+
try {
462+
yield git.exec(['remote', 'prune', branchRemoteName]);
463+
}
464+
catch (error) {
465+
core.warning(`Failed to prune remote '${branchRemoteName}': ${error.message}`);
466+
}
462467
}
463468
core.endGroup();
464469
// Apply the branch suffix if set

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/create-pull-request.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
127127
// deleted after being merged or closed. Without this the push using
128128
// '--force-with-lease' fails due to "stale info."
129129
// https://github.com/peter-evans/create-pull-request/issues/633
130-
await git.exec(['remote', 'prune', branchRemoteName])
130+
try {
131+
await git.exec(['remote', 'prune', branchRemoteName])
132+
} catch (error) {
133+
core.warning(
134+
`Failed to prune remote '${branchRemoteName}': ${(error as Error).message}`
135+
)
136+
}
131137
}
132138
core.endGroup()
133139

0 commit comments

Comments
 (0)