snilard
snilard

Reputation: 107

Patch cannot proceeed one specific diff

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.

Upvotes: 0

Views: 307

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 208555

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?

Upvotes: 1

Related Questions