Получить diff между двумя тегами с помощью nodegit
Как я могу получить разницу между двумя тегами, используя nodegit?
В командной строке я вижу разницу между двумя тегами, никаких проблем.
Кроме того, я могу использовать nodegit для перечисления тегов в моем репо:
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)
})
})
})
1 ответ
Решение
Вот как вы можете увидеть данные фиксации для последних двух тегов:
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)
})
})
})
))