Как получить коммит sha из имени тега с помощью 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(),
  }))

Этот код работает, если tagName является просто псевдонимом коммита, но выдает ошибку, если тег является правильным Tag, созданным с помощью nodegit:

the requested type does not match the type in the ODB

Когда используешь 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)

Итак, как мне получить ссылку на этот тег на сам коммит (c465e)?

1 ответ

С помощью 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(),
  }))
Другие вопросы по тегам