Skip to content

fix(patchset): ignore trailing junks when hunk is complete#23

Merged
weihanglo merged 8 commits intogit-format-patchfrom
email-sig
Jan 26, 2026
Merged

fix(patchset): ignore trailing junks when hunk is complete#23
weihanglo merged 8 commits intogit-format-patchfrom
email-sig

Conversation

@weihanglo
Copy link
Copy Markdown
Owner

@weihanglo weihanglo commented Jan 26, 2026

Before this, we failed to handle patch that deletes a diff file
containing -- patterns within its content. As we'll strip out
the actual patch content by the wrong rfind logic.

Both git apply and GNU patch handle this correctly by just ignoring
junks between each file patch.

With this we can also remove the email signature stripping logic.

Junk Between Hunks vs Between Files

Scenario GNU patch git apply diffy
Junk between hunks (same file) ✅ Ignores trailing, applies first hunk only ❌ Errors ✅ Ignores trailing, applies first hunk only
Junk between files ✅ Treats as preamble ✅ Treats as preamble ✅ Treats as preamble
Trailing junk at end ✅ Ignores ✅ Ignores ✅ Ignores

diffy matches GNU patch behavior.
git apply is stricter (errors on junk between hunks).


This bug was found during a replay of the most recent 1000 commits in rust-lang/rust https://github.com/weihanglo/diffy/actions/runs/21342417740/job/61423914086.

This also add a check that fail when no patch found in a patchset.

Patch that deletes a diff file containing `-- ` patterns within
its content, followed by a real email signature at the end.

Tests that we should correctly distinguish between:

- `-- ` appearing as patch content (from inner diff's empty context lines)
- `-- ` appearing as the actual email signature separator

Both git apply and GNU patch handle this correctly.
Before this, we failed to handle patch that deletes a diff file
containing `-- ` patterns within its content. As we'll strip out
the actual patch content by the wrong `rfind` logic.

Both git apply and GNU patch handle this correctly by just ignoring
junks between each file patch.

With this we can also remove the email signature stripping logic.
@weihanglo weihanglo merged commit 56116cf into git-format-patch Jan 26, 2026
11 checks passed
@weihanglo weihanglo deleted the email-sig branch January 26, 2026 20:08
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