1. I think the `git_obj` that gets created here is leaked. You'll have to call `git_object_free(git_obj)` on it before returning.
2. Instead of calling `git_revparse_single` which has to parse the reference name with no context (and instead of using the shorthand which I think is theoretically ambiguous), you probably just want to call `git_reference_peel` to get the object.

FWIW, in libgit2, we would probably write this as:

```c
git_reference *ref = NULL;
git_object *git_obj = NULL;
int error;

if (!(error = git_reference_lookup(&ref, repo, refName)) &&
    !(error = git_reference_peel(&git_obj, ref, GIT_OBJ_TREE)) &&
    !(error = git_checkout_tree(repo, git_obj, &opts)))
    error = git_repository_set_head(repo, refName);

git_object_free(git_obj); git_obj = NULL;
git_reference_free(ref); ref = NULL;

if (!error)
    return scope.Close(Boolean::New(true));
```

That may not be idiomatic for the code you're writing here, but I thought I'd point it out. It takes advantage of the fact that calling `git_XYZ_free(...)` on a NULL pointer is always a no-op in libgit2.