diff options
author | Zettat123 <zettat123@gmail.com> | 2024-12-04 15:30:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 23:30:46 -0800 |
commit | 5dda9510f48f6babb1a5c582e83c501b5eaa214e (patch) | |
tree | 84b9b705c68eb4622f722e0f29e71a0fe282efe0 /modules/git/repo_commit_gogit.go | |
parent | 17053e953f697ba21e067f1ad7715b18e07e273b (diff) | |
download | gitea-5dda9510f48f6babb1a5c582e83c501b5eaa214e.tar.gz gitea-5dda9510f48f6babb1a5c582e83c501b5eaa214e.zip |
Fix gogit `GetRefCommitID` (#32705)
Diffstat (limited to 'modules/git/repo_commit_gogit.go')
-rw-r--r-- | modules/git/repo_commit_gogit.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/git/repo_commit_gogit.go b/modules/git/repo_commit_gogit.go index 84580be9a5..993013eef7 100644 --- a/modules/git/repo_commit_gogit.go +++ b/modules/git/repo_commit_gogit.go @@ -14,9 +14,16 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -// GetRefCommitID returns the last commit ID string of given reference (branch or tag). +// GetRefCommitID returns the last commit ID string of given reference. func (repo *Repository) GetRefCommitID(name string) (string, error) { - ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true) + if plumbing.IsHash(name) { + return name, nil + } + refName := plumbing.ReferenceName(name) + if err := refName.Validate(); err != nil { + return "", err + } + ref, err := repo.gogitRepo.Reference(refName, true) if err != nil { if err == plumbing.ErrReferenceNotFound { return "", ErrNotExist{ |