Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to apply patches with trailing blank line removed #59

Open
fmarier opened this issue Mar 29, 2019 · 2 comments
Open

Unable to apply patches with trailing blank line removed #59

fmarier opened this issue Mar 29, 2019 · 2 comments

Comments

@fmarier
Copy link

fmarier commented Mar 29, 2019

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
@swissembedded
Copy link

Had the same issue, very annoying as this lib is now used with conan package manager

@techtonik
Copy link
Owner

How can I reproduce it with git locally? Ideally on this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants