Skip to content

Commit 1d5d745

Browse files
zeripathlafriksguillep2ksapk
authored
Convert plumbing.ErrObjectNotFound to git.ErrNotExist in getCommit (#10862) (#10868)
Backport #10862 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: guillep2k <[email protected]> Co-authored-by: Antoine GIRARD <[email protected]>
1 parent 3dabfd4 commit 1d5d745

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/git/repo_commit.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"strconv"
1313
"strings"
1414

15-
"github.com/mcuadros/go-version"
1615
"github.com/go-git/go-git/v5/plumbing"
1716
"github.com/go-git/go-git/v5/plumbing/object"
17+
"github.com/mcuadros/go-version"
1818
)
1919

2020
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
@@ -94,9 +94,15 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
9494
gogitCommit, err := repo.gogitRepo.CommitObject(id)
9595
if err == plumbing.ErrObjectNotFound {
9696
tagObject, err = repo.gogitRepo.TagObject(id)
97+
if err == plumbing.ErrObjectNotFound {
98+
return nil, ErrNotExist{
99+
ID: id.String(),
100+
}
101+
}
97102
if err == nil {
98103
gogitCommit, err = repo.gogitRepo.CommitObject(tagObject.Target)
99104
}
105+
// if we get a plumbing.ErrObjectNotFound here then the repository is broken and it should be 500
100106
}
101107
if err != nil {
102108
return nil, err

0 commit comments

Comments
 (0)