There is this Git command where you can get a list of all remote branches
git ls-remote [url]
Is this possible with NodeGit?
@Mklueh I think you are referring to #1218?
Seems to go in the right direction, but I can麓t find anything in the documentation of NodeGit covering it.
I麓m looking for getting a list of all branches without checking the repository out locally
@Mklueh, I did it this way
Repository object_for simplify I skip promises (e.g. then())_
// /tmp/remote - is a repository directory and next specifies is_bar option
// this is like `git init --bare /tmp/remote`
const localRepository = NodeGit.Repository.init('/tmp/remote', 1);
Remote object of this repository// this is like `git remote add origin [email protected]:nodegit/nodegit.git`
const remoteRepository = NodeGit.Remote.create(localRepository, 'origin', '[email protected]:nodegit/nodegit.git');
remoteRepository.connect(NodeGit.Enums.DIRECTION.FETCH, {
certificateCheck() { return 1; },
credentials(url, username) {
return new NodeGit.Cred.sshKeyNew(username, '~/.ssh/github_rsa.pub', '~/.ssh/github_rsa', '');
}
});
const references = remoteRepository.referenceList();
references.forEach(reference => {
console.log(`${reference.name()}: ${reference.oid().toString()}`);
});
Result something like
HEAD: 6f7d38184c05acbfd616b550246420c7c5e7b9a9
refs/heads/master: 6f7d38184c05acbfd616b550246420c7c5e7b9a9
refs/heads/refactoring: 60404998ac705d662211266c4c3f49479c62c90b
Do you know how to get remote branch by name and delete it if exists?
I've tried
.then(() => nodegit.Remote.lookup(repo, 'origin'))
.then((remoteResult) => {
console.log('remote Configured');
remote = remoteResult;
return remote.connect(nodegit.Enums.DIRECTION.PUSH, callbacks);
})
.then(() => {
console.log('remote Connected?', remote.connected());
return remote.push(
'refs/heads/' + branchName
);
})
But does not work. please helper me out. thanks
If you want find out all the remote branch based on local repo
const listRemoteBranch = async (pathToRepo) => {
const repo = await NodeGit.Repository.open(pathToRepo);
const refs = await repo.getReferences();
const remoteRefs = refs.filter(r => r.isRemote() === 1);
return remoteRefs.map(r => r.name());
}
Most helpful comment
@Mklueh, I did it this way
Repositoryobject_for simplify I skip promises (e.g. then())_
Remoteobject of this repositoryResult something like