简体   繁体   中英

Nodegit How can I get new branch list?

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);
    })

I fetched all branches once (5 branches total), and I deleted one branch, local and remote, this still return 5 branches, but it should return 4 branches, how can I get new list of the branch ?

repository.getReferenceNames(Git.Reference.TYPE.LISTALL); can be synonymous with

git show-ref command.

This is using the references in .git/refs folder.

You want to run a git fetch --all --prune upon deleting the branch to remove remote tracking references that are removed in the remote.

Depending on your version of nodegit (for [v0.5.0] and up)

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

For older versions ( v0.4.1 - v0.3.0 )

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

I am using v0.27.0 and the following works for me:

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

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