Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert plumbing.ErrObjectNotFound to git.ErrNotExist in getCommit (#10862) #10868

Merged
merged 2 commits into from Mar 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion modules/git/repo_commit.go
Expand Up @@ -12,9 +12,9 @@ import (
"strconv"
"strings"

"github.com/mcuadros/go-version"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/mcuadros/go-version"
)

// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
Expand Down Expand Up @@ -94,9 +94,15 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
gogitCommit, err := repo.gogitRepo.CommitObject(id)
if err == plumbing.ErrObjectNotFound {
tagObject, err = repo.gogitRepo.TagObject(id)
if err == plumbing.ErrObjectNotFound {
return nil, ErrNotExist{
ID: id.String(),
}
}
if err == nil {
gogitCommit, err = repo.gogitRepo.CommitObject(tagObject.Target)
}
// if we get a plumbing.ErrObjectNotFound here then the repository is broken and it should be 500
}
if err != nil {
return nil, err
Expand Down