Skip to content

Commit

Permalink
Merge 2cef5b5 into 8cf3063
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Apr 18, 2015
2 parents 8cf3063 + 2cef5b5 commit d7cbfb6
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
8 changes: 6 additions & 2 deletions generate/input/callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
},
{
Expand All @@ -283,7 +287,7 @@
],
"return": {
"type": "int",
"noResults": 1,
"noResults": 0,
"success": 0,
"error": -1
}
Expand Down
11 changes: 10 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,17 @@
}
}
},
"git_note_remove": {
"isAsync": true,
"return": {
"isErrorCode": true
}
},
"git_note_foreach": {
"ignore": true
"isAsync": true,
"return": {
"isErrorCode": true
}
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions lib/note.js
Original file line number Diff line number Diff line change
@@ -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);
};
69 changes: 69 additions & 0 deletions test/tests/note.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});

0 comments on commit d7cbfb6

Please sign in to comment.