repo_handle.getTagByName('v0.0.1').then(function (tag) {
永远不会开始。试着这样做:
git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});
来自asker的更新
对于那些后来发现这一点的人来说,实际的问题是
repo_handle.Tag
是未定义的,由于添加了
catch
对于错误,因此接受这个答案。
有效的新更新代码如下所示:
let nodegit = require('nodegit');
let path = require('path');
var repo_root = path.resolve(__dirname, './.git');
let repo = null;
nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});