From 76fec90f845e5e3e931130059764fc492092e726 Mon Sep 17 00:00:00 2001 From: Adam Bowker Date: Thu, 2 Apr 2026 08:48:04 -0700 Subject: [PATCH] fix(code): skip branch creation on PR saga retry --- .../src/main/services/git/create-pr-saga.ts | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/code/src/main/services/git/create-pr-saga.ts b/apps/code/src/main/services/git/create-pr-saga.ts index 62bc059fd..5887619ea 100644 --- a/apps/code/src/main/services/git/create-pr-saga.ts +++ b/apps/code/src/main/services/git/create-pr-saga.ts @@ -66,25 +66,28 @@ export class CreatePrSaga extends Saga { let { commitMessage, prTitle, prBody } = input; if (input.branchName) { - this.deps.onProgress( - "creating-branch", - `Creating branch ${input.branchName}...`, + const currentBranch = await this.readOnlyStep("get-original-branch", () => + this.deps.getCurrentBranch(directoryPath), ); - const originalBranch = await this.readOnlyStep( - "get-original-branch", - () => this.deps.getCurrentBranch(directoryPath), - ); + // on retry, do not attempt to re-create the branch + if (currentBranch !== input.branchName) { + this.deps.onProgress( + "creating-branch", + `Creating branch ${input.branchName}...`, + ); - await this.step({ - name: "creating-branch", - execute: () => this.deps.createBranch(directoryPath, input.branchName!), - rollback: async () => { - if (originalBranch) { - await this.deps.checkoutBranch(directoryPath, originalBranch); - } - }, - }); + await this.step({ + name: "creating-branch", + execute: () => + this.deps.createBranch(directoryPath, input.branchName!), + rollback: async () => { + if (currentBranch) { + await this.deps.checkoutBranch(directoryPath, currentBranch); + } + }, + }); + } } const changedFiles = await this.readOnlyStep("check-changes", () =>