I can't seem to figure out how to get a git_reference * to a particular remote's HEAD.
I've got:
git_repository * repo = NULL;
git_reference * ref = NULL;
/* ...load repository... */
if(git_reference_lookup(&ref, repo, "remotes/origin/HEAD"))
printf("Error obtaining reference to remote HEAD!");
The error message is displayed when the application is run, indicating that the reference wasn't found. However, the remote HEAD does indeed exist:
$: find .git/refs/* .git/refs/heads .git/refs/heads/master .git/refs/remotes .git/refs/remotes/origin .git/refs/remotes/origin/HEAD .git/refs/tags
Why can't I obtain a git_reference * to the remote HEAD?
You need to specify a full path to the reference. For example:
int error = git_reference_lookup(&ref, repo, "refs/remotes/origin/HEAD");
libgit2 could not prefix refs/ for you, or else you would be unable to open references in other places, most notably the HEAD reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With