Files
DIY_GIT_in_Python/how_to/Change_23.md
2024-04-20 21:37:31 +02:00

794 B
Raw Blame History

  • tag: Resolve name to oid in argparse

Its nice that we can create tags, but now lets actually make them usable from the CLI.

In base.py, well create get_oid to resolve a “name” to an OID. A name can either be a ref (in which case get_oid will return the OID that the ref points to) or an OID (in which case get_oid will just return that same OID).

Next, well modify the argument parser in cli.py to call get_oid on all arguments which are expected to be an OID. This way we can pass a ref there instead of an OID.

At this point we can do something like:

$ ugit tag mytag d8d43b0e3a21df0c845e185d08be8e4028787069
$ ugit log refs/tags/mytag
# Will print log of commits starting at d8d43b0e...
$ ugit checkout refs/tags/mytag
# Will checkout commit d8d43b0e...
etc...