revert: undo PR checkout fork support and unique branch naming (#937)
Reverts the following commits: - f669191 fix: use unique local branch names for PR checkout to avoid conflicts (#931) - 21e3fe0 Fix PR checkout to support fork PRs (#851) Simplifies PR branch checkout back to using headRefName directly instead of the pr-{number} local branch naming scheme introduced in #931 and the GitHub pull ref fetch approach introduced in #851. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f669191d7d
commit
26a64887f3
@ -151,10 +151,7 @@ export async function setupBranch(
|
|||||||
// Handle open PR: Checkout the PR branch
|
// Handle open PR: Checkout the PR branch
|
||||||
console.log("This is an open PR, checking out PR branch...");
|
console.log("This is an open PR, checking out PR branch...");
|
||||||
|
|
||||||
const originalBranchName = prData.headRefName;
|
const branchName = 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}`;
|
|
||||||
|
|
||||||
// Determine optimal fetch depth based on PR commit count, with a minimum of 20
|
// Determine optimal fetch depth based on PR commit count, with a minimum of 20
|
||||||
const commitCount = prData.commits.totalCount;
|
const commitCount = prData.commits.totalCount;
|
||||||
@ -163,28 +160,16 @@ export async function setupBranch(
|
|||||||
console.log(
|
console.log(
|
||||||
`PR #${entityNumber}: ${commitCount} commits, using fetch depth ${fetchDepth}`,
|
`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
|
// 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)
|
// Execute git commands to checkout PR branch (dynamic depth based on PR size)
|
||||||
// Using execFileSync instead of shell template literals for security
|
// Using execFileSync instead of shell template literals for security
|
||||||
// Use GitHub's PR ref which works for both same-repo and fork PRs
|
execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]);
|
||||||
// The local branch name uses pr-{number} format to ensure uniqueness
|
execGit(["checkout", branchName, "--"]);
|
||||||
execGit([
|
|
||||||
"fetch",
|
|
||||||
"origin",
|
|
||||||
`--depth=${fetchDepth}`,
|
|
||||||
`pull/${entityNumber}/head:${localBranchName}`,
|
|
||||||
]);
|
|
||||||
execGit(["checkout", localBranchName, "--"]);
|
|
||||||
|
|
||||||
console.log(
|
console.log(`Successfully checked out PR branch for PR #${entityNumber}`);
|
||||||
`Successfully checked out PR #${entityNumber} as local branch '${localBranchName}'`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// For open PRs, we need to get the base branch of the PR
|
// For open PRs, we need to get the base branch of the PR
|
||||||
const baseBranch = prData.baseRefName;
|
const baseBranch = prData.baseRefName;
|
||||||
@ -192,7 +177,7 @@ export async function setupBranch(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
baseBranch,
|
baseBranch,
|
||||||
currentBranch: localBranchName,
|
currentBranch: branchName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user