Skip to content

Patch.diff generates a malformed diff when adding a line at the end of a file that doesn't end with a newline character #28

@kit-ty-kate

Description

@kit-ty-kate

Using patch.3.0.0~alpha2, opam 2.4.0~alpha2 generates and prints the following malformed diff:

--- default/packages/b0/b0.0.0.5/opam
+++ default.new/packages/b0/b0.0.0.5/opam
@@ -45,0 +45,1 @@
\ No newline at end of file
+x-maintenance-intent: ["(latest)"]
\ No newline at end of file

Parsing that file (understandably) raises the following error:

Failure {|"no newline at the end of file" is not at the end of the file|}

For reference, this is what GNU diff outputs for such change:

$ printf "%s" a > a
$ printf "%s\nb" a > b
$ diff -u a b
--- a	2025-05-27 17:27:01.410580904 +0100
+++ b	2025-05-27 17:27:10.235615949 +0100
@@ -1 +1,2 @@
-a
\ No newline at end of file
+a
+b
\ No newline at end of file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions