-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Describe the bug
PR #851 introduced a bug where PR checkout fails if the PR branch name conflicts with existing branches in the base repository.
The new checkout strategy git fetch origin pull/${number}/head:${branchName} attempts to create a local branch with the PR's branch name, which fails when that branch name already exists locally or remotely in the base repo.
To Reproduce
Steps to reproduce the behavior:
- Create a branch named
feature/my-featurein your base repository - Create a PR (from same repo or fork) using the same branch name
feature/my-feature - Trigger the claude-code-action workflow on that PR
- See error:
git fetch origin --depth=20 pull/123/head:feature/my-feature
fatal: refusing to update ref with bad name 'feature/my-feature'Expected behavior
The workflow should successfully checkout the PR regardless of branch name conflicts. The PR should be fetched and checked out to a local branch without naming collisions.
Screenshots
N/A
Workflow yml file
N/A
API Provider
[x] Anthropic First-Party API (default)
[ ] AWS Bedrock
[ ] GCP Vertex
Additional context
Background:
PR #851 was introduced to support fork PRs, which is a valuable improvement for organizations like PyTorch where 90%+ PRs come from forks.
Before #851:
- Used
git fetch origin <branch-name>- only works for same-repo PRs - Fork PR branches don't exist in the base repo's origin, causing fetch failures
After #851:
- Uses GitHub's
refs/pull/NUMBER/headwhich exists for all PRs (both same-repo and fork) - Successfully enables fork PR support
Root cause:
The new implementation uses git fetch origin pull/${number}/head:${branchName}, where :${branchName} creates a local branch with the PR's original branch name. This avoids detached HEAD state but introduces naming collisions when:
- A local branch with the same name already exists
- The workflow is currently checked out to that branch
- The base repo has a remote branch with the same name
The issue is a trade-off: while #851 solved the fork PR problem, it created a new branch naming conflict problem.