Skip to content

fix: hunk header counts and the deleted-line check - #580

Merged
jakubbortlik merged 2 commits into
harrisoncramer:developfrom
seflue:fix/hunk-header-counts
Aug 3, 2026
Merged

fix: hunk header counts and the deleted-line check#580
jakubbortlik merged 2 commits into
harrisoncramer:developfrom
seflue:fix/hunk-header-counts

Conversation

@seflue

@seflue seflue commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Git omits the ,N in a hunk header when N is 1, so @@ -5 +4,0 @@ is a one-line deletion. parse_possible_hunk_headers reads the empty capture as 0, which makes that header look like @@ -5,0 +4,0 @@: is_range_zero short-circuits get_modification_type_from_new_sha, and the unmodified line above the deletion comes back as added. The same deletion over two lines classifies correctly. The first commit reads the empty capture as 1.

Found this while working on #577.

While I was in there I replaced the body walk in line_was_removed with a range check: with --unified=0 a hunk has no context lines, so the old range already answers the question. No behaviour change. The old side had no tests, so that commit adds some.

Putting get_modification_type under test properly is a different matter; I will write that up in #386. Related to that issue, not a fix for it.

seflue added 2 commits August 2, 2026 13:02
Commenting on the unchanged line directly above a deletion of exactly
one line sent it as an added line, anchored to the new side, and
without the warning that comments on unmodified lines are placed in
the old file. It now goes to the old file with both line numbers, the
way it already did above a deletion of two or more lines.
The check implemented the general algorithm for arbitrary diffs,
including context lines, and its range carried an off-by-one that no
caller could reach. The only diff it ever sees comes from
git.diff_files, which runs with --unified=0 and has no context lines,
so a line is removed exactly when it falls in the hunk's old range.
Simplify to that rather than fix the bound.
@jakubbortlik

Copy link
Copy Markdown
Collaborator

Hi Sebastian! Thanks for opening the PR. I'm aware of hunk header parsing bug and the same fix is part of my WIP. Regarding the modification type detection, I'm playing with the idea of actually checking the diff with a three line context (--unified=3) because that will possibly make it easier to detect "expanded" lines - a type of "non-modification" that Gitlab itself distinguishes, so maybe I'll revert the line_was_removed function in the future, but I'm merging this anyway now because it will prevent some of the errors commenting produces.

Thank you especially for the tests!

@jakubbortlik
jakubbortlik merged commit 876ed78 into harrisoncramer:develop Aug 3, 2026
4 checks passed
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.

2 participants