Skip to content

Fix absorb refusing any change that deletes lines - #60

Merged
DomBlack merged 1 commit into
mainfrom
absorb-offset
Oct 16, 2026
Merged

DomBlack merged 1 commit into
mainfrom
absorb-offset

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Absorbing a staged change that only removed lines always failed. The dry run planned it fine, then the real run refused with "could not be applied ... this is a bug in stack_absorb", and git apply's output said a hunk succeeded at an offset of 1 line. This came up for real on a migration where a couple of the eleven hunks were deletions.

The patches absorb writes number each hunk the way git diff -U0 does, and for a deletion git diff gives the line before the gap. git apply doesn't read it that way though: it takes the new start as the line where the removed lines begin, so it found them one line further down and said so. We refuse any apply at an offset (a hunk landing somewhere other than where the plan put it would be silently wrong), so every deletion was turned away even though the plan was right. I checked this against git apply directly with a one line deletion: numbered the git diff way it applies "at offset 1 line", numbered from the first removed line it applies exactly.

So a deletion's new start is now the line its removed lines start on, once the hunks above it are in. The offset check is unchanged, so a hunk that really doesn't fit where it was planned is still refused.

Absorbing a staged change that only removed lines always failed: the dry run planned it fine, then the real run refused with "could not be applied ... this is a bug in stack_absorb" and git apply's output saying a hunk succeeded at an offset of 1 line. A migration with a couple of deleted lines among nine other hunks was enough to hit it.

The patches absorb writes number each hunk the way git diff -U0 does, and for a deletion git diff gives the line before the gap. git apply doesn't read it that way though; it takes the new start as the line where the removed lines begin, so it found them one line further down and said so. We refuse any apply at an offset (a hunk landing somewhere other than where the plan put it would be silently wrong), so every deletion was turned away even though the plan was right.

So the patch now gives a deletion the line its removed lines start on, once the hunks above it are in, and git apply places it exactly where it says. The offset check stays as it was, so a hunk that really doesn't fit where it was planned is still refused.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 13:49
@DomBlack DomBlack added the bug Something isn't working label Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@DomBlack
DomBlack merged commit 4dc5b21 into main Oct 16, 2026
5 of 6 checks passed
@DomBlack
DomBlack deleted the absorb-offset branch October 16, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants