Skip to content

Changes pane can't render Staged/Unstaged diffs when git emits non-default diff prefixes (diff.mnemonicPrefix, diff.noprefix) #7596

Closed

Description

@aponcedeleonch

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

  1. git config --global diff.mnemonicPrefix true (or diff.noprefix true)
  2. Open any workspace and modify a tracked file, leaving it unstaged
  3. Open the Changes pane. The file is listed under Unstaged with correct +/- counts
  4. 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

  1. github-actions commented on Sep 16, 2026

    @github-actions
    Contributor

    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 diff without pinning any of the prefix-affecting config, so diff.mnemonicPrefix / diff.noprefix / diff.srcPrefix / diff.dstPrefix from the user's own gitconfig land in the diff --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 with a//b/; Staged (c/→i/), Unstaged (i/→w/) and untracked --no-index (1/→2/) do not, and diff.noprefix strips 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 the Unable to load diff placeholder.

    Affected code

    • packages/host-service/src/trpc/router/git/utils/diff-patch.ts:38-43 — BASE_ARGS is 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, bare diff, ref pairs), and :212 for the untracked --no-index call. All four share BASE_ARGS.
    • packages/host-service/src/workers/tasks/git.ts:180-207 — the worker task that runs it, with gitEnv from createGitEnvResolver.
    • packages/host-service/src/runtime/git/git.ts:47-74 — the shared env seam. It already pins LC_ALL=C and GIT_OPTIONAL_LOCKS=0 for 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 — parsePatchFiles output is indexed by fileDiff.name/prevName; :288-295 looks up parsed.byPath.get(member.file.path).
    • useDiffCodeViewItems.ts:334-355 — a group that resolved but has no section for the path maps groupReason === "deferred" to reason: "error", i.e. the Unable to load diff placeholder (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/diffs itself — node_modules isn't installed in this triage environment — so the ALTERNATE_FILE_NAMES_GIT regex text is unverified from here. Note also that apps/desktop/package.json:79 pins @pierre/diffs at 1.3.6 on main, 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 diff honours user config for prefixes, and the patch parser requires literal a//b/. Two corroborating details from the code:

    1. Why CI didn't catch it. packages/host-service/src/trpc/router/git/get-diff-patch.test.ts:67 asserts patch).toContain("diff --git a/tracked.txt b/tracked.txt") in a temp repo that sets only user.email/user.name/commit.gpgsign (:35-43) and does not isolate the global config (unlike runtime/git/simple-git.test.ts:28, which sets GIT_CONFIG_GLOBAL). CI machines have no diff.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.
    2. The non-ASCII note in the issue looks right, and is a separate default-config bug. The sidebar/status path uses -z (utils/git-helpers.ts:469-470, utils/git-status.ts:97,121), and -z suppresses path quoting entirely, so file.path is raw UTF-8. The patch path has no equivalent: with core.quotePath at its default true, git emits diff --git "a/caf\303\251.txt" "b/caf\303\251.txt". Unless parsePatchFiles unescapes, byPath is keyed on the escaped literal and parsed.byPath.get("café.txt") misses — same placeholder, no console error, no unusual config required.

    Ruled out: the PR Code tab (PullRequestCodeTab.tsx:147) also calls parsePatchFiles, but its patch comes from gh pr diff (pull-requests/procedures/get-diff.ts:42-56), which is GitHub-rendered and always a//b/. Unaffected.

    On the secondary claim (Retry): as written it no longer matches main. requestDiff consults retryByItemIdRef first and calls patchQueries[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 deterministic git 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:

    cd /path/to/any/workspace
    git config diff.mnemonicPrefix true    # or: git config diff.noprefix true
    # edit a tracked file, open the Changes pane, click the file under Unstaged

    A bun:test repro drops straight into the existing suite — add to initRepo in get-diff-patch.test.ts:35-43:

    await git.raw(["config", "diff.mnemonicPrefix", "true"]);

    and the existing "unstaged patch carries the working-tree edit" test fails on its header assertion (:67), getting diff --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 a diff.noprefix true case, each asserting the a//b/ header survives. A core.quotePath case with a café.txt filename 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 produce fileDiff.name, so a looser regex would have to learn every prefix pair to keep the names right, and the names are what the byPath lookup joins on.

    Two placements, both defensible:

    • At the call site — a CONFIG_ARGS array prepended before "diff" in diffArgsForCategory and in the --no-index call at :212. Note these are git-level options, so they cannot live inside BASE_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 ....
    • At the createGitEnvResolver seam (runtime/git/git.ts:47-74) via GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n, which covers every programmatic caller without each one remembering, and is where LC_ALL already 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 sets GIT_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 means diff.srcPrefix/diff.dstPrefix (also 2.45) are harmless no-ops on older git, where mnemonicPrefix and noprefix are the only two knobs that exist. Adding core.quotePath=false to the same list closes the non-ASCII path independently.

  2. added a commit that references this issue on Sep 19, 2026
    0f5bcab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions