Skip to content

Bug: Fork PRs fail with "couldn't find remote ref" - branch.ts doesn't use refs/pull/*/head #821

@paddo

Description

@paddo

Bug: Fork PRs fail with "couldn't find remote ref" - branch.ts doesn't use refs/pull/*/head

Description

The action fails on PRs from forks with:

Prepare step failed with error: Command failed: git fetch origin --depth=20 <branch-name>
fatal: couldn't find remote ref <branch-name>

This affects both pull_request_target and issue_comment triggers.

Root Cause

In src/github/operations/branch.ts, the action fetches branches by name from origin:

const branchName = prData.headRefName;
execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]);

For fork PRs, the branch doesn't exist on origin — it exists in the fork's repo. The code should use GitHub's PR refs instead:

// For fork PRs, use PR ref instead of branch name
const ref = isFork ? `refs/pull/${prNumber}/head` : branchName;
execGit(["fetch", "origin", `--depth=${fetchDepth}`, ref]);

Related Issues

Environment

  • Action version: v1 (v1.0.29)
  • Trigger: issue_comment on a PR from a fork
  • Workflow correctly checks out the PR via gh pr checkout before the action runs, but the action's internal fetch still fails

Expected Behavior

Fork PRs should work the same as same-repo PRs. The action should detect fork PRs and use refs/pull/{number}/head for fetching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existsp1Showstopper bug preventing substantial subset of users from using the product, or incorrect docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions