diff --git a/generate/input/callbacks.json b/generate/input/callbacks.json index 6c5837c31..708edc27e 100644 --- a/generate/input/callbacks.json +++ b/generate/input/callbacks.json @@ -273,7 +273,11 @@ "git_note_foreach_cb": { "args": [ { - "name": "id", + "name": "blob_id", + "cType": "const git_oid *" + }, + { + "name": "annotated_object_id", "cType": "const git_oid *" }, { @@ -283,7 +287,7 @@ ], "return": { "type": "int", - "noResults": 1, + "noResults": 0, "success": 0, "error": -1 } diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 75b886330..01f2a5f49 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -960,8 +960,17 @@ } } }, + "git_note_remove": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_note_foreach": { - "ignore": true + "isAsync": true, + "return": { + "isErrorCode": true + } } } }, diff --git a/lib/note.js b/lib/note.js new file mode 100644 index 000000000..4f3ff76bb --- /dev/null +++ b/lib/note.js @@ -0,0 +1,16 @@ +var NodeGit = require("../"); + +var Note = NodeGit.Note; + +// Override Note.foreach to eliminate the need to pass null payload +var foreach = Note.foreach; +Note.foreach = function(repo, notesRef, callback) { + function wrapperCallback(blobId, objectId) { + // We need to copy the OID since libgit2 types are getting cleaned up + // incorrectly right now in callbacks + + return callback(blobId.copy(), objectId.copy()); + } + + return foreach(repo, notesRef, wrapperCallback, null); +}; diff --git a/test/tests/note.js b/test/tests/note.js new file mode 100644 index 000000000..1624714e7 --- /dev/null +++ b/test/tests/note.js @@ -0,0 +1,69 @@ +var assert = require("assert"); +var path = require("path"); +var local = path.join.bind(path, __dirname); + +describe("Note", function() { + var NodeGit = require("../../"); + var Note = NodeGit.Note; + var Signature = NodeGit.Signature; + var reposPath = local("../../"); + + beforeEach(function() { + var test = this; + + return NodeGit.Repository.open(reposPath).then(function(repository) { + test.repository = repository; + + return repository.getMasterCommit().then(function(commit) { + test.commit = commit; + }); + }); + }); + + it("can be created", function() { + var sha = this.commit.id(); + var sig = Signature.create("John", "john@doe.com", Date.now(), 0); + var noteRef = "refs/notes/commits"; + + return Note.create(this.repository, noteRef, sig, sig, sha, "Testing!", 1); + }); + + it("can be read", function() { + var sha = this.commit.id(); + var noteRef = "refs/notes/commits"; + + return Note.read(this.repository, noteRef, sha).then(function(note) { + assert.equal(note.message(), "Testing!"); + }); + }); + + it("can iterate all notes", function() { + var test = this; + var noteRef = "refs/notes/commits"; + var ref = null; + + return Note.foreach(this.repository, noteRef, function(blobId, objectId) { + ref = objectId; + }).then(function() { + return NodeGit.Note.read(test.repository, noteRef, ref) + .then(function(note) { + assert.equal(note.message(), "Testing!"); + }); + }); + }); + + it("can be removed", function(done) { + var test = this; + var sha = this.commit.id(); + var noteRef = "refs/notes/commits"; + var sig = Signature.create("John", "john@doe.com", Date.now(), 0); + + return Note.remove(this.repository, noteRef, sig, sig, sha) + .then(function() { + return Note.read(test.repository, noteRef, sha).catch(function(ex) { + assert.equal(ex.message, "Note could not be found"); + done(); + }); + }); + }); +});