Skip to content

Commit ec01d8a

Browse files
genednaclaude
andcommitted
fix: remove Setup PR Branch and apply refspec fix unconditionally
The claude-code-action fetches the PR branch for ALL event types including issue_comment. The Setup PR Branch step created and checked out pr-N locally, causing "refusing to fetch into branch" when the action tried to fetch into the same branch. Remove the step entirely and apply the refs/pull/*/head refspec fix unconditionally so the action's own fetch succeeds for all events. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Quanyi Ma <eli@patch.sh>
1 parent 4fd0c1f commit ec01d8a

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

.github/workflows/claude-review.yml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,16 @@ jobs:
8585
ref: ${{ steps.resolve-pr-ref.outputs.pr_sha || github.event.pull_request.head.sha || github.sha }}
8686
fetch-depth: 20
8787

88-
# Manually setup PR branch to workaround Claude Action issue with forks
89-
# For issue_comment events, the action does not attempt to fetch the PR branch,
90-
# so we create it locally from the current HEAD (secure, verified SHA)
91-
- name: Setup PR Branch
92-
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
93-
env:
94-
PR_NUMBER: ${{ github.event.issue.number }}
95-
run: |
96-
echo "Setting up local PR branch pr-$PR_NUMBER..."
97-
git checkout -b pr-$PR_NUMBER
98-
99-
# Fix git protocol for PR ref access
100-
# actions/checkout@v6 creates a shallow clone with only refs/heads/* in the fetch
101-
# refspec. The claude-code-action internally runs:
102-
# git fetch origin pull/N/head:pr-N
103-
# Under git protocol v2 (default since git 2.26), the client sends ref-prefix
104-
# filters to the server. Since refs/pull/* is not in the configured fetch refspec,
105-
# the server may not return refs/pull/N/head, causing "couldn't find remote ref".
106-
# Adding refs/pull/*/head to the fetch refspec ensures these refs are discoverable.
88+
# Fix git ref access for claude-code-action PR branch checkout
89+
# The action internally runs: git fetch origin pull/N/head:pr-N
90+
# This can fail for two reasons:
91+
# 1. Under git protocol v2, refs/pull/* may not be discoverable if not in
92+
# the configured fetch refspec (causes "couldn't find remote ref")
93+
# 2. If a local branch pr-N already exists and is checked out, git refuses
94+
# to fetch into it (causes "refusing to fetch into branch")
95+
# Adding refs/pull/*/head to the fetch refspec solves issue 1, and we avoid
96+
# creating local branches to prevent issue 2.
10797
- name: Configure git for PR ref access
108-
if: |
109-
github.event_name == 'pull_request_target' ||
110-
github.event_name == 'pull_request_review_comment' ||
111-
github.event_name == 'pull_request_review'
11298
run: |
11399
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pull/*/head'
114100

0 commit comments

Comments
 (0)