Description
Trying to do a pygit2 equivalent of git checkout
's refish resolving, and found libgit2's checkout
example:
-
It initially calls
resolve_refish()
which callsgit_reference_dwim()
which does a whole set of ref lookups (refs, heads, tags, branches, remotes, etc). That isn't available in pygit2 AFAICS. Returns an annotated commit, which seems to be a commit + the ref it was resolved from? -
then gets the actual commit, which is straightforward enough
-
then does the checkout
-
and finally updates HEAD using the annotated commit ref to decide whether the head is detached or not. This seems to be covered (a bit unintuitively) in pygit2 by passing a string vs oid to
repo.set_head()
So...
Q1: I wonder whether we should be preferring/helping get annotated commits when we're looking up references so the user can get back to their ref easily. We could be more aggressive about this than libgit2? eg: make AnnotatedCommit a subclass of Commit, and automatically use the underlying git_commit for APIs that need it.
Q2: Would adding support for git_reference_dwim()
be a good idea? That returns references, so at least you could maintain a (reference, commit) pair in Python and do
Q3: Would adding a Repository.resolve_refish()
method (similarly to revparse_single()
) be useful? I think revparse_single()
resolves all "commitish" properly?