-
Notifications
You must be signed in to change notification settings - Fork 521
Closed
Description
If a patch is supposed to completely erase a file, applyPatch
will instead keep the first line.
$ cat testfile
This
is
a
file,
yo
$ cat > testfile # empty the file out
$ cat testfile
$ git diff > diff.patch # create unified patch w/ git
$ cat diff.patch
diff --git a/testfile b/testfile
index c9d61c6..e69de29 100644
--- a/testfile
+++ b/testfile
@@ -1,5 +0,0 @@
-This
-is
-a
-file,
-yo
$ git checkout -- . # restore testfile
$ cat testfile
This
is
a
file,
yo
$ patch -p1 < diff.patch # test with 'patch'
patching file testfile
$ cat testfile # yep, worked
$ git checkout -- . # restore testfile again
$ cat patch.js
var fs = require('fs');
var diff = require('diff');
console.log(
diff.applyPatch(
fs.readFileSync('testfile', 'utf8'),
fs.readFileSync('diff.patch', 'utf8')
)
);
$ node patch.js # this should be empty
This
Metadata
Metadata
Assignees
Labels
No labels