Browse Source

Fix panic in API pulls when headbranch does not exist (#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>
for-closed-social
zeripath 4 years ago
committed by GitHub
parent
commit
3fc4f3670c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions
  1. +1
    -1
      modules/convert/pull.go
  2. +5
    -0
      modules/git/repo_commit.go
  3. +1
    -2
      routers/repo/branch.go

+ 1
- 1
modules/convert/pull.go View File

@ -114,7 +114,7 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
if git.IsErrBranchNotExist(err) { if git.IsErrBranchNotExist(err) {
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref) headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
if err != nil && !git.IsErrNotExist(err) { if err != nil && !git.IsErrNotExist(err) {
log.Error("GetCommit[%s]: %v", headBranch.Name, err)
log.Error("GetCommit[%s]: %v", pr.HeadBranch, err)
return nil return nil
} }
if err == nil { if err == nil {

+ 5
- 0
modules/git/repo_commit.go View File

@ -21,6 +21,11 @@ import (
func (repo *Repository) GetRefCommitID(name string) (string, error) { func (repo *Repository) GetRefCommitID(name string) (string, error) {
ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true) ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true)
if err != nil { if err != nil {
if err == plumbing.ErrReferenceNotFound {
return "", ErrNotExist{
ID: name,
}
}
return "", err return "", err
} }

+ 1
- 2
routers/repo/branch.go View File

@ -17,7 +17,6 @@ import (
"code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/repofiles"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"gopkg.in/src-d/go-git.v4/plumbing"
) )
const ( const (
@ -253,7 +252,7 @@ func loadBranches(ctx *context.Context) []*Branch {
repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo
} }
pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName()) pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil && err != plumbing.ErrReferenceNotFound {
if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommitID", err) ctx.ServerError("GetBranchCommitID", err)
return nil return nil
} }

Loading…
Cancel
Save