-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |