fix: Pull branch if push errors (#534)

This commit is contained in:
Brace Sproul 2025-07-25 15:44:03 -07:00 • committed by GitHub
parent 3ec90ef6e6
commit 2d17904153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -128,16 +128,34 @@ export async function checkoutBranchAndCommit(
); );
if (pushRes instanceof Error) { if (pushRes instanceof Error) {
logger.info("Failed to push changes, attempting to pull and push again");
// attempt to git pull, then push again
await sandbox.git.pull(
absoluteRepoDir,
"git",
options.githubInstallationToken,
);
logger.info("Successfully pulled changes. Pushing again.");
const pushRes2 = await withRetry(
async () => {
return await sandbox.git.push(
absoluteRepoDir,
"git",
options.githubInstallationToken,
);
},
{ retries: 3, delay: 0 },
);
const gitStatus = await sandbox.git.status(absoluteRepoDir); const gitStatus = await sandbox.git.status(absoluteRepoDir);
const errorFields = { const errorFields = {
...(pushRes instanceof Error ...(pushRes2 instanceof Error
? { ? {
name: pushRes.name, name: pushRes2.name,
message: pushRes.message, message: pushRes2.message,
stack: pushRes.stack, stack: pushRes2.stack,
cause: pushRes.cause, cause: pushRes2.cause,
} }
: pushRes), : pushRes2),
}; };
logger.error("Failed to push changes", { logger.error("Failed to push changes", {
...errorFields, ...errorFields,