fix(ci): detach HEAD before claude-code-action on fork PR (#464)
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 Co-authored-by: baiqing <lbx12309@icloud.com>
This commit is contained in:
1 parent
5d050d6121
commit
fe56eb3038
1 file changed
+11
@@ -39,6 +39,17 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
# Detach HEAD 释放 refs/heads/<default-branch> 这个本地分支名。
|
||||
# 背景:claude-code-action 在 fork PR 上会执行
|
||||
# git fetch origin pull/<n>/head:<head-ref-name>
|
||||
# 把 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:
|
||||
|
||||
Reference in new issue
Block a user