Jason Huang
Jason Huang

Reputation: 216

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 ?

Upvotes: 2

Views: 359

Answers (2)

patwis
patwis

Reputation: 306

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

Upvotes: 0

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38982

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

Upvotes: 1

Related Questions