git_checkout_head() doesn't do anything (in practice) · Issue #2864 · libgit2/libgit2 · GitHub
Skip to content

git_checkout_head() doesn't do anything (in practice) #2864

Description

@swisspol

The doc says:

* Updates files in the index and the working tree to match the content of
* the commit pointed at by HEAD.

But since git_checkout_head() simply calls git_checkout_tree() with a NULL tree, the checkout code will use HEAD as a baseline and attempts to check out HEAD against it. In practice this means, no attempt will be made to touch modified files (whatever the mode) or create missing ones (unless you happen to be GIT_CHECKOUT_SAFE_CREATE mode).

As an example, if you move the HEAD to a different commit then call git_checkout_head() expecting the index and workdir to be updated to reflect the new commit (as per the docs), nothing happens (and there are no errors either of course).

Is there a bug in the implementation, is the doc wrong, or is it really the intended behavior of git_checkout_head()?

PS: If the latter, what's the actual and most efficient way using libgit2 to update the index and workdir to match the HEAD?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions