Skip to content

Ignore "No newline at end of file" markers in patches - #93

Merged
janedbal merged 1 commit into
masterfrom
jn-fix-patch-no-newline-marker
Oct 20, 2026
Merged

janedbal merged 1 commit into
masterfrom
jn-fix-patch-no-newline-marker

Conversation

@janedbal

Copy link
Copy Markdown
Member

Git writes \ No newline at end of file after a line that has no newline. sebastian/diff parses this marker as an unchanged line, so PatchParser counts it as a line of the new file. Every added line after the marker gets a number one too high:

@@ -1,3 +1,4 @@
 parameters:
     paths:
-        - src
\ No newline at end of file      ← counted as line 3
+        - src                    ← gets #4, real line is 3
+        - tests                  ← gets #5, real line is 4

The content check then fails, and check --patch and patch-coverage stop:

⚠️  Error: Patch file 'neon.patch' has added line #4 that does not match actual content of file '…/phpstan.neon'.
Patch data: '        - src'
Filesystem: '        - tests'

Is the patch up-to-date?

When it happens:

  • The old version of a file has no final newline, and the change adds lines after its last line or edits its last line.
  • Adding the missing final newline is enough, e.g. a phpcbf fix.
  • The check covers every file in the patch, so a .neon, .yml or .json file also triggers it.

In a unified diff, every file line starts with a space, + or -. Only this marker starts with a backslash. Now PatchParser removes such lines before it parses the patch.

  • New PatchParserTest with a fixture patch from a real git diff. The test fails on master.

Co-Authored-By: Claude Code

@janedbal
janedbal marked this pull request as ready for review October 20, 2026 07:48
Git writes "\ No newline at end of file" after a line that has no
newline. sebastian/diff parses this marker as an unchanged line, so
PatchParser counted it as a line of the new file. Every added line after
the marker got a number one too high. The content check then failed with
a false "Is the patch up-to-date?" error, and check --patch and
patch-coverage stopped.

This happens when the old version of a file has no final newline and the
change adds lines after its last line or edits its last line. Adding the
missing final newline is enough. The check covers every file in the
patch, so a .neon, .yml or .json file also triggers it.

In a unified diff, only this marker starts with a backslash. PatchParser
now removes such lines before it parses the patch.

Co-Authored-By: Claude Code
@janedbal
janedbal force-pushed the jn-fix-patch-no-newline-marker branch from 2f61fa2 to 7aeb017 Compare October 20, 2026 08:41
@janedbal
janedbal merged commit 0ed07cc into master Oct 20, 2026
31 checks passed
@janedbal
janedbal deleted the jn-fix-patch-no-newline-marker branch October 20, 2026 08:43
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