diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 90b06ed4a..05938ae73 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -524,7 +524,39 @@ ], "functions": { "git_diff_blob_to_buffer": { - "ignore": true + "args": { + "old_blob" : { + "isOptional": true + }, + "old_as_path" : { + "isOptional": true + }, + "buffer" : { + "isOptional": true + }, + "buffer_len" : { + "isOptional": true + }, + "buffer_as_path" : { + "isOptional": true + }, + "options" : { + "isOptional": true + }, + "file_cb" : { + "isOptional": true + }, + "hunk_cb" : { + "isOptional": true + }, + "line_cb" : { + "isOptional": true + } + }, + "return": { + "isErrorCode": true + }, + "isAsync": true }, "git_diff_blobs": { "ignore": true diff --git a/lib/diff.js b/lib/diff.js index 4761dfdfd..91f72d168 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -62,3 +62,31 @@ Diff.prototype.findSimilar = function(opts) { opts = normalizeOptions(opts, NodeGit.DiffFindOptions); return findSimilar.call(this, opts); }; + +var blobToBuffer = Diff.blobToBuffer; +Diff.blobToBuffer= function( + old_blob, + old_as_path, + buffer, + buffer_as_path, + opts, + file_cb, + hunk_cb, + line_cb) { + var bufferLength = !buffer ? 0 : buffer.length; + + opts = normalizeOptions(opts, NodeGit.DiffOptions); + + return blobToBuffer.call( + this, + old_blob, + old_as_path, + buffer, + bufferLength, + buffer_as_path, + opts, + file_cb, + hunk_cb, + line_cb, + null); +}; diff --git a/test/tests/diff.js b/test/tests/diff.js index dd8f6d8d8..66ab6b1c9 100644 --- a/test/tests/diff.js +++ b/test/tests/diff.js @@ -145,6 +145,38 @@ describe("Diff", function() { }); }); + it("can diff the contents of a file to a string", function(done) { + this.repository.getBranchCommit("master") + .then(function(commit) { + return commit.getEntry("LICENSE"); + }) + .then(function(entry) { + var _entry = entry; + return _entry.getBlob(); + }) + .then(function(blob) { + var buffer = "New Text"; + return Diff.blobToBuffer( + blob, + null, + buffer, + null, + null, + null, + function(delta, hunk, payload) { + assert.equal(hunk.oldStart(), 1); + assert.equal(hunk.oldLines(), 19); + assert.equal(hunk.newStart(), 1); + assert.equal(hunk.newLines(), 1); + assert.equal( + hunk.header().substring(0, hunk.headerLen() - 1), + "@@ -1,19 +1 @@" + ); + done(); + }); + }); + }); + it("can diff with a null tree", function() { var repo = this.repository; var tree = this.masterCommitTree;