fix(host-service): pin diff prefixes so user git config cannot break the Changes pane
Fixes #7596
What was broken
With diff.mnemonicPrefix = true (or diff.noprefix = true) in the user's gitconfig, every file under Staged and Unstaged shows "Unable to load diff". The sidebar counts are right, and Against base and Commits still work, which made this hard to diagnose.
The pane parses patch text and expects diff --git a/... b/... headers, but git builds those prefixes from user config. Mnemonic prefixes turn them into i/ and w/ (unstaged), c/ and i/ (staged), and 1/ and 2/ (untracked via --no-index). diff.noprefix strips them everywhere, which would break Against base and Commits too. Comparing two commits is the one case where mnemonic prefixes happen to match a/ and b/, which is exactly why those two sections kept working.
The fix
Pin the four prefix settings at the invocation instead of teaching the parser every user's config. All five git diff argv builders in diff-patch.ts now start with:
-c diff.mnemonicPrefix=false -c diff.noprefix=false -c diff.srcPrefix=a/ -c diff.dstPrefix=b/
I used -c rather than --default-prefix on purpose: --default-prefix needs git 2.45 and is a hard error below that, while unknown -c keys are silently ignored by every git version, so this has no version floor.
Tests
Three new tests in diff-patch.test.ts against real git repos: with diff.mnemonicPrefix, with diff.noprefix, and with custom srcPrefix/dstPrefix, the unstaged, staged, and untracked patches must all keep a/ and b/ headers. All three fail on main.
Out of scope
The issue also notes that the Retry button on the placeholder never refetches, and a possible quoting mismatch for non-ASCII filenames. Both are renderer concerns and worth their own issues; this PR fixes the reason the placeholder appears in the first place.
Summary by cubic
Fixes the Changes pane rendering "Unable to load diff" when user git config sets diff.mnemonicPrefix, diff.noprefix, or custom srcPrefix/dstPrefix, by pinning the prefix settings at every git diff invocation.
- Pins
diff.mnemonicPrefix,diff.noprefix,diff.srcPrefix, anddiff.dstPrefixwith-cflags in all five diff argument builders indiff-patch.ts. - Uses
-cinstead of--default-prefixso there's no git version floor; unknown-ckeys are ignored by older git. - Adds three tests covering mnemonic prefixes,
noprefix, and custom prefixes, all of which fail on main.
Out of scope
- The Retry button never refetches and a possible non-ASCII filename quoting mismatch remain open as renderer concerns.
Summary by CodeRabbit
- Bug Fixes
- Fixed diff rendering when Git path-prefix settings are customized.
- Ensured staged, unstaged, and untracked file diffs consistently display with recognizable
a/andb/headers instead of appearing as unavailable.