使用 NodeGit 读取 Git 配置变量

Reading Git config variable using NodeGit

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

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

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

也许,它现在在 NodeGit 中丢失了,因为 libgit2 有那些 APIs。

有什么提示吗?

NodeGit 目前没有 expose the config functionality libgit2。这应该不难进入,但我不知道它是否会进入计划在下一个版本中发布的 0.3.0 版本。

我创建了一个 issue 如果你想更新它的进度,你可以跟踪它。

这是获取全局 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);