fix(Diff): 新增/删除/重命名文件在 Commit 与 Graph 视图可正常打开差异;#87
Merged
Conversation
缺失端(新增文件无旧端、删除文件无新端)改用 git 空树 ref 构造 URI,跨 VS Code 版本稳定解析为空内容,修复新版 readFile 对不存在具名 ref 抛 FileNotFound 致差异打不开。按状态正交分解:新增空树置旧端、删除空树置新端、重命名两端异路径;补齐 Graph 视图逐文件 status/oldPath 传参与干净路径,修复重命名点击崩溃;新增分类器与端点解析的单元/集成测试,并记录 issue #15。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Commit 视图与 Graph 视图中点击新增文件无法打开差异(预期应展示「全绿新增」对比);删除、重命名文件同样失败;Graph 视图重命名文件点击更是彻底无效。
根因(循证,源自 VS Code 官方源码对比)
两处「打开差异」都为差异的缺失端构造了指向不存在对象的 git URI:
src/adapter/commands.ts的openDiff:toGitUri(change.uri, 'HEAD')—— 新增文件在 HEAD 不存在src/adapter/history-commands.ts的openCommitFileDiff:toGitUri(uri,${hash}^)—— 新增文件在父提交不存在;删除文件右端toGitUri(uri, hash)亦不存在VS Code git
FileSystemProvider.readFile行为随版本演进:1.85(engines.vscode下限)catch吞错返空(容错),当前主线改为对不存在对象抛FileNotFound、仅当ref === repository.getEmptyTree()(空树)时才回空。故'HEAD'/${hash}^这类具名 ref 在新版必崩,旧版仅侥幸可用 —— 与「用户实际运行较新 VS Code」的现象吻合。修法(复用 VS Code 官方现行做法)
缺失端统一改用 git 空树 ref(
4b825dc642cb6eb9a060e54bf8d69288fbee4904),旧版容错、新版空树逃逸,两版皆稳定解析为空内容。按变更状态正交分解端点选择:oldPath@父newPath@本提交改动文件
src/engine/diff/change-side.ts:纯状态分类器(diffShapeFromStatus/diffShapeFromCode→added/deleted/renamed/modified),零 vscode 依赖、可单测src/adapter/diff-sides.ts:GIT_EMPTY_TREE常量 +resolveDiffSides(按形态把缺失端置空树)src/adapter/commands.ts:openDiff按状态选端 + 补try/catch(签名不变,菜单/程序调用皆兼容)src/adapter/history-commands.ts:openCommitFileDiff新签名(hash, filePath, status?, oldPath?),移除hasParent分支src/shared/protocol.ts+src/adapter/webview/log-webview.ts:透传逐文件status/oldPath、path改回干净新路径附带修复
detailLeafHtml的data-path复用展示串"old → new",joinPath得伪路径 → 数据与展示分离修复hasParent,宿主无法区分 A/D/M/R → 由status取代openDiff无try/catch→ 补错误提示验证(全绿)
pnpm run lint✓ ·tsc --noEmit✓关联
🤖 Generated with Claude Code, CodeX, Gemini
Co-Authored-By: Aurelius Huangthreefish.ai@gmail.com