Repository navigation
Description
Where did this happen?
Desktop app (macOS)
Version
1.29.0
What happened?
With diff.mnemonicPrefix = true in my git config, every file in the Staged and Unstaged sections renders the Unable to load diff placeholder. The sidebar lists the files correctly with accurate +/- counts. Against base and Commits render fine, which is what made this confusing to diagnose.
The Changes pane parses patch text with a regex that hardcodes git's a//b/ prefixes, but git diff only emits those for some comparisons. DevTools console:
useDiffCodeViewItems.ts:256 parsePatchContent: invalid git diff header diff --git i/path/to/file.sh w/path/to/file.sh
at useDiffCodeViewItems (useDiffCodeViewItems.ts:243)
at DiffPane (DiffPane.tsx:228)
The regex is in the bundled parser, @pierre/diffs@1.4.2:
// package/dist/constants.js:18
const ALTERNATE_FILE_NAMES_GIT = /^diff --git (?:"a\/(.+?)"|a\/(.+?)) (?:"b\/(.+?)"|b\/(.+?))$/;When it fails, the file gets no section in the parsed patch and useDiffCodeViewItems falls through to reason: "error".
BASE_ARGS in packages/host-service/src/trpc/router/git/utils/diff-patch.ts is ["--no-color", "--no-ext-diff", "--find-renames", "--unified=3"], which does not pin the prefixes, so git honours the user's config.
Every header form, run against that exact regex:
| Section | git command | header emitted | parses |
|---|---|---|---|
| Against base / Commits | git diff <ref> HEAD |
diff --git a/f.txt b/f.txt |
yes |
| Unstaged | git diff |
diff --git i/f.txt w/f.txt |
no |
| Staged | git diff --cached |
diff --git c/f.txt i/f.txt |
no |
| Untracked | git diff --no-index |
diff --git 1/u.txt 2/u.txt |
no |
any, with diff.noprefix=true |
diff --git f.txt f.txt |
no |
Comparing two commits is the one case git leaves at a//b/, which is exactly why Against base and Commits still work. diff.noprefix = true, a common dotfiles setting, breaks the same three sections with no prefix at all.
Secondary: the failure is unrecoverable from the UI. The placeholder offers a Retry button, but onRequest only adds the item to requestedItemIds, which ungates generated files. It never refetches. Combined with the query's staleTime: Infinity and refetchOnWindowFocus: false, an errored getDiffPatch stays errored until something else fires git:changed. Happy to split this into its own issue if you'd rather.
Steps to reproduce
git config --global diff.mnemonicPrefix true(ordiff.noprefix true)- Open any workspace and modify a tracked file, leaving it unstaged
- Open the Changes pane. The file is listed under Unstaged with correct +/- counts
- Click it
Expected: the diff renders.
Actual: Unable to load diff, and Retry does nothing.
git add the file and click it under Staged for the same result. Against base keeps working throughout.
Logs, screenshots, or recordings
Regression window: #6968 ("render the Changes pane from patches", 2026-08-30, shipped in 1.26.0) switched the pane from per-file git show blobs to parsing patch text. The old path never read a diff header, so this could not happen before 1.26.0.
Suggested fix. Pin the output-affecting config at the invocation rather than teaching the parser each user's settings:
git -c diff.mnemonicPrefix=false \
-c diff.noprefix=false \
-c diff.srcPrefix=a/ \
-c diff.dstPrefix=b/ \
diff --no-color --no-ext-diff --find-renames --unified=3--default-prefix is the tidier one-liner and overrides all four knobs, but it needs git >= 2.45. On older git it is an unrecognised option that makes git exit non-zero, producing the same Unable to load diff from a different cause. Unknown config keys are silently ignored by every git version, so the -c form has no version floor.
diff-patch.ts is not the only programmatic git caller, so the durable place for this is the shared seam createGitEnvResolver already occupies, rather than each call site remembering. The --name-status / --numstat calls already sidestep path quoting via -z; the patch path never got an equivalent.
Possibly related, not verified: the regex does accept quoted headers, but captures the escaped literal (caf\303\251.txt) rather than the raw path that --name-status -z reports. That would make the parsed.byPath.get(file.path) lookup miss for non-ASCII filenames, giving the same placeholder with no console error. I have not reproduced it end to end.
Environment: macOS (Darwin 25.6.0), git 2.50.1 (Apple Git-155), desktop + CLI + host-service all 1.29.0.
Activity
github-actions commentedon Sep 16, 2026
Summary
The report is credible and I can confirm the server side of it by reading the code: the Changes pane's patch path shells out to
git diffwithout pinning any of the prefix-affecting config, sodiff.mnemonicPrefix/diff.noprefix/diff.srcPrefix/diff.dstPrefixfrom the user's own gitconfig land in thediff --git ...headers that the renderer then parses. Against-base and Commits keep working because comparing two commits is the one case where mnemonic prefixes coincide witha//b/; Staged (c/→i/), Unstaged (i/→w/) and untracked--no-index(1/→2/) do not, anddiff.noprefixstrips the prefix from all of them. A header the parser rejects yields no section, the per-path lookup misses, and the file falls through to theUnable to load diffplaceholder.Affected code
packages/host-service/src/trpc/router/git/utils/diff-patch.ts:38-43—BASE_ARGSis exactly["--no-color", "--no-ext-diff", "--find-renames", "--unified=3"], as quoted in the issue. Nothing pins the prefixes.packages/host-service/src/trpc/router/git/utils/diff-patch.ts:48-68— argv per category (--cached, barediff, ref pairs), and:212for the untracked--no-indexcall. All four shareBASE_ARGS.packages/host-service/src/workers/tasks/git.ts:180-207— the worker task that runs it, withgitEnvfromcreateGitEnvResolver.packages/host-service/src/runtime/git/git.ts:47-74— the shared env seam. It already pinsLC_ALL=CandGIT_OPTIONAL_LOCKS=0for exactly this class of reason ("pin the locale so every machine produces the wording those patterns were written against"), which is a precedent for pinning the prefixes too.apps/desktop/.../DiffPane/hooks/useDiffCodeViewItems/useDiffCodeViewItems.ts:256-264—parsePatchFilesoutput is indexed byfileDiff.name/prevName;:288-295looks upparsed.byPath.get(member.file.path).useDiffCodeViewItems.ts:334-355— a group that resolved but has no section for the path mapsgroupReason === "deferred"toreason: "error", i.e. theUnable to load diffplaceholder (DeferredDiffPlaceholder.tsx:29-42). That matches the described symptom precisely: the tRPC query succeeds (git exits 0), so this is a parse miss, not a fetch failure.I could not inspect
@pierre/diffsitself —node_modulesisn't installed in this triage environment — so theALTERNATE_FILE_NAMES_GITregex text is unverified from here. Note also thatapps/desktop/package.json:79pins@pierre/diffsat 1.3.6 onmain, not the 1.4.2 quoted in the issue; worth checking whether the reporter's build differs, though the failure mode doesn't depend on which of the two it is.Root cause
git diffhonours user config for prefixes, and the patch parser requires literala//b/. Two corroborating details from the code:packages/host-service/src/trpc/router/git/get-diff-patch.test.ts:67assertspatch).toContain("diff --git a/tracked.txt b/tracked.txt")in a temp repo that sets onlyuser.email/user.name/commit.gpgsign(:35-43) and does not isolate the global config (unlikeruntime/git/simple-git.test.ts:28, which setsGIT_CONFIG_GLOBAL). CI machines have nodiff.mnemonicPrefix, so it passes there — and that same assertion should fail today on the reporter's machine, which is a cheap one-command confirmation of the whole diagnosis.-z(utils/git-helpers.ts:469-470,utils/git-status.ts:97,121), and-zsuppresses path quoting entirely, sofile.pathis raw UTF-8. The patch path has no equivalent: withcore.quotePathat its defaulttrue, git emitsdiff --git "a/caf\303\251.txt" "b/caf\303\251.txt". UnlessparsePatchFilesunescapes,byPathis keyed on the escaped literal andparsed.byPath.get("café.txt")misses — same placeholder, no console error, no unusual config required.Ruled out: the PR Code tab (
PullRequestCodeTab.tsx:147) also callsparsePatchFiles, but its patch comes fromgh pr diff(pull-requests/procedures/get-diff.ts:42-56), which is GitHub-rendered and alwaysa//b/. Unaffected.On the secondary claim (Retry): as written it no longer matches
main.requestDiffconsultsretryByItemIdReffirst and callspatchQueries[index].refetch()(useDiffCodeViewItems.ts:130-145, map built at:234-241), so Retry does refetch for any file that belongs to a group — which staged/unstaged files do. The observable symptom still stands, though, for a stronger reason: the refetch re-runs the same deterministicgit diff, gets a byte-identical patch, and fails to parse again.staleTime: Number.POSITIVE_INFINITY(:221) is real but not what's stranding the user here. So this is one bug, not two — no need to split it.Reproduction
Steps as filed reproduce it; the repo-local equivalent is easier to script:
A
bun:testrepro drops straight into the existing suite — add toinitRepoinget-diff-patch.test.ts:35-43:and the existing
"unstaged patch carries the working-tree edit"test fails on its header assertion (:67), gettingdiff --git i/tracked.txt w/tracked.txt. A regression test wants one case per category (staged→c/+i/,unstaged→i/+w/, untracked--no-index→1/+2/) plus adiff.noprefix truecase, each asserting thea//b/header survives. Acore.quotePathcase with acafé.txtfilename would pin the second defect at the same time.Suggested fix
Pin the output-affecting config at the invocation, as the issue proposes, rather than teaching the parser anyone's settings — the parser also strips
a//b/to producefileDiff.name, so a looser regex would have to learn every prefix pair to keep the names right, and the names are what thebyPathlookup joins on.Two placements, both defensible:
CONFIG_ARGSarray prepended before"diff"indiffArgsForCategoryand in the--no-indexcall at:212. Note these aregit-level options, so they cannot live insideBASE_ARGS, which is appended after the subcommand:git -c diff.mnemonicPrefix=false -c diff.noprefix=false -c diff.srcPrefix=a/ -c diff.dstPrefix=b/ -c core.quotePath=false diff ....createGitEnvResolverseam (runtime/git/git.ts:47-74) viaGIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n, which covers every programmatic caller without each one remembering, and is whereLC_ALLalready lives. Caveats: those env vars need git ≥ 2.31 (vs. no floor for-c), the resolver's env is consumed by many non-diff commands, and nothing else in the tree setsGIT_CONFIG_*today so there's no collision — but since only this one call site parses patch text, the call-site version is the smaller change and I'd start there.The reporter is right that
--default-prefix(git ≥ 2.45) is the tidier spelling but introduces a version floor that fails loudly as an unknown option, whereas unknown config keys are silently ignored by every git — which also meansdiff.srcPrefix/diff.dstPrefix(also 2.45) are harmless no-ops on older git, wheremnemonicPrefixandnoprefixare the only two knobs that exist. Addingcore.quotePath=falseto the same list closes the non-ASCII path independently.fix(host-service): pin git's diff prefixes so the Changes pane can pa…