Open pablocompagni-contractorvp opened 1 year ago
I do this as following
func Checkout(repo *git.Repository, branch *git.Branch) error {
branchName, err := branch.Name()
if err != nil {
return err
}
commit, err := repo.LookupCommit(branch.Target())
if err != nil {
return err
}
defer commit.Free()
tree, err := repo.LookupTree(commit.TreeId())
if err != nil {
return err
}
defer tree.Free()
err = repo.CheckoutTree(tree, &git.CheckoutOptions{
Strategy: git.CheckoutForce,
})
if err != nil {
return err
}
err = repo.SetHead("refs/heads/" + branchName)
if err != nil {
return err
}
return nil
}
Looking at this issue it seems this should be a branch switch and then a checkout, but I just can't figure out how to do it. https://github.com/libgit2/git2go/issues/291
I've tried doing this:
and this:
But they both end up with a detached head. I've also tried, based on the suggestions from the other ticket, to do this:
But this just throws and error.