diff options
author | zeripath <art27@cantab.net> | 2020-03-29 17:47:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 17:47:53 +0100 |
commit | 1d5d7458516a3f04d822cb35875a3050c12760af (patch) | |
tree | 2d296dc3a6d28e8580c3da570da68c9f9090e827 | |
parent | 3dabfd493372e693b6905d08ec2fb22abaed8ae7 (diff) | |
download | gitea-1d5d7458516a3f04d822cb35875a3050c12760af.tar.gz gitea-1d5d7458516a3f04d822cb35875a3050c12760af.zip |
Convert plumbing.ErrObjectNotFound to git.ErrNotExist in getCommit (#10862) (#10868)
Backport #10862
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
-rw-r--r-- | modules/git/repo_commit.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 52f2d27703..b7532a6db2 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -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). @@ -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 |