src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 541 forks source link

Error: object not found when git pull origin refs/tags/mytag #1229

Open miltalex opened 4 years ago

miltalex commented 4 years ago

Hi,

I get the Error: object not found when I try to git pull from a tag:

err = w.Pull(&git.PullOptions{
        RemoteName:    "origin",
        ReferenceName: plumbing.ReferenceName("/refs/tags/mytag"),
    })

Any help appreciated.

tshak commented 4 years ago

Are you using a shallow clone? If so shallow clones are broken (https://github.com/src-d/go-git/issues/1143). Even without shallow cloning, this can still happen on occasion. This appears related to https://github.com/src-d/go-git/issues/1151. Here's my error handling:

// plumbing.ErrObjectNotFound is a work around for https://github.com/src-d/go-git/issues/1151
if err != nil && err != git.NoErrAlreadyUpToDate && err != plumbing.ErrObjectNotFound {
  return err
}

I hope this helps.