2
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 ?

Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31
Jason Wong
  • 216
  • 3
  • 14

2 Answers2

1

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)
//...
Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
0

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
})
patwis
  • 136
  • 1
  • 13