fix(git): open commit diffs from subdirectory workspaces (#6801)

* fix(git): resolve commit file diffs from the worktree root

* test(git): cover commit diffs from nested workspaces through daemon RPC
This commit is contained in:
Elowen
2026-10-13 15:52:54 +02:00
committed by GitHub
parent 4400445edb
commit 5805b776c2
2 changed files with 67 additions and 5 deletions
+5 -4
View File
@@ -2665,10 +2665,11 @@ export async function getCommitFileDiff({
sha: string;
path: string;
}): Promise<ParsedDiffFile | null> {
const worktreeRoot = await requireGitWorktreeRoot(cwd);
const { stdout } = await runGitCommand(
["show", sha, "--format=", "--diff-merges=first-parent", ...GIT_PATCH_FORMAT_ARGS, "--", path],
{
cwd,
cwd: worktreeRoot,
envOverlay: READ_ONLY_GIT_ENV,
},
);
@@ -2677,9 +2678,9 @@ export async function getCommitFileDiff({
return null;
}
const parsedFiles = await parseAndHighlightDiff(stdout, cwd, {
getOldFileContent: (file) => readGitFileContentAtRef(cwd, `${sha}^`, file.path),
getNewFileContent: (file) => readGitFileContentAtRef(cwd, sha, file.path),
const parsedFiles = await parseAndHighlightDiff(stdout, worktreeRoot, {
getOldFileContent: (file) => readGitFileContentAtRef(worktreeRoot, `${sha}^`, file.path),
getNewFileContent: (file) => readGitFileContentAtRef(worktreeRoot, sha, file.path),
});
// `--` scopes the diff to a single pathspec, so there is at most one real