Skip to content

fix(diff): full file context and deleted line parsing#113

Merged
actionshrimp merged 3 commits intomainfrom
fix/diff-viewer-full-context-and-deleted-lines
Feb 24, 2026
Merged

fix(diff): full file context and deleted line parsing#113
actionshrimp merged 3 commits intomainfrom
fix/diff-viewer-full-context-and-deleted-lines

Conversation

@actionshrimp
Copy link
Owner

Summary

  • Full file context (-U999999): The diff viewer was using git's default 3-line context, so longer files only showed fragments around each change. Added -U999999 to all diff source types (staged, unstaged, worktree, commit, range, stash, PR) to show the complete file, matching the three-way diffs which already had this. Also added is_hunk_boundary post-processing to 2-pane align_sides() so ]c/[c navigation still works when hunks merge.

  • Deleted line parsing bug: The unified diff parser checked for file header patterns (^--- , ^+++ ) before checking if it was inside a hunk. Deleted lines starting with -- (e.g. Lua comments) produced diff lines like --- comment that matched the file header pattern and were silently dropped. Fixed by prioritizing the "inside a hunk" state — only diff --git and @@ can exit a hunk, everything else is hunk content.

Test plan

  • Unit tests for -U999999 args in all source types (test_diff_source.lua)
  • Unit tests for is_hunk_boundary context-to-change transitions (test_diff_content.lua)
  • Unit test for multiple change regions in a single hunk (test_diff_content.lua)
  • Unit tests for deleted -- comment lines not being swallowed (test_diff_hunk.lua)
  • Unit tests for added ++ ... lines not being swallowed (test_diff_hunk.lua)
  • All 1539 unit tests pass
  • All 622 e2e tests pass (55 suites)
  • Manual verification by user

Without full-context flag, git only outputs 3 lines of surrounding
context per hunk. For longer files this meant the side-by-side diff
viewer showed only fragments rather than the complete file.

Add -U999999 to all diff source types (staged, unstaged, worktree,
commit, range, stash, PR) to match the three-way diffs which already
had this fix. Also add is_hunk_boundary post-processing to 2-pane
align_sides() so ]c/[c navigation works correctly when hunks merge
into one.
The unified diff parser checked for file header patterns (^--- , ^+++ )
before checking if we were inside a hunk. This meant deleted lines whose
content started with "-- " (e.g. Lua comments) produced diff lines like
"--- comment" that matched the file header pattern and got swallowed
instead of being added to the hunk. Same issue for additions starting
with "++ ".

Fix by checking current_hunk_lines first — if we're inside a hunk, all
lines belong to the hunk (only diff --git and @@ can end it).
…ments

Add 3 E2E tests covering the bugs fixed in this branch:
- Commit diff shows full file content (line10 visible in 20-line file
  with changes at lines 2 and 19, would be missing without -U999999)
- Deleted Lua comment lines appear in commit diff left buffer
- Deleted Lua comment lines appear in staged diff left buffer
@actionshrimp actionshrimp merged commit 1523469 into main Feb 24, 2026
3 checks passed
@actionshrimp actionshrimp deleted the fix/diff-viewer-full-context-and-deleted-lines branch February 24, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant