What does ‘patch unexpectedly ends in middle of line’ mean

command linediff()

This is the output of my patch command:

Hunk #11 merged at 4184,4190.
Hunk #12 merged at 4444.
Hunk #13 merged at 4944.
Hunk #14 NOT MERGED at 5106-5116.
Hunk #15 merged at 5290.
Hunk #16 merged at 5448.
patch unexpectedly ends in middle of line
Hunk #17 merged at 5608,5611.

The command was

patch -d ~/SOME_DIR -p1 --merge --verbose -u

The patch was produced using git:

git --git-dir ~/SOME_DIR/.git diff -U8 bb1ee538982957b421a4c0e78f30428e73c9a072 HEAD -- malloc.c

What does patch unexpectedly ends in middle of line mean, and is it a problem? Is it referring to hunk 16 or 17? What can I look for in the patch file to figure out what's causing this?

Best Answer

The message refers to Hunk 16.

This GitHub discussion is probably related to your issue.

It is about patch unexpectedly ends in middle of line messages because of CRLF (carriage-return, linefeed) issues when git generated diffs are used with patch.

To quote the conclusion:

[..] git can be very picky about line endings. Are you on windows or not? At any rate, you should probably set autocrlf in the git config. If you're on windows, you want "true", if you're on mac or linux, you should use "input" [..]

In the article Dealing with line endings GitHub details the above statement.

Related Question