I have this:
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 the tagName is just an alias to a commit but it gives me an error if the tag is a proper Tag created with nodegit:
the requested type does not match the type in the ODB
When using 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 from this tag reference to the commit itself (c465e) ?
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(),
  }))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With