如何使用nodegit从标签名称获取提交信息?

gas*_*ard 5 javascript nodegit

我有这个:

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(),
  }))
Run Code Online (Sandbox Code Playgroud)

如果tagName只是提交的别名,则此代码有效,但是如果标记是使用nodegit创建的正确标记,则会给我一个错误:

the requested type does not match the type in the ODB
Run Code Online (Sandbox Code Playgroud)

使用git show [tagname]时显示如下:

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)
Run Code Online (Sandbox Code Playgroud)

那么,如何从该标记引用到提交本身(c465e)?

gas*_*ard 5

使用peel(type)作品:

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(),
  }))
Run Code Online (Sandbox Code Playgroud)