Skip to content

Commit 3dabfd4

Browse files
zeripathlafriks
andauthored
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 <[email protected]> * Apply suggestions from code review Co-Authored-By: Lauris BH <[email protected]>
1 parent 6ee6731 commit 3dabfd4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

modules/git/repo_commit.go

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

15+
"github.com/mcuadros/go-version"
1516
"github.com/go-git/go-git/v5/plumbing"
1617
"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).
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)