Skip to content

fix(ci): detach HEAD 释放本地分支名,避开 fork PR 同名冲突#464

Merged
appergb merged 2 commits into
betafrom
fix/claude-action-fork-detach
May 17, 2026
Merged

fix(ci): detach HEAD 释放本地分支名,避开 fork PR 同名冲突#464
appergb merged 2 commits into
betafrom
fix/claude-action-fork-detach

Conversation

@appergb
Copy link
Copy Markdown
Collaborator

@appergb appergb commented May 17, 2026

User description

背景

PR #451 (fork aeoform/openless, head ref 也叫 beta) 上有人 @claude,云端 review action 失败:

failed run: https://github.com/Open-Less/openless/actions/runs/25978532215

错误链:

PR #451 is from a fork, fetching via refs/pull/451/head...
fatal: refusing to fetch into branch 'refs/heads/beta' checked out at '/home/runner/work/openless/openless'
##[error]Action failed with error: Command failed: git fetch origin --depth=20 pull/451/head:beta

根因(三连命中才会触发)

  1. PR 来自 fork (isCrossRepository: true)
  2. fork 的 head 分支名也叫 beta —— 与本仓库 base / 默认分支同名
  3. actions/checkout@v4 默认把 worktree checkout 到了 refs/heads/beta

claude-code-action@v1 内部执行:

git fetch origin --depth=20 pull/451/head:beta

把 PR head 拉到本地同名分支 beta(命名取自 fork 端 head ref name)。但 beta 已是当前 checked-out 分支,git 拒绝 fetch 到已 checkout 的分支 → 失败。

修复

actions/checkout 之后立即 git checkout --detach,释放 refs/heads/<default-branch> 这个本地分支名,让 action 自己 fetch 不撞名。

仅对 fork head ref == base ref name 这个 corner case 有影响;其他场景(本仓库分支、fork 分支名不同)detach 都是无副作用的。

改动

  • .github/workflows/claude.yml: +11 行,单 step + 注释,无其他改动。

Test plan

  • 合入后在 PR feat(linux): fcitx5 plugin for Wayland input + deb packaging #451 上重新 @claude,确认 action run 成功,不再出现 refusing to fetch into branch 错误
  • 在本仓库分支的 PR / Issue 上 @claude,确认正常路径不退化
  • 若有第二个 fork PR head ref name 与 base 不同名,确认仍正常工作

PR Type

Bug fix


Description

  • Detach checkout before Claude action

  • Free default branch ref on forks

  • Prevent fetch collisions in CI


Diagram Walkthrough

flowchart LR
  A["actions/checkout"] -- "detach HEAD" --> B["Free local branch ref"]
  B -- "avoids ref collision" --> C["claude-code-action fetches PR head"]
  C -- "CI succeeds" --> D["Claude review workflow"]
Loading

File Walkthrough

Relevant files
Bug fix
claude.yml
Detach HEAD before Claude review step                                       

.github/workflows/claude.yml

  • Adds a git checkout --detach step after repository checkout.
  • Prevents claude-code-action from fetching into an already checked-out
    branch.
  • Documents the fork PR ref-name collision scenario in workflow
    comments.
+11/-0   

PR #451 (来自 fork aeoform/openless, head ref 也叫 beta) 触发 @claude 时,
claude-code-action 执行 `git fetch origin pull/451/head:beta` 把 PR head
拉到本地 beta 分支,但此时 worktree 正 checkout 在 refs/heads/beta,
git 拒绝 fetch 到已 checkout 的分支:

    fatal: refusing to fetch into branch 'refs/heads/beta' checked out at ...
    Action failed with error: Command failed: git fetch origin --depth=20 pull/451/head:beta

修复: 在 actions/checkout 后立即 git checkout --detach,释放
refs/heads/<default-branch> 这个本地分支名,让 action 自己 fetch 不撞名.
仅在 fork head ref == base ref name 的 corner case 才会触发问题,
detach 对其他场景无副作用.

失败 run: https://github.com/Open-Less/openless/actions/runs/25978532215
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 17, 2026

PR Reviewer Guide 🔍

(Review updated until commit 00cffb3)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 00cffb3

@appergb appergb merged commit fe56eb3 into beta May 17, 2026
4 checks passed
@appergb appergb deleted the fix/claude-action-fork-detach branch May 17, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant