Skip to content

Unable to apply patches with trailing blank line removed #59

Open
@fmarier

Description

@fmarier

Given a.txt:

1
2
3

and broken.patch (note that it's missing the third line of context):

--- a.txt	2019-03-28 17:02:04.832004033 -0700
+++ b.txt	2019-03-28 17:02:34.999576803 -0700
@@ -1,4 +1,4 @@
-1
+0
 2
 3

one can get to b.txt:

0
2
3

using patch -p0 < broken.patch but not with python-patch:

$ ./patch.py --debug broken.patch 
   DEBUG reading broken.patch
 WARNING error: patch stream is incomplete!
   DEBUG -  0 hunks for a.txt
   DEBUG total files: 1  total hunks: 0
   DEBUG normalize filenames
   DEBUG     patch type = plain
   DEBUG     source = a.txt
   DEBUG     target = b.txt
Traceback (most recent call last):
  File "./patch.py", line 1193, in <module>
    main()
  File "./patch.py", line 1186, in main
    patch.apply(options.strip, root=options.directory) or sys.exit(-1)
AttributeError: 'bool' object has no attribute 'apply'

To patch a.txt correctly using python-patch, one needs to provide the non-truncated patch file which contains the full three lines of context (with the last line consisting of a single trailing space):

--- a.txt	2019-03-28 17:02:04.832004033 -0700
+++ b.txt	2019-03-28 17:02:34.999576803 -0700
@@ -1,4 +1,4 @@
-1
+0
 2
 3
 

This can be a problem since git is commonly configured to remove "unnecessary trailing whitespace" via the following option in ~/.gitconfig:

[apply]
        whitespace = fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions