fix(parser): support git diff.mnemonicPrefix in diff header#195
Merged
barrettruth merged 2 commits intobarrettruth:mainfrom Mar 17, 2026
Merged
fix(parser): support git diff.mnemonicPrefix in diff header#195barrettruth merged 2 commits intobarrettruth:mainfrom
barrettruth merged 2 commits intobarrettruth:mainfrom
Conversation
Owner
|
Looking at this later today. Did not know about this setting - thanks for ironing it out. |
letientai299
added a commit
to letientai299/nvim.conf
that referenced
this pull request
Mar 17, 2026
diffs.nvim was lazy=true and only loaded as a neogit dependency, so it never activated during `git commit -v`. Also switch to fork that fixes diff.mnemonicPrefix support (upstream PR: barrettruth/diffs.nvim#195).
Problem: `git diff.mnemonicPrefix = true` produces diff headers like `diff --git c/init.lua i/init.lua` using single-letter mnemonic prefixes (`c/`, `i/`, `w/`) instead of the standard `a/`/`b/`. The parser only matched `a/.+ b/(.+)`, so mnemonic-prefixed diffs produced no highlighting. Solution: Change the pattern to `%a/.+ %a/(.+)` (Lua `%a` matches any letter), accepting any single-letter prefix while correctly rejecting numeric prefixes like `1/`/`2/`. Adds tests for both the accepted mnemonic cases and the rejected numeric case.
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.
When
diff.mnemonicPrefixis enabled in git config, diff headers usecontext-dependent single-letter prefixes instead of the default
a/and
b/. For example,git commit -vproduces:where
c/= commit (HEAD) andi/= index (staged). Other contextsuse
w/(worktree),o/(object), etc. The full set is documentedin git-diff(1) under
diff.mnemonicPrefix.The parser hardcoded
a/andb/, so it failed to extract thefilename from the diff header. Without a filename, filetype detection
returned nil and no syntax highlighting was applied to hunk content.
The fix replaces the literal
aandbwith%a(Lua pattern forany ASCII letter). This is a strict superset of the old behavior:
a/…b/still matches (the default prefix).c/…i/,w/…i/, etc. now also match./still won't match, so paths like1/fooor./fooare correctly rejected./.+) is unchanged, so the capture groupstill extracts the path after the second prefix.
The
diff --combinedanddiff --ccbranches are unaffected.