From f0f8dfef68fa99d500ff8fbf3976f55e6fe23047 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 22 Mar 2015 01:13:41 -0400 Subject: [PATCH 1/3] Added Note tests Wanted to see if native code coverage would be affected. Yup! --- test/tests/note.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/tests/note.js diff --git a/test/tests/note.js b/test/tests/note.js new file mode 100644 index 000000000..0b1ca1db8 --- /dev/null +++ b/test/tests/note.js @@ -0,0 +1,52 @@ +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("../repos/merge"); + + 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 be removed", function(done) { + var sha = this.commit.id(); + var noteRef = "refs/notes/commits"; + var sig = Signature.create("John", "john@doe.com", Date.now(), 0); + + Note.remove(this.repository, noteRef, sig, sig, sha); + + return Note.read(this.repository, noteRef, sha).catch(function(ex) { + assert.equal(ex.message, "Note could not be found"); + done(); + }); + }); +}); From fab9237a544a01c1a34b99c0cf82132e3bbf2ab1 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 22 Mar 2015 01:41:44 -0400 Subject: [PATCH 2/3] Enable note foreach and remove async And added testing goodness! --- generate/input/callbacks.json | 8 ++++++-- generate/input/descriptor.json | 11 ++++++++++- lib/note.js | 9 +++++++++ test/tests/note.js | 31 ++++++++++++++++++++++++------- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 lib/note.js 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..40926f498 --- /dev/null +++ b/lib/note.js @@ -0,0 +1,9 @@ +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) { + return foreach(repo, notesRef, callback, null); +}; diff --git a/test/tests/note.js b/test/tests/note.js index 0b1ca1db8..1624714e7 100644 --- a/test/tests/note.js +++ b/test/tests/note.js @@ -6,7 +6,7 @@ describe("Note", function() { var NodeGit = require("../../"); var Note = NodeGit.Note; var Signature = NodeGit.Signature; - var reposPath = local("../repos/merge"); + var reposPath = local("../../"); beforeEach(function() { var test = this; @@ -37,16 +37,33 @@ describe("Note", function() { }); }); + 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); - Note.remove(this.repository, noteRef, sig, sig, sha); - - return Note.read(this.repository, noteRef, sha).catch(function(ex) { - assert.equal(ex.message, "Note could not be found"); - done(); - }); + 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(); + }); + }); }); }); From 2cef5b584bc81085333c47d0455570c030a7ded9 Mon Sep 17 00:00:00 2001 From: John Haley Date: Fri, 17 Apr 2015 21:17:33 -0700 Subject: [PATCH 3/3] Fix note tests --- lib/note.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/note.js b/lib/note.js index 40926f498..4f3ff76bb 100644 --- a/lib/note.js +++ b/lib/note.js @@ -5,5 +5,12 @@ 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) { - return foreach(repo, notesRef, callback, null); + 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); };