使用NodeJS获取git远程信息

时间:2016-06-16 08:04:06

标签: node.js git

我必须使用NodeJS获取远程git信息。我已设法使用simple-git从克隆的回购中获取信息。我测试的代码如下:

require('simple-git')('/my/local/git/repo/path')
    .pull()
    .tags(function(err, tags) {
       console.log("These are my tags: %s", tags.all);
});

但是,它需要在当地克隆回购。是否有任何方法(使用此模块或其他模块)连接远程git以获取此信息?

1 个答案:

答案 0 :(得分:2)

您需要指定任何有效仓库的路径,或者将其视为空,因为git repo位于当前目录下。这只需要使命令有效。

之后,您可以通过以下方式使用listRemote方法:

require('simple-git')([optional path])
   // .init() - in case it's totally empty folder
  .addRemote('remote_repo_alias', 'path/to/remote/repo')
  .listRemote(['--tags', 'remote_repo_alias'], function(err, tags) {
    // ...
  });
相关问题