Skip to content

fix: 修复 git-diff-service 硬编码路径分隔符导致 Windows 预览空白的问题#422

Merged
ErlichLiu merged 1 commit into
ErlichLiu:mainfrom
Andreaseszhang:fix/windows-path-separator-in-diff-preview
May 12, 2026
Merged

fix: 修复 git-diff-service 硬编码路径分隔符导致 Windows 预览空白的问题#422
ErlichLiu merged 1 commit into
ErlichLiu:mainfrom
Andreaseszhang:fix/windows-path-separator-in-diff-preview

Conversation

@Andreaseszhang
Copy link
Copy Markdown
Contributor

Overview

修复 git-diff-service.ts 中因硬编码 / 路径分隔符导致的 Windows 兼容性问题。在 Windows 上,realpathSyncpath.join 返回 \ 分隔的路径,而 normalizeSafePathcomputeSource 使用硬编码 /startsWith 前缀匹配,导致所有路径被判定为"不安全"而拒绝,git diff 预览功能在 Windows 上完全失效。

Changes

  • apps/electron/src/main/lib/git-diff-service.ts
    • normalizeSafePathrootWithSep 改用 sep 拼接,确保与 realpathSync 返回的分隔符一致
    • computeSourcesessionPath/workspaceFilesPath 前缀改用 sep,确保与 join() 结果的分隔符一致
    • candidateRoots — 正则改为 [/\\\\]+$ 兼容两种分隔符,拼接改用 sep
    • gitRootNamessplit('/').pop() 改为 basename(),跨平台正确提取仓库名

Impact

  • macOS/Linux:零影响(sep === '/',行为不变)
  • Windows:修复 git diff 预览、文件来源标识、候选目录过滤三项功能

How to Test

  1. Windows 环境启动 Proma
  2. 在 Agent 模式下修改任意项目文件
  3. 点击文件行,确认预览面板正常显示 diff 内容(不再空白)
  4. 确认文件来源标识(session/workspace 标签)显示正确
  5. macOS/Linux 回归:确认 diff 预览功能无变化

🤖 Generated with Claude Code

…lity in git-diff-service

normalizeSafePath、computeSource 和 candidateRoots 中使用硬编码 `/`
拼接路径分隔符,导致 Windows 上 realpathSync 返回的 `\` 路径无法通过
startsWith 前缀匹配,所有 git diff 预览均返回空内容。

- normalizeSafePath: rootWithSep 改用 sep 拼接
- computeSource: sessionPath/workspaceFilesPath 前缀改用 sep
- candidateRoots: 正则兼容两种分隔符,拼接改用 sep
- gitRootNames: split('/').pop() 改为 basename() 跨平台取仓库名

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Andreaseszhang Andreaseszhang changed the title fix: replace hardcoded with for Windows path compatibility fix: 修复 git-diff-service 硬编码路径分隔符导致 Windows 预览空白的问题 May 12, 2026
@ErlichLiu ErlichLiu merged commit 89ca15e into ErlichLiu:main May 12, 2026
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