使用NodeGit读取Git配置变量

时间:2015-03-02 09:31:07

标签: node.js git nodegit

NodeGit似乎没有提供任何API来检索Git配置值。

请参阅http://www.nodegit.org/#Config

我期待像Config#getValue()或类似的API来检索配置值。

也许,截至目前,NodeGit中缺少它,因为libgit2具有这些API。

任何提示?

2 个答案:

答案 0 :(得分:1)

NodeGit当前不是libgit2的expose the config functionality。这不应该太难进入,但我不知道它是否会进入下一版本的0.3.0版本。

我创建了一个issue,您可以跟踪它是否需要更新其进度。

答案 1 :(得分:1)

以下是获取全局git配置变量的示例:

var nodegit = require("nodegit");

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

以及如何获取存储库的配置变量:

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