2

I want to apply a .patch file to one file. I placed both in the same folder and I tried this

trinity@Zion ~/Desktop $ patch -i lalala.patch 
patching file install.sub
patch unexpectedly ends in middle of line
Hunk #1 FAILED at 1562.
1 out of 1 hunk FAILED -- saving rejects to file install.sub.rej

But as you see in the output, it failed. The content of install.sub.rej is basically all the code from lalala.patch I tried similar commands but I got the same results. I guess I'm doing something wrong.

I know applying a patch is just 1 command but I'm so lost at this. If someone tells me the command or directly patches the file (and also tells me the command) thanks

original file http://pastebin.com/raw.php?i=PKru8m5r patch: http://pastebin.com/raw.php?i=kkMUHtj8

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Florencia Hoffmann
  • 123
  • 1
  • 1
  • 4
  • What operating system are you using? Is it possible that your source file and patch file have different line endings (LF vs CRLF)? That can sometimes cause the `patch` program to throw a wobbly. – Greg Hewgill Aug 06 '11 at 23:05
  • I'm using Linux Mint(Ubuntu) but the patch I'm trying to apply is to OpenBSD installer script. (Maybe this help, I want to apply a patch to this revision: http://www.openbsd.org/cgi-bin/cvsweb/src/distrib/miniroot/install.sub?r1=1.650#rev1.650 ) – Florencia Hoffmann Aug 06 '11 at 23:10
  • Just want to add a comment for others that may find this as I did but issue was different, I was in windows using Notepad++ which handles *nix line endings fine, but when you're using a .patch file and press enter, it automatically adds a space to the next line. So in my case last line had an extra space which made patch complain. – user3161924 Dec 07 '21 at 23:26

2 Answers2

1

Your patch command is fine. It is the patch file itself that gives the problem (at least for me (Kubuntu 11.04), as looking at the link you gave in the comment, all patch files contain the same error...?!)

To solve the problem for me, find this line in the patch file:

@@ -1562,6 +1562,8 @@ set_timezone() {

and remove the set_timezone() { part and the error you describe is gone.

This part is showing the function where the changes are made. When looking at the patches on the page you gave in your comment, it shows that all of them contain this extra information. As far as I know (but I am not a patch guru, so please correct me) is this not accepted by the default patch command.

(Unfortunately enough, your patch still fails and the expected lines in the patch file compared to the original file do not match...)

Veger
  • 37,240
  • 11
  • 105
  • 116
0

Quite likely, the generated patch is "correct" but double-check the encode of it and be sure it's UTF-8.

Alex Moreno
  • 151
  • 1
  • 8