Skip to content

chore(tools): Fix corrupt patch when staging a non-last hunk#498

Merged
JeanMertz merged 2 commits intomainfrom
prr66
Apr 2, 2026
Merged

chore(tools): Fix corrupt patch when staging a non-last hunk#498
JeanMertz merged 2 commits intomainfrom
prr66

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

When a diff contains multiple hunks, splitting on \n@@ consumed the newline that separated hunks. This meant selecting any hunk other than the last produced a patch string without a trailing newline.

git apply requires every diff line to be newline-terminated and rejects patches that lack it as corrupt. The fix adds a trailing newline to the assembled patch when one is missing before passing it to git apply --cached.

When a diff contains multiple hunks, splitting on `\n@@ ` consumed the
newline that separated hunks. This meant selecting any hunk other than
the last produced a patch string without a trailing newline.

`git apply` requires every diff line to be newline-terminated and
rejects patches that lack it as corrupt. The fix adds a trailing newline
to the assembled patch when one is missing before passing it to `git
apply --cached`.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz merged commit 129167c into main Apr 2, 2026
12 checks passed
@JeanMertz JeanMertz deleted the prr66 branch April 2, 2026 20:56
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