Skip to content

Commit 855a9e0

Browse files
committed
Enable note foreach and remove async
And added testing goodness!
1 parent cc99947 commit 855a9e0

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

generate/input/callbacks.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@
273273
"git_note_foreach_cb": {
274274
"args": [
275275
{
276-
"name": "id",
276+
"name": "blob_id",
277+
"cType": "const git_oid *"
278+
},
279+
{
280+
"name": "annotated_object_id",
277281
"cType": "const git_oid *"
278282
},
279283
{
@@ -283,7 +287,7 @@
283287
],
284288
"return": {
285289
"type": "int",
286-
"noResults": 1,
290+
"noResults": 0,
287291
"success": 0,
288292
"error": -1
289293
}

generate/input/descriptor.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,17 @@
944944
}
945945
}
946946
},
947+
"git_note_remove": {
948+
"isAsync": true,
949+
"return": {
950+
"isErrorCode": true
951+
}
952+
},
947953
"git_note_foreach": {
948-
"ignore": true
954+
"isAsync": true,
955+
"return": {
956+
"isErrorCode": true
957+
}
949958
}
950959
}
951960
},

lib/note.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var NodeGit = require("../");
2+
3+
var Note = NodeGit.Note;
4+
5+
// Override Note.foreach to eliminate the need to pass null payload
6+
var foreach = Note.foreach;
7+
Note.foreach = function(repo, notesRef, callback) {
8+
return foreach(repo, notesRef, callback, null);
9+
};

test/tests/note.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe("Note", function() {
66
var NodeGit = require("../../");
77
var Note = NodeGit.Note;
88
var Signature = NodeGit.Signature;
9-
var reposPath = local("../repos/merge");
9+
var reposPath = local("../../");
1010

1111
beforeEach(function() {
1212
var test = this;
@@ -37,16 +37,33 @@ describe("Note", function() {
3737
});
3838
});
3939

40+
it("can iterate all notes", function() {
41+
var test = this;
42+
var noteRef = "refs/notes/commits";
43+
var ref = null;
44+
45+
return Note.foreach(this.repository, noteRef, function(blobId, objectId) {
46+
ref = objectId;
47+
}).then(function() {
48+
return NodeGit.Note.read(test.repository, noteRef, ref)
49+
.then(function(note) {
50+
assert.equal(note.message(), "Testing!");
51+
});
52+
});
53+
});
54+
4055
it("can be removed", function(done) {
56+
var test = this;
4157
var sha = this.commit.id();
4258
var noteRef = "refs/notes/commits";
4359
var sig = Signature.create("John", "john@doe.com", Date.now(), 0);
4460

45-
Note.remove(this.repository, noteRef, sig, sig, sha);
46-
47-
return Note.read(this.repository, noteRef, sha).catch(function(ex) {
48-
assert.equal(ex.message, "Note could not be found");
49-
done();
50-
});
61+
return Note.remove(this.repository, noteRef, sig, sig, sha)
62+
.then(function() {
63+
return Note.read(test.repository, noteRef, sha).catch(function(ex) {
64+
assert.equal(ex.message, "Note could not be found");
65+
done();
66+
});
67+
});
5168
});
5269
});

0 commit comments

Comments
 (0)