0

I have got one specific file like this:

 +
 +                        %3)+Lorem
 +
 +                        %4)+Lorem
 +
 +                        %5)+Lorem
 +
 +

I generate unified diff using python 2.7 difflib with all context lines:

--- bug-3.txt   2012-07-23 15:25:42
+++ FILE    2012-07-23 15:25:42
@@ -1,8 +1,10 @@
 +
 +                        %3)+Lorem
 +
 +                        %4)+Lorem
 +
 +                        %5)+Lorem
 +
++                        %6)+Lorem
++
 +

And when I call patch (patch --verbose bug-3.txt bug-3.patch) it gives me this error:

Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- bug-3.txt  2012-07-23 15:25:42
|+++ FILE   2012-07-23 15:25:42
--------------------------
Patching file bug-3.txt using Plan A...
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file bug-3.txt.rej
done

I thing there could be bug in patch. Do you have any idea what exactly cause this error and what to do with it?

I run Ubuntu 12.04 and patch patch 2.6.1.

1 Answer 1

1

It looks like the original file contains a single space at the beginning of each line, but that space is missing from the diff. I would expect your diff output to look something like this:

--- bug-3.txt   2012-07-23 15:25:42
+++ FILE    2012-07-23 15:25:42
@@ -1,8 +1,10 @@
  +
  +                        %3)+Lorem
  +
  +                        %4)+Lorem
  +
  +                        %5)+Lorem
  +
+ +                        %6)+Lorem
+ +
  +

Perhaps you are calling strip() on each line from the file before generating the diff?

Sign up to request clarification or add additional context in comments.

2 Comments

You are right. I have got a little bit more complex file and this is only change. I entered original file wrong, it should by without leading space on each line. But my example works, so problem is somewere else in my file. Thank you.
I found solution for my problem. Patch is little fit sensitive on right number of new lines on ned of .patch file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.