Skip to content

Resolving "refish" #922

Closed
Closed
@rcoup

Description

@rcoup

Trying to do a pygit2 equivalent of git checkout's refish resolving, and found libgit2's checkout example:

  1. It initially calls resolve_refish() which calls git_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?

  2. then gets the actual commit, which is straightforward enough

  3. then does the checkout

  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions