Skip to content

fix(core): fetch origin/<defaultBranch> before creating task worktrees (ARC-108)#1

Merged
loop2zero merged 1 commit into
feat/linear-control-plane-relayfrom
task/176c7be3-dispatcher-开-worktree-前先-fetch
Jun 11, 2026

Hidden character warning

The head ref may contain hidden characters: "task/176c7be3-dispatcher-\u5f00-worktree-\u524d\u5148-fetch"
Merged

fix(core): fetch origin/<defaultBranch> before creating task worktrees (ARC-108)#1
loop2zero merged 1 commit into
feat/linear-control-plane-relayfrom
task/176c7be3-dispatcher-开-worktree-前先-fetch

Conversation

@loop2zero

Copy link
Copy Markdown
Owner

问题

devlog watch 的 dispatcher 为新任务开 worktree 时基于本地 defaultBranch 切分支,从不 git fetch。链式子任务每合并一环,远端就前进一次,下一环必然基于陈旧基底 → PR 必冲突(实测 ARC-104 PR moose-lab#10、ARC-105 PR moose-lab#11)。

修复

全部收在 src/core/worktree-manager.ts,createWorktree 公共签名不变,task-execution.ts 零改动:

  • resolveWorktreeBase(repoRoot, baseBranch):git fetch origin <baseBranch> + rev-parse --verify origin/<baseBranch>,成功返回 origin/<baseBranch>;失败(离线/无 remote)打 warn 降级返回本地分支,不阻塞派发。
  • createWorktreeAt(repoRoot, …):repo-root 级创建核心,抽出以便单测注入临时 repo(getRepoRoot 依赖 cwd 配置,无法在测试中注入)。
  • createWorktree 委托给上述两者。

测试(TDD,先红后绿)

src/core/__tests__/worktree-manager.test.ts(node:test + tsx),夹具为 bare remote + 双 clone(writer 推进远端、local 保持陈旧):

  • 有远端:新 worktree HEAD == origin/<defaultBranch> 远端 tip(前置断言本地确实陈旧)
  • 无远端:fetch 失败仍创建成功,基底为本地 tip(降级路径)
  • resolveWorktreeBase 两条路径各自单测

验证

  • bun run typecheck
  • TZ=Asia/Shanghai bun run test → 350 pass / 0 fail ✅

关联:ARC-108(发现于 ARC-102 链;relay 主体 ARC-107)

🤖 Generated with Claude Code

Chained subtasks merge remotely while the local default branch never
advances, so each new worktree was cut from a stale base and every PR in
the chain conflicted (ARC-104 PR moose-lab#10, ARC-105 PR moose-lab#11).

createWorktree now fetches origin/<baseBranch> and bases the new branch
on the remote tip via resolveWorktreeBase; when the fetch fails (offline
or no remote) it logs a warning and degrades to the local branch so
dispatch is never blocked. createWorktreeAt is the repo-root-level core,
extracted so tests can run against a temp repo with a local bare remote.

ARC-108

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@loop2zero
loop2zero merged commit 2d6c759 into feat/linear-control-plane-relay Jun 11, 2026
@loop2zero
loop2zero deleted the task/176c7be3-dispatcher-开-worktree-前先-fetch branch June 11, 2026 01:35
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.

1 participant