How do I get the sha commit from a tag name using nodegit?
I have it:
nodegit.Reference
.lookup(repo, `refs/tags/${tagName}`)
.then(ref => nodegit.Commit.lookup(repo, ref.target()))
.then(commit => ({
tag: tagName,
hash: commit.sha(),
date: commit.date().toJSON(),
}))
This code works if tagName is just an alias for the commit, but it gives me an error if the tag is a valid tag created with nodegit:
the requested type does not match the type in the ODB
When used, git show [tagname]
it shows this:
tag release_2017-07-21_1413
Tagger: xxx
Date: Fri Jul 21 16:13:47 2017 +0200
commit c465e3323fc2c63fbeb91f9b9b43379d28f9b761 (tag: release_2017-07-21_1413, initialRelease)
So how do I get a link to that tag on the commit itself (c465e)?
+3
source to share
1 answer
Using peel(type)
works:
nodegit.Reference
.lookup(repo, `refs/tags/${tagName}`)
// This resolves the tag (annotated or not) to a commit ref
.then(ref => ref.peel(nodegit.Object.TYPE.COMMIT))
.then(ref => nodegit.Commit.lookup(repo, ref.id())) // ref.id() now
.then(commit => ({
tag: tagName,
hash: commit.sha(),
date: commit.date().toJSON(),
}))
+2
source to share