gdiff: normalize endpoint line reads for generated diffs #120
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
barrettruth/diffs.nvim#120
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent tracker: #270
Problem
Generated
:Gdiffcan render a fake trailing-newline hunk for files that have no text difference on the selected edge.Observed in the local real-repo scenario matrix:
:Gdiffon a staged-only file opensdiffs://unstaged:file.txtwith a bogus trailing-newline-only hunk;:Gdiffon a staged added file does the same, even though plain direct:Gdiffisindex -> worktreeand the index/worktree contents are identical;:Gdiffon a mode-only file can show a fake text hunk instead of reporting the mode-only unsupported case;:Gdiffon a pure rename can show a fake text hunk instead of correctly reporting no text changes or unsupported rename behavior.This is not a Fugitive parity issue. Plain worktree-file
:Gdiffshould remain anindex -> worktreegenerated unified diff. If that edge has no text changes, it should report no changes.Suspected cause
Git endpoint reads and buffer/worktree reads normalize lines differently.
Relevant code:
lua/diffs/git.luaget_file_content()usesvim.fn.systemlist({ "git", ..., "show", REV:path }, nil, true)get_index_content()usesvim.fn.systemlist({ "git", ..., "show", ":0:path" }, nil, true)get_working_content()usesvim.fn.readfile(filepath, "b")lua/diffs/render.luaread_endpoint()reads tree/index/worktree endpointsunified_lines()joins line arrays with\nand delegates tovim.text.diff/vim.diffIn a temp repo,
git show :0:file.txtthroughsystemlist(..., true)produced{ "one", "two", "three", "" }for a normal newline-terminated file, while the buffer/worktree representation was{ "one", "two", "three" }. That final sentinel creates a fake\ No newline at end of filediff.Expected behavior
index -> worktreecontent should produce no generated diff.:Gdiffshould report no unstaged changes.:Gdiffshould report no unstaged changes when index and worktree match.:Gdiffshould reportGdiff does not support mode-only changes, not a fake text hunk.systemlist()EOF sentinel, not legitimate content.Implementation guidance
Add a small normalization helper near the Git endpoint readers, or in the render endpoint path, that makes Git blob reads and worktree/buffer reads comparable.
Be careful with these cases:
a\nshould compare as{ "a" }, matchingreadfile().a\n\nshould compare as{ "a", "" }, preserving the intentional blank final line.awithout a trailing newline should remain{ "a" }.Do not solve this by suppressing all no-newline metadata globally; hunk parsing already treats
\ No newline at end of fileas metadata when the diff engine legitimately emits it.Acceptance criteria
:Gdiff.