如何使用 Revparse 和 nodegit 获取提交和树?
How to get commit and tree using Revparse with nodegit?
我正在尝试使用 nodegit 获取基于引用的提交树或使用 Revparse 的 oid,我认为以下代码可以工作,但是我收到 getTree 未定义错误:
return git.Repository.open(path_to_repo)
.then((repo) => git.Revparse.single(repo, "other"))
.then((commit) => commit.getTree());
如何将 Revparse 返回的对象转换为提交?
所以 RevParse.single
returns 一个 Object which really is just a low level libgit2 object. That will have to have its type checked to make sure it's an Object.TYPE.COMMIT
. If it is then you can grab the OID and use that to get the actual Commit.
由于 NodeGit 实际上只是绑定到 libgit2,因此(目前)没有任何方法可以真正将对象从一个事物转换为另一个事物。您必须自己进行查找。
现在,如果您只是想获取给定引用指向的提交,您可以将代码修改为:
return git.Repository.open(path_to_repo)
.then((repo) => repo.getReferenceCommit("other"))
.then((commit) => commit.getTree());
我正在尝试使用 nodegit 获取基于引用的提交树或使用 Revparse 的 oid,我认为以下代码可以工作,但是我收到 getTree 未定义错误:
return git.Repository.open(path_to_repo)
.then((repo) => git.Revparse.single(repo, "other"))
.then((commit) => commit.getTree());
如何将 Revparse 返回的对象转换为提交?
所以 RevParse.single
returns 一个 Object which really is just a low level libgit2 object. That will have to have its type checked to make sure it's an Object.TYPE.COMMIT
. If it is then you can grab the OID and use that to get the actual Commit.
由于 NodeGit 实际上只是绑定到 libgit2,因此(目前)没有任何方法可以真正将对象从一个事物转换为另一个事物。您必须自己进行查找。
现在,如果您只是想获取给定引用指向的提交,您可以将代码修改为:
return git.Repository.open(path_to_repo)
.then((repo) => repo.getReferenceCommit("other"))
.then((commit) => commit.getTree());