Skip to content

fix: skip core.symlinks=true on Windows to avoid false type-change di…#905

Merged
yqmaphy merged 1 commit into
devfrom
fix/windows-vcs-git-info
May 28, 2026
Merged

fix: skip core.symlinks=true on Windows to avoid false type-change di…#905
yqmaphy merged 1 commit into
devfrom
fix/windows-vcs-git-info

Conversation

@code-JDS
Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes None

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Fixes false uncommitted changes shown in VCS panel on Windows git worktrees
  • The core.symlinks=true config caused git status to report symlink files as type-changed on Windows
  • Solution: conditionally set core.symlinks=true only on non-Windows platforms

How did you verify your code works?

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@code-JDS
Copy link
Copy Markdown
Collaborator Author

/oc review

@github-actions
Copy link
Copy Markdown
Contributor

PR #905 审查

一、变更梳理

本 PR 仅修改一个文件 packages/opencode/src/git/index.ts,具体变更如下:

  1. 条件化 core.symlinks=true 配置:将 cfg 数组中无条件硬编码的 "-c", "core.symlinks=true" 替换为条件展开 ...(process.platform !== "win32" ? ["-c", "core.symlinks=true"] : [])。在 Windows(process.platform === "win32")上不再传入该配置项,在非 Windows 平台上行为不变。

  2. 移除 as const 类型断言cfg 数组从 ] as const 变为 ]。因条件展开使数组类型无法保持为字面量 readonly tuple,as const 不可再适用,遂移除。

实际效果:Windows 用户在使用 git worktree 时,VCS 面板不再因 core.symlinks=true 被强制覆盖而出现虚假的 "type-changed" 未提交变更。git 在 Windows 上默认 core.symlinks=false,与 NTFS 实际的符号链接支持能力一致,不再产生误报。非 Windows(含 WSL,其 process.platform"linux")行为完全不变。

二、合理性与有效性

  • 修复方向正确:Windows NTFS 在默认配置下不支持真正的符号链接,强制 core.symlinks=true 使 git 认为文件系统支持符号链接,从而将仓库中的符号链接条目标记为类型变更。移除该强制配置让 git 回归默认值,符合 Windows 实际文件系统行为。
  • 条件判断准确:使用 process.platform !== "win32" 而非检测 git 版本或文件系统能力,简单可靠。WSL 下 process.platform"linux",不会误判。
  • 移除 as const 是必要的附带变更:条件展开使数组元素类型变为 string,无法维持 readonly tuple 字面量类型。下游 cfg 仅以 [...cfg, ...args] 形式传入 ChildProcess.make,其中 args 已为 string[],展开结果始终为 string[],移除 as const 不影响类型安全。

三、潜在影响与系统性评述

遗漏的同类问题packages/opencode/src/snapshot/index.ts 中也存在无条件使用 core.symlinks=true 的相同模式——第 39 行的 const core = ["-c", "core.longpaths=true", "-c", "core.symlinks=true"] 以及第 236 行的 git(["config", "core.symlinks", "true"]) 持久化配置。snapshot 模块使用独立的 bare git 仓库追踪工作目录快照,在 Windows 上同样可能遭遇 diff-filesls-files 的类型变更误判,影响快照的 addtrack 操作准确性。本 PR 只修复了 VCS 面板所在的 git/index.ts,未覆盖 snapshot 模块中的同类根因。严重程度:Medium——功能性问题,影响 Windows 用户快照追踪的可靠性,但不像 VCS 误报那样直接可见。

.db 文件的审查:本变更不涉及数据库模式、迁移、持久化逻辑、存储路径或读写行为的任何改动。无影响。

对自动更新的审查:本变更不涉及更新检测、下载、安装、重启、版本比较、发布渠道、回滚行为或故障处理。无影响。

类型宽化的极低风险:移除 as const 使 cfg 从 readonly literal tuple 变为 string[],丧失了编译期对配置项拼写错误的保护。但在实际使用中,cfg 是模块内部的私有常量,拼写错误在首次运行时即会暴露(git 命令失败),且当前值经过长期使用验证,风险极低。严重程度:Low

系统性评述:修复精准、侵入极小,仅改动了必要的两处(条件展开 + 移除 as const),无多余变更。但修复范围不完整——同根因在 snapshot 模块中未同步处理,存在系统性遗漏。建议将条件判断抽取为共享的配置生成函数,或在 snapshot 模块中同步应用相同的平台条件化逻辑,以确保一致性。

@yqmaphy yqmaphy merged commit 4bd4c7f into dev May 28, 2026
18 checks passed
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