In libgit2, how to resolve short ref name to get the full ref name or hash?
What libgit2 function need to be called?
In libgit2, how to resolve short ref name to get the full ref name
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
libgit2 supports the full extended SHA-1 syntax through the use of the
git_revparse_single()function. In order to retrieve the hash, just pass the retrieved object to thegit_object_id()function.Leveraging
git_revparse_single()will allow one to replicate following standard git command line usages:Libgit2 code:
For more information or examples about usage, you can peek at the unit tests.
Note: There’s currently no built-in exposed way to retrieve a canonical reference name from a short reference name.
Update
The amazing @CarlosMartinNieto made it happen.
Libgit2 now exposes
git_reference_dwimwhich retrieves a reference by its short name (e.g.master,heads/master, …)