LibGit2: fix resource leaks in checkout!
The GitObject, peeled GitCommit, and GitReference created during
checkout were never closed, leaking C pointers. Wrap them in
try/finally blocks to ensure proper cleanup.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>