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个分支,我如何获得分支的新列表?

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)
//...

我使用的是v0.27.0,以下适用于我:

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

最新更新