I am trying to replicate the behaviour of the command "git checkout (commit)" where (commit) is the reference to as specific commit and not a branch name.
When using this command, the 'HEAD' of the repository point to the commit (detached head) and the working directory is in the same state that it was in this commit.
For the moment, I managed to make the HEAD of the repository point to a commit with PyGit2 :
def go(self, repo_name, version):
repo = pygit2.Repository(bdd[repo_name])
#commit = repo.revparse_single(version)
#repo.reset(version, pygit2.GIT_RESET_HARD)
repo.set_head(pygit2.Oid(hex=version))
print repo.head_is_detached
My problem is that I can't find how to rollback the working directory like the Git CLI does. I tried using:
repo.checkout_head()
: It doesn't do anything on the working directory.repo.checkout()
: Crash with aGitError: X conflicts prevent checkout
Is there a way to replicate this behaviour without using Repository.reset(ref, pygit2.GIT_RESET_HARD)
?