build safe convenience wrapper for git_remote_ls#1218
build safe convenience wrapper for git_remote_ls#1218implausible merged 9 commits intonodegit:masternodegit/nodegit:masterfrom implausible:feature/git_remote_lsimplausible/nodegit:feature/git_remote_lsCopy head branch name to clipboard
Conversation
| baton->proxy_opts, | ||
| baton->custom_headers | ||
| ); | ||
| baton->error_code = git_remote_connect( |
There was a problem hiding this comment.
Instead of connecting (and disconnecting) as part of ReferenceList, it could be just a wrapper over git_remote_ls, and that way the user can use it with an already connected remote.
| } | ||
| else if (baton->error_code < 0) | ||
| { | ||
| Local<v8::Object> err = Nan::Error("Method next has thrown an error.")->ToObject(); |
There was a problem hiding this comment.
"Method next has thrown an error." seems like the wrong error here.
| dest->local = src->local; | ||
| git_oid_cpy(&dest->oid, &src->oid); | ||
| git_oid_cpy(&dest->loid, &src->loid); | ||
| dest->name = strdup(src->name); |
There was a problem hiding this comment.
a null-check here like you have below wouldn't hurt
There was a problem hiding this comment.
I think it's always supposed to be defined, but you're right, we should err on the side of safety 🤦♂️.
lib/remote.js
Outdated
| * Lists advertised references from a remote | ||
| * | ||
| * @async | ||
| * @return {Promise<Array<RemoteHead>>} a list of the remote heads currently |
There was a problem hiding this comment.
"currently available" might be a little off - isn't it more like what the remote had available when the connection was established?
|
is there a way to use this but for a specific branch? |
|
Can sb please tell me how to use this? I can´t find it in the documentation Just want to get a list of all remote branches from remote without fetching anything like "git ls-remote git@...." |
|
@mklueh Looking at the unit test helps :) Looks like a function on the response: |
Documentation for
git_remote_lsshows that for it to work, a connection must be established to a remote first. When a subsequent connection is made, retrieved remote heads are destroyed and replaced with a new set.This manual template locks the remote during execution of 3 actions (git_remote_connect, git_remote_ls, git_remote_disconnect) and copies all the data retrieved from git_remote_ls into memory for nodegit consumption.
The other contributing factor for using a manual template here is git_remote_ls has the only triple pointer use case in libgit2, so writing additional handlers for one case is overkill, especially when considering the volatility of the memory being retrieved. Complications that will exist if there is ever a good reason to build triple pointer handling into our generation system will be handling the bounds of the retrieved double pointer, as there will probably be a corresponding size argument.