Reading Git config variable using NodeGit

丶灬走出姿态 提交于 2020-02-03 04:55:09

问题


NodeGit does not seem to be providing any API to retrieve Git configuration values.

See http://www.nodegit.org/#Config

I was expecting something like Config#getValue() or similar API to retrieve configuration values.

Perhaps, it is missing in NodeGit as of now, since libgit2 has those APIs.

Any hints?


回答1:


NodeGit currently doesn't expose the config functionality of libgit2. That shouldn't be too hard to get in there but I don't know if it'll make into the 0.3.0 release that is scheduled for the next release.

I created an issue that you can track if you want updates on the progress of it.




回答2:


Here's an example to get a global git config variable:

var nodegit = require("nodegit");

nodegit.Config.openDefault()
  .then(function (config) {
    return config.getStringBuf('user.name');
  })
  .then(console.log);

and here's how to get a repository's config variable:

nodegit.Repository.open('PATH_TO_REPO')
  .then(function (repository) {
    return repository.config();
  })
  .then(function (config) {
    return config.getStringBuf('user.name');
  })
  .then(console.log);


来源:https://stackoverflow.com/questions/28806392/reading-git-config-variable-using-nodegit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!