diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 9f31fe407..86197da96 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -151,10 +151,7 @@ export async function setupBranch( // Handle open PR: Checkout the PR branch console.log("This is an open PR, checking out PR branch..."); - const originalBranchName = prData.headRefName; - // Use unique local branch name to avoid conflicts with existing branches - // Format: pr-{number} ensures uniqueness since PR numbers are unique per repo - const localBranchName = `pr-${entityNumber}`; + const branchName = prData.headRefName; // Determine optimal fetch depth based on PR commit count, with a minimum of 20 const commitCount = prData.commits.totalCount; @@ -163,28 +160,16 @@ export async function setupBranch( console.log( `PR #${entityNumber}: ${commitCount} commits, using fetch depth ${fetchDepth}`, ); - console.log( - `Fetching PR branch '${originalBranchName}' as local branch '${localBranchName}'`, - ); // Validate branch names before use to prevent command injection - validateBranchName(localBranchName); + validateBranchName(branchName); // Execute git commands to checkout PR branch (dynamic depth based on PR size) // Using execFileSync instead of shell template literals for security - // Use GitHub's PR ref which works for both same-repo and fork PRs - // The local branch name uses pr-{number} format to ensure uniqueness - execGit([ - "fetch", - "origin", - `--depth=${fetchDepth}`, - `pull/${entityNumber}/head:${localBranchName}`, - ]); - execGit(["checkout", localBranchName, "--"]); + execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]); + execGit(["checkout", branchName, "--"]); - console.log( - `Successfully checked out PR #${entityNumber} as local branch '${localBranchName}'`, - ); + console.log(`Successfully checked out PR branch for PR #${entityNumber}`); // For open PRs, we need to get the base branch of the PR const baseBranch = prData.baseRefName; @@ -192,7 +177,7 @@ export async function setupBranch( return { baseBranch, - currentBranch: localBranchName, + currentBranch: branchName, }; } }