Skip to content

Commit c0730bf

Browse files
committed
Fix panic in API pulls when headbranch does not exist (go-gitea#10676)
Backport go-gitea#10676 * Fix panic in API pulls when headbranch does not exist * refix other reference to plumbing.ErrReferenceNotFound Signed-off-by: Andrew Thornton <[email protected]>
1 parent 6ee6731 commit c0730bf

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

modules/git/repo_commit.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ import (
1212
"strconv"
1313
"strings"
1414

15-
"github.com/go-git/go-git/v5/plumbing"
16-
"github.com/go-git/go-git/v5/plumbing/object"
1715
"github.com/mcuadros/go-version"
16+
"gopkg.in/src-d/go-git.v4/plumbing"
17+
"gopkg.in/src-d/go-git.v4/plumbing/object"
1818
)
1919

2020
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
2121
func (repo *Repository) GetRefCommitID(name string) (string, error) {
2222
ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true)
2323
if err != nil {
24+
if err == plumbing.ErrReferenceNotFound {
25+
return "", ErrNotExist{
26+
ID: name,
27+
}
28+
}
2429
return "", err
2530
}
2631

routers/repo/branch.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/repofiles"
1818
"code.gitea.io/gitea/modules/util"
19-
20-
"github.com/go-git/go-git/v5/plumbing"
2119
)
2220

2321
const (
@@ -253,7 +251,7 @@ func loadBranches(ctx *context.Context) []*Branch {
253251
repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo
254252
}
255253
pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
256-
if err != nil && err != plumbing.ErrReferenceNotFound {
254+
if err != nil && !git.IsErrNotExist(err) {
257255
ctx.ServerError("GetBranchCommitID", err)
258256
return nil
259257
}

0 commit comments

Comments
 (0)