Nodegit如何获取新的分支列表?

时间:2018-11-14 08:45:12

标签: javascript node.js git nodegit

open(o.localPath).then(function (repo) {
        repository = repo;
        return repo.fetchAll(credentials);
    }).then(function () {
        return repository.getReferenceNames(Git.Reference.TYPE.LISTALL);
    }).then(function (arrayString) {
        console.log(arrayString);   
    }).catch(err => {
        reject(err);
    })

我获取了所有分支一次(总共5个分支),并且删除了一个本地和远程分支,这仍然返回5个分支,但是它应该返回4个分支,我如何获得该分支的新列表?

2 个答案:

答案 0 :(得分:1)

repository.getReferenceNames(Git.Reference.TYPE.LISTALL);可以与

同义

git show-ref命令。

这正在使用.git/refs文件夹中的引用。

您要在删除分支后运行git fetch --all --prune,以删除在远程站点中删除的远程跟踪引用。

取决于您的nodegit版本([v0.5.0]及更高版本)

//...
const fetchOptions = { callbacks: credentials, pruneAfter: true }
return repo.fetchAll(fetchOptions)
//...

对于较早的版本(v0.4.1-v0.3.0

//...
return repo.fetchAll(remoteCallbacks, true)
//...

答案 1 :(得分:0)

我使用的是 v0.27.0,以下对我有用:

repo.fetchAll({
  callbacks: {
    credentials(url, username) {
      return ...
    }
  },
  prune: Git.Fetch.PRUNE.GIT_FETCH_PRUNE
})
相关问题