techtonik / python-patch

Library to parse and apply unified diffs
https://pypi.python.org/pypi/patch
112 stars 65 forks source link

No error returned if patching is aborted due to existing .orig file #60

Open fmarier opened 5 years ago

fmarier commented 5 years ago

Given the following a.txt file:

1
2
3

and the following working.patch:

--- 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

Patching will fail if a.txt.orig already exists:

$ touch a.txt.orig
$ ./patch.py --debug working.patch && echo Success!
   DEBUG reading working.patch
   DEBUG crlf: 0  lf: 5  cr: 0   - file: b.txt hunk: 1
   DEBUG -  1 hunks for a.txt
   DEBUG total files: 1  total hunks: 1
   DEBUG normalize filenames
   DEBUG     patch type = plain
   DEBUG     source = a.txt
   DEBUG     target = b.txt
   DEBUG processing 1/1:     a.txt
   DEBUG  hunk no.1 for file a.txt  -- is ready to be patched
 WARNING can't backup original file to a.txt.orig - aborting
Success!

$ cat a.txt
1
2
3

but the program will exit successfully instead of returning an error.