简体   繁体   中英

Get git remote info using NodeJS

I have to get remote git information using NodeJS. I have managed to get info from a cloned repo using simple-git . The code I have test is the following:

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

However, it requires the repo to be locally cloned. Is there any way (using this or another module) to connect the remote git to get this info?

You need to specify the path to any valid repo or leave it empty considered git repo is under current directory. That's just required to make commands worked.

After that you can use listRemote method in the following way:

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) {
    // ...
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM