Skip to content

fix(windows): align local branch checkout and deletion refs - #101

Merged
1lck merged 3 commits into
1lck:preview/0.3.0from
yangboxuan726:fix/windows-git-checkout-contract
Aug 16, 2026
Merged

fix(windows): align local branch checkout and deletion refs#101
1lck merged 3 commits into
1lck:preview/0.3.0from
yangboxuan726:fix/windows-git-checkout-contract

Conversation

@yangboxuan726

Copy link
Copy Markdown
Contributor

问题

Windows 分支切换和删除调用链存在三处契约错位,导致两个操作都会被共享 Core 拒绝:

  1. git_checkout / git_delete_branch 翻译层只传短分支名,而 Core 的 local_branch_name() 要求完整引用 refs/heads/<branch>
  2. git_checkout 缺少 referenceKind,Core 的 switch_reference() 对缺省值直接返回 invalid_request
  3. core-result-adapter 没有 git_checkout 适配分支,前端拿到的原始 {output, exitCode} 缺少 success / hasChanges,成功切换也不会触发状态刷新。

修复

  • platform.rs:新增 local_branch_reference() 统一补全 refs/heads/ 前缀(仅对已是 refs/heads/ 开头的值透传);git_checkoutreferenceKind: "local";新增 git_checkout_preflightgit.checkoutPreflight 翻译;git_delete_branch 走同样的限定引用
  • core-result-adapter.ts:补 git_checkout(exitCode/output → success/message)与 git_checkout_preflight(blockingPaths)适配
  • git-branches-api.ts:切换前先跑 preflight,阻塞时返回 hasChanges: true 复用现有 Stash Changes 重试流程;失败信息透传 git 真实输出

UI 组件、Rust Core、macOS 实现均未改动。

验证

  • cargo test(src-tauri):13/13 通过(新增 checkout / preflight / deleteBranch 翻译测试及 helper 边界测试)
  • bun test:14/14 通过(新增 5 个 adapter 适配测试)
  • tsc --noEmit:通过
  • 未验证:真机 UI 手工场景(Stash 重试、错误提示展示),依赖 reviewer 环境确认

后续

  • checkoutBranch catch 路径的 API 层错误传播测试计划随下一个 PR 补充(需要 invoke 模块 mock)
  • scripts/verify-windows-boundaries.sh 在 Windows 存在基线既有的路径分隔符误报(白名单正则用 /,rg 输出 \),与本 PR 无关,可单独修复

- qualify git_checkout, git_checkout_preflight, and git_delete_branch
  references with refs/heads/ and pass referenceKind: local, matching the
  shared core contract that rejects short branch names
- translate git_checkout_preflight to git.checkoutPreflight and adapt its
  blocking paths plus git_checkout results for the branch manager UI
- run checkout preflight from checkoutBranch so blocked switches surface
  hasChanges and reuse the existing stash-and-retry flow, and propagate
  real git error output on failure
@1lck
1lck merged commit 0a7baf9 into 1lck:preview/0.3.0 Aug 16, 2026
8 of 11 checks passed
@yangboxuan726
yangboxuan726 deleted the fix/windows-git-checkout-contract branch August 16, 2026 13:18
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.

2 participants