From 9f77e41ed20773c3c8f95176a0a8839c74926b69 Mon Sep 17 00:00:00 2001 From: baiqing Date: Sun, 17 May 2026 10:38:24 +0800 Subject: [PATCH] fix(ci): detach HEAD before claude-code-action on fork PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/ 这个本地分支名,让 action 自己 fetch 不撞名. 仅在 fork head ref == base ref name 的 corner case 才会触发问题, detach 对其他场景无副作用. 失败 run: https://github.com/Open-Less/openless/actions/runs/25978532215 --- .github/workflows/claude.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index b60f6035..68fb5103 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -39,6 +39,17 @@ jobs: with: fetch-depth: 1 + # Detach HEAD 释放 refs/heads/ 这个本地分支名。 + # 背景:claude-code-action 在 fork PR 上会执行 + # git fetch origin pull//head: + # 把 PR head 拉到与 fork 端 head 同名的本地分支。当 fork PR 的 head ref + # 与本仓库 base / 默认分支同名(例如 fork 也是 beta → beta)时, + # 上面那条 fetch 会撞上"当前已 checkout 的分支"而失败: + # fatal: refusing to fetch into branch 'refs/heads/beta' checked out at ... + # 提前 detach 让本地分支名可以被 action 重新使用。 + - name: Detach HEAD to free local branch ref + run: git checkout --detach + - name: Pick model (default sonnet, opt-in opus) id: pick_model env: