I'd like to be able to check what's the latest tag for a given repo (I'm using CPython here as an example).
The following works:
g = git.cmd.Git()
blob = g.ls_remote('https://github.com/python/cpython', sort='-v:refname', tags=True)
blob.split('\n')[0].split('/')[-1] # 'v3.9.0a6'
because the blob
looks something like this:
'bc1c8af8ef2563802767404c78c8ec6d6a967897\trefs/tags/v3.9.0a6\ndcd4 (...)'
But: is there a cleaner way of getting the latest tag?
Preferably using gitpython
but any other package is also OK.
git ls-remote
is a stable and documented command of the git suite, so parsing its output is already a valid and stable way to get the info you need.
(I dug out a release note which specifies is was rewritten in C in version 1.5.4 (released somewhere in 2007-2008), which implies it already existed as a script in previous versions)
AFAIK, there isn't yet a python wrapper around it to find the existence or value of said reference through python methods, but the implementation of said methods would look a lot like what you wrote yourself.
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