What does 'patch unexpectedly ends in middle of line' mean?
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.
If you're not using git
(@maxslepzig's comment was about using patch in the context of git
), try adding a carriage return at the end of your file. I did that and patch
accepted my patch.
To add to this very old discussion:
The problem leading to the warning the OP noted is generally caused by problems with line endings.
patch
wants a trailing line feed (LF) in order to determine the end of file (and warns of a unified diff that may have been accidentally truncated)
Append the proper linefeed without opening the file up for editing (which might modify your line endings or strip trailing lines/spaces depending on your editor's settings) you can do something simple like:
echo -e "\n" >> YOURPATCHFILE
This appends a linefeed character to the end of the file without making any other changes.
If your patch file is already weird or you want to go through several possible fixes at once, you can correct many problems with encoding (to ascii) including the line endings (CR or CRLF to LF):
dos2unix -k YOURPATCHFILE
You may have to install the dos2unix binary from your OS's package manager; i.e.
- Debian/Ubuntu based:
sudo apt install dos2unix
- Fedora/RHEL/CentOS:
sudo yum install dos2unix
- MacOS (with brew):
brew install dos2unix
- Debian/Ubuntu based: