我们如何从 git 存储库获取标签并按相关提交日期对它们进行排序?
Tag.list 只返回名称,而 Tag.lookup 需要 OID,那么我们如何填写将标签名称转换为标签或标签 id 的缺失部分?
最佳答案
阅读... luagit2 文档(!)以实际了解 libgit 的工作原理后,这里有一个解决方案:
nodegit.Repository.open(repoPath).then(repo =>
nodegit.Tag.list(repo)
.then(list =>
Promise.all(
list.map(tagName =>
nodegit.Reference.lookup(repo, `refs/tags/${tagName}`)
.then(ref => nodegit.Commit.lookup(repo, ref.target()))
.then(commit => ({
tag: tagName,
date: commit.date().toJSON(),
}))
)
)
)
.then(tags => tags.sort((a, b) => (a.date < b.date ? -1 : 1)))
关于javascript - 如何使用nodegit按日期对标签进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44832548/