Skip to content

Patch: Stop mangling file when both pre- and post-patch file has no trailing newline#7128

Open
clemyan wants to merge 3 commits intomasterfrom
clemyan/fix-patch-no-trailing-newline
Open

Patch: Stop mangling file when both pre- and post-patch file has no trailing newline#7128
clemyan wants to merge 3 commits intomasterfrom
clemyan/fix-patch-no-trailing-newline

Conversation

@clemyan
Copy link
Copy Markdown
Member

@clemyan clemyan commented May 5, 2026

What's the problem this PR addresses?

The patch format used by plugin-patch assumes the source file ends with a newline, and uses the "\ No newline at end of file" marker to reconstruct the correct post-patch file contents. This wasn't taken into account when applying the patch, which caused files without a trailing newline to lose their last line after the patch was applied.

Closes #6612

How did you fix it?

Ensures source files are always treated as if they ended with a newline so that the patch can correctly reconstruct the post-patch file contents.

Also found a bug with fslib's implementation of Dirent while writing the tests so I just fixed it in passing.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

clemyan added 3 commits May 6, 2026 00:14
The patch format used by plugin-patch assumes the source file ends with
a newline, and uses the "\ No newline at end of file" marker to
reconstruct the correct post-patch file contents. This wasn't taken into
account when applying the patch, which caused files without a trailing
newline to lose their last line after the patch was applied.

This change ensures source files are always treated as if they ended
with a newline so that the patch can correctly reconstruct the
post-patch file contents.
@clemyan clemyan changed the title Clemyan/fix patch no trailing newline Patch: Stop mangling file when both pre- and post-patch file has no trailing newline May 7, 2026
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.

[Bug?]: Problem with applying patch if there is "No newline at end of file"

1 participant