首页 > 解决方案 > 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 个分支,我怎样才能获得新的分支列表?

标签: javascriptnode.jsgitnodegit

解决方案


repository.getReferenceNames(Git.Reference.TYPE.LISTALL);可以是同义词

git show-ref命令。

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

您希望git fetch --all --prune在删除分支时运行 a 以删除远程中删除的远程跟踪引用。

取决于您的 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)
//...

推荐阅读