fix: parse HEAD ref (#38119)

backport #38088
This commit is contained in:
Lunny Xiao
2026-06-14 12:52:44 -07:00
committed by GitHub
parent 98cc15b307
commit bb4cccc6e9
4 changed files with 30 additions and 3 deletions
+5 -1
View File
@@ -8,6 +8,7 @@ import (
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)
@@ -86,8 +87,11 @@ func (repo *Repository) UnstableGuessRefByShortName(shortName string) RefName {
commit, err := repo.GetCommit(shortName)
if err == nil {
commitIDString := commit.ID.String()
if strings.HasPrefix(commitIDString, shortName) {
// Make sure the short name is either a partial commit ID, or the symbolic HEAD ref.
if strings.HasPrefix(commitIDString, shortName) || shortName == "HEAD" {
return RefName(commitIDString)
} else {
setting.PanicInDevOrTesting("abuse of UnstableGuessRefByShortName, queried %s, got %s", shortName, commitIDString)
}
}
return ""