mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	* 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>
This commit is contained in:
		@@ -12,15 +12,20 @@ import (
 | 
				
			|||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/mcuadros/go-version"
 | 
				
			||||||
	"github.com/go-git/go-git/v5/plumbing"
 | 
						"github.com/go-git/go-git/v5/plumbing"
 | 
				
			||||||
	"github.com/go-git/go-git/v5/plumbing/object"
 | 
						"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).
 | 
					// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
 | 
				
			||||||
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
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,8 +16,6 @@ import (
 | 
				
			|||||||
	"code.gitea.io/gitea/modules/log"
 | 
						"code.gitea.io/gitea/modules/log"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/repofiles"
 | 
						"code.gitea.io/gitea/modules/repofiles"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/util"
 | 
						"code.gitea.io/gitea/modules/util"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/go-git/go-git/v5/plumbing"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -253,7 +251,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
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user