使用 nodegit 获取两个标签之间的差异

Get diff between two tags with nodegit

如何使用 nodegit 获取两个标签之间的差异?

在命令行中,I can see the diff between two tags, no problemo

此外,我可以使用 nodegit 列出我的 repo 中的标签:

const Git = require('nodegit')
const path = require('path')

Git.Repository.open(path.resolve(__dirname, '.git'))
.then((repo) => {
  console.log('Opened repo ...')
  Git.Tag.list(repo).then((array) => {
    console.log('Tags:')
    console.log(array)
  })
})

但是,我不确定如何在 nodegit 中找到两个标签之间的差异。

我试过了,但是 Diff 部分没有打印任何内容:

const Git = require('nodegit')
const path = require('path')

Git.Repository.open(path.resolve(__dirname, '.git'))
.then((repo) => {
  console.log('Opened repo ...')
  Git.Tag.list(repo).then((array) => {
    console.log('Tags:')
    console.log(array)
    Git.Diff(array[0], array[1]).then((r) =>  {
      console.log('r', r)
    })
  })
})

查看最后两个标签的提交数据的方法如下:

nodegit.Repository.open(path.resolve(__dirname, '.git'))
  .then(repo => (
    nodegit.Tag.list(repo).then(tags => {
      return [
        tags[ tags.length - 1 ],
        tags[ tags.length - 2 ],
      ]
    })
    .then(tags => {
      console.log(tags)
      tags.forEach(t => {
        nodegit.Reference.lookup(repo, `refs/tags/${t}`)
        .then(ref => ref.peel(nodegit.Object.TYPE.COMMIT))
        .then(ref => nodegit.Commit.lookup(repo, ref.id()))
        .then(commit => ({
           tag: t,
           hash: commit.sha(),
           date: commit.date().toJSON(),
         }))
         .then(data => {
           console.log(data)
         })
      })
    })
  ))