From b12957001c698efa738e4a257f9f04d465e2e5ea Mon Sep 17 00:00:00 2001 From: Cole Davis Date: Tue, 16 Sep 2025 21:46:32 -0400 Subject: [PATCH] Fall back to default on duplicate branch --- src/github/operations/branch.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index fc3f5b7..565bcff 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -117,7 +117,7 @@ export async function setupBranch( const title = githubData.contextData.title; // Generate branch name using template or default format - const newBranch = generateBranchName( + let newBranch = generateBranchName( branchNameTemplate, branchPrefix, entityType, @@ -127,6 +127,27 @@ export async function setupBranch( title, ); + // Check if generated branch already exists on remote + try { + await $`git ls-remote --exit-code origin refs/heads/${newBranch}`.quiet(); + + // If we get here, branch exists (exit code 0) + console.log( + `Branch '${newBranch}' already exists, falling back to default format`, + ); + newBranch = generateBranchName( + undefined, // Force default template + branchPrefix, + entityType, + entityNumber, + sourceSHA, + firstLabel, + title, + ); + } catch { + // Branch doesn't exist (non-zero exit code), continue with generated name + } + // For commit signing, defer branch creation to the file ops server if (context.inputs.useCommitSigning) { console.log(