-
Notifications
You must be signed in to change notification settings - Fork 811
Closed
Description
So I'm trying to checkout by the tag commit id. Basically I get the tag, its hash then do a checkout. Like this.
err = w.Checkout(&git.CheckoutOptions{
Hash: commitHash,
Force: true,
})
I've verified the working directory has the commit, even checked objects folder by unpacking the repo I'm working with. I'm also able to checkout using the command line.
I tracked down the issue to this here. Here is the order
- Checkout will call Reset which calls ResetSparsely.
- ResetSparsely will then call getTreeFromCommitHash.
Line 307 in 5d08d3b
t, err := w.r.getTreeFromCommitHash(opts.Commit) - getTreeFromCommitHash will call r.CommitObject which then calls object.GetCommit.
https://github.com/go-git/go-git/blob/master/repository.go#L1424 - GetCommit will then call s.EncodedObject. https://github.com/go-git/go-git/blob/master/plumbing/object/commit.go#L70
- This is where it fails. It seems based off the hash, the object that is retrieved from the pack or objects folder is a TabObject. However, it will fail on the last "IF" check because it expects a commit object. Due to the two types be different it returns an error.
func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
var obj plumbing.EncodedObject
var err error
if s.index != nil {
obj, err = s.getFromPackfile(h, false)
if err == plumbing.ErrObjectNotFound {
obj, err = s.getFromUnpacked(h)
}
} else {
obj, err = s.getFromUnpacked(h)
if err == plumbing.ErrObjectNotFound {
obj, err = s.getFromPackfile(h, false)
}
}
// If the error is still object not found, check if it's a shared object
// repository.
if err == plumbing.ErrObjectNotFound {
dotgits, e := s.dir.Alternates()
if e == nil {
// Create a new object storage with the DotGit(s) and check for the
// required hash object. Skip when not found.
for _, dg := range dotgits {
o := NewObjectStorage(dg, s.objectCache)
enobj, enerr := o.EncodedObject(t, h)
if enerr != nil {
continue
}
return enobj, nil
}
}
}
if err != nil {
return nil, err
}
if plumbing.AnyObject != t && obj.Type() != t {
return nil, plumbing.ErrObjectNotFound
}
return obj, nil
}
I'm wondering if this is a bug or if I'm going about the wrong way to checkout by tag.
3DA1
Metadata
Metadata
Assignees
Labels
No labels