Skip to content

fix: resolve claude-code-action PR branch fetch failures#1930

Merged
genedna merged 1 commit into
gitmono-dev:mainfrom
genedna:main
Feb 12, 2026
Merged

fix: resolve claude-code-action PR branch fetch failures#1930
genedna merged 1 commit into
gitmono-dev:mainfrom
genedna:main

Conversation

@genedna

@genedna genedna commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove the Setup PR Branch step that pre-created and checked out pr-N locally, which caused refusing to fetch into branch errors when claude-code-action tried to fetch into the same branch
  • Apply refs/pull/*/head refspec fix unconditionally for all event types, ensuring PR refs are discoverable under git protocol v2

Background

The claude-code-action internally runs git fetch origin pull/N/head:pr-N for all PR-related events. This fetch can fail in two ways:

  1. "couldn't find remote ref" — Under git protocol v2, refs/pull/* refs may not be discoverable if not in the configured fetch refspec
  2. "refusing to fetch into branch" — If a local branch pr-N already exists and is checked out, git refuses to fetch into it

The previous Setup PR Branch workaround caused issue 2. This PR removes it and addresses both issues by adding +refs/pull/*/head to the remote fetch refspec before the action runs.

Test plan

  • Verify on a fork PR triggered by pull_request_target
  • Verify on a same-repo PR triggered by issue_comment (@claude mention)

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings February 12, 2026 07:18
@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Claude finished @genedna's task in 1m 22s —— View job


Code Review Complete ✓

Tasks

  • Read and analyze the workflow file changes
  • Review the refspec fix implementation
  • Verify the solution addresses both stated issues
  • Check for security and correctness issues
  • Provide comprehensive feedback

Summary

This PR successfully addresses the PR branch fetch failures by taking a simpler and more correct approach than the previous workaround. The changes are well-reasoned and the implementation is sound.

Key Changes

Removed (23 lines):

  • The "Setup PR Branch" step that pre-created local pr-N branches
  • Conditional logic that only applied the refspec fix to certain event types

Added (9 lines):

  • Clearer, more comprehensive comment explaining both failure modes
  • Unconditional application of the refspec fix for all event types

Review by Focus Area

1. Code Quality ✓ Excellent

Strengths:

  • Simplification: Removes unnecessary complexity by eliminating the workaround branch creation
  • Comments: The new comment at lines 88-96 is exceptional - it clearly explains:
    • What the action does internally (git fetch origin pull/N/head:pr-N)
    • Both failure modes (refs not discoverable + refusing to fetch into branch)
    • The root cause (git protocol v2 behavior)
    • How the fix addresses each issue
  • Correctness: The solution addresses the root cause rather than working around symptoms

Why this is better than the previous approach:

2. Security ✓ No Issues

  • No security concerns introduced
  • The refspec +refs/pull/*/head:refs/remotes/origin/pull/*/head is standard and safe
  • Doesn't grant additional permissions or expose sensitive data
  • Still relies on the existing checkout step's security (verified SHA from lines 83-86)

3. Performance ✓ Improved

Benefits:

  • Removes unnecessary git checkout -b operation
  • Removes conditional checks on event type
  • Simpler execution path = faster workflow runs

No drawbacks:

  • The git config --add command is lightweight
  • No additional network operations

4. Testing ⚠️ Partially Complete

Test Plan Status:

  • ✅ Verified on fork PR triggered by pull_request_target
  • ⏳ Pending verification on same-repo PR with issue_comment (@claude mention)

Recommendation:
The second test case is important because:

  1. It's the event type that had the "Setup PR Branch" workaround before
  2. It exercises a different code path through the workflow (via resolve-pr-ref step)
  3. It's the most common way users interact with Claude in practice

Suggested test: Trigger this PR with an @claude mention in a comment to verify the fix works for issue_comment events.

5. Documentation ✓ Excellent

Specific Observations

.github/workflows/claude-review.yml:97-99

What changed:

- name: Configure git for PR ref access
-  if: |
-    github.event_name == 'pull_request_target' ||
-    github.event_name == 'pull_request_review_comment' ||
-    github.event_name == 'pull_request_review'
   run: |
     git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pull/*/head'

Why this is correct:

  • The conditional was incomplete anyway (missing issue_comment event type)
  • Running this unconditionally is harmless for non-PR events
  • Ensures consistency regardless of event type
  • Prevents future bugs if new event types are added

.github/workflows/claude-review.yml:88-96

Comment Quality:
The new comment is a model for how to document non-obvious fixes:

  1. States what command the external tool runs
  2. Explains each failure mode separately
  3. Links the failure to root cause (git protocol v2)
  4. Maps the solution to each problem

This level of documentation prevents future developers from "fixing" this again incorrectly.

Potential Issues

None identified

I carefully reviewed for:

  • Race conditions: None (refspec config happens before action runs)
  • Event type edge cases: Covered (unconditional application)
  • Permissions issues: None (only configures local git)
  • Merge conflicts with other PRs: None (isolated change)

Recommendations

  1. Complete the test plan - Test with @claude mention on this PR to verify the issue_comment path
  2. Consider documenting - If the claude-code-action has documentation about workflow setup, consider contributing this pattern back upstream
  3. Monitor for regressions - After merge, watch for any fetch failures in workflow runs

Conclusion

Verdict: Approve ✅

This PR represents a correct simplification that:

  • Removes unnecessary complexity
  • Addresses the root cause properly
  • Improves documentation
  • Has no downsides

The approach of "don't create local branches" is far superior to the previous "create them preemptively" workaround. The unconditional refspec configuration is the right choice.

One action item: Complete the second test case in the test plan before merging.


@genedna genedna merged commit 666c49d into gitmono-dev:main Feb 12, 2026
13 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes claude-code-action PR branch fetch failures in the claude-review GitHub Actions workflow by removing a conflicting local PR-branch checkout and ensuring PR refs are always discoverable under git protocol v2.

Changes:

  • Removed the Setup PR Branch step that created/checked out pr-N, which could cause “refusing to fetch into branch”.
  • Made the refs/pull/*/head refspec configuration unconditional so PR refs are discoverable for all supported event types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants