aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-03-23 13:01:25 +0000
committerGitHub <noreply@github.com>2020-03-23 15:01:25 +0200
commit3dabfd493372e693b6905d08ec2fb22abaed8ae7 (patch)
tree0bedf9e5ab6c65bc5fbf76e073c3db97b0a7e594
parent6ee67312909d2ccfa47496d50bf46e0665902b2d (diff)
downloadgitea-3dabfd493372e693b6905d08ec2fb22abaed8ae7.tar.gz
gitea-3dabfd493372e693b6905d08ec2fb22abaed8ae7.zip
Convert plumbing.ErrReferenceNotFound to git.ErrNotExist in GetRefCommitID (#10676) (#10797)
* Fix panic in API pulls when headbranch does not exist (#10676) Backport #10676 * Fix panic in API pulls when headbranch does not exist * refix other reference to plumbing.ErrReferenceNotFound Signed-off-by: Andrew Thornton <art27@cantab.net> * Apply suggestions from code review Co-Authored-By: Lauris BH <lauris@nix.lv>
-rw-r--r--modules/git/repo_commit.go7
-rw-r--r--routers/repo/branch.go4
2 files changed, 7 insertions, 4 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 0181f86bfe..52f2d27703 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -12,15 +12,20 @@ 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).
func (repo *Repository) GetRefCommitID(name string) (string, error) {
ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true)
if err != nil {
+ if err == plumbing.ErrReferenceNotFound {
+ return "", ErrNotExist{
+ ID: name,
+ }
+ }
return "", err
}
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index 5a020a8e85..c33242b9ba 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -16,8 +16,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/util"
-
- "github.com/go-git/go-git/v5/plumbing"
)
const (
@@ -253,7 +251,7 @@ func loadBranches(ctx *context.Context) []*Branch {
repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo
}
pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
- if err != nil && err != plumbing.ErrReferenceNotFound {
+ if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommitID", err)
return nil
}