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

applyPatch can't handle clearing the file #116

Closed
chaaz opened this issue May 29, 2016 · 0 comments · Fixed by #118
Closed

applyPatch can't handle clearing the file #116

chaaz opened this issue May 29, 2016 · 0 comments · Fixed by #118

Comments

@chaaz
Copy link
Contributor

chaaz commented May 29, 2016

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

Successfully merging a pull request may close this issue.

1 participant