Skip to content

fix(core): index moved hunk lines that start with ++ or -- - #867

Open
benvinegar wants to merge 2 commits into
mainfrom
fix/moved-line-classification
Open

fix(core): index moved hunk lines that start with ++ or --#867
benvinegar wants to merge 2 commits into
mainfrom
fix/moved-line-classification

Conversation

@benvinegar

@benvinegar benvinegar commented Aug 27, 2026

Copy link
Copy Markdown
Member

Before / after

Real terminal captures — tmux panes running Hunk's interactive TUI on the same git diff --color-moved=zebra input, buggy code (origin/main) vs. this fix.

BEFORE AFTER
before after

The moved tint glows on the ++ plus row before the fix (it was silently dropped from the indexer), and the real moved line + AAA one… renders as a plain addition. After the fix, the tint sits exactly on the moved line.


The hunk adds ++ plus right before a moved line. The classifier indexes every +/- row it sees; the ++ plus row is one of them — but its diff body reads +++, so the old guard treated it as a file header and skipped it, shifting every later classification by one row.

Root cause

collectLineMoveKinds guarded hunk-body +/- lines against looking like +++ b/… / --- a/… file headers, but those headers never appear inside a hunk. A content line whose own text starts with ++ (e.g. ++i;, ++ plus) reads as +++… in the patch and was skipped, so:

  • a genuine --color-moved line lost its "moved" styling, and
  • one other row gained a moved badge it didn't earn.

Fix

Removed both guards (src/core/changeset/fromPatch.ts): inside a hunk, every line starting with + is an added content row and every line starting with - is a deleted content row; inHunk already excludes the actual headers.

Verification

  • New regression tests in src/core/changeset/fromPatch.test.ts for both sides (fail on the old code, pass on the fix).
  • End-to-end check against a real zebra patch: parser output matches ground-truth move indices exactly (was off by one).
  • bun test src/core/changeset + bun run typecheck green.

collectLineMoveKinds guarded hunk-body +/− lines against looking like +++ b/…/--- a/… file headers, but headers never appear inside a hunk. A content line whose own text starts with ++ (e.g. ++i;, ++ plus) reads as +++… in the patch and was skipped, shifting every later moved-line classification by one row: git's color-moved badges landed on the wrong line and the final moved line lost its badge.

Drop both guards; every hunk-body line starting with + or − is content that advances the per-side index. Add regression coverage for both sides.
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hunk-web Ignored Ignored Preview Aug 27, 2026 1:25am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Corrects moved-line indexing for hunk content beginning with repeated plus or minus characters.

  • Removes file-header guards after hunk entry so all added and deleted content rows advance their side-specific indices.
  • Adds regression coverage for both addition and deletion prefixes.
  • Adds a patch changeset describing the user-visible classification fix.

Confidence Score: 5/5

The PR appears safe to merge, with focused tests covering both corrected indexing paths.

Within a hunk, repeated-sign rows are content rather than file headers, and the collector now advances indices consistently with the parsed addition and deletion arrays.

Important Files Changed

Filename Overview
src/core/changeset/fromPatch.ts Removes inappropriate +++/--- exclusions within hunks, preserving alignment between parser metadata and moved-line classifications.
src/core/changeset/fromPatch.test.ts Adds focused end-to-end parser regressions for added ++ content and deleted -- content.
.changeset/quiet-diffs-moved.md Accurately documents the moved-line classification correction as a patch release.

Reviews (1): Last reviewed commit: "fix(core): index moved hunk lines that s..." | Re-trigger Greptile

@benvinegar

Copy link
Copy Markdown
Member Author

Real terminal captures (tmux panes running the interactive TUI, buggy vs. fixed): https://sideshow.sh/p/2VKXeBS2W-E

@benvinegar

Copy link
Copy Markdown
Member Author

The real terminal captures are inline in the PR body above (before/after side by side).

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