1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-14 22:47:21 +00:00

Move git references checking to gitrepo packages to reduce expose of repository path (#33891)

This commit is contained in:
Lunny Xiao
2025-03-15 19:48:59 -07:00
committed by GitHub
parent f11ac6bf3c
commit 0056fdb942
24 changed files with 79 additions and 46 deletions

View File

@ -814,7 +814,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
reqPath := ctx.PathParam("*")
if reqPath == "" {
refShortName = ctx.Repo.Repository.DefaultBranch
if !ctx.Repo.GitRepo.IsBranchExist(refShortName) {
if !gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, refShortName) {
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 1)
if err == nil && len(brs) != 0 {
refShortName = brs[0].Name
@ -854,7 +854,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
return
}
if refType == git.RefTypeBranch && ctx.Repo.GitRepo.IsBranchExist(refShortName) {
if refType == git.RefTypeBranch && gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, refShortName) {
ctx.Repo.BranchName = refShortName
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
@ -864,7 +864,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
return
}
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
} else if refType == git.RefTypeTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
} else if refType == git.RefTypeTag && gitrepo.IsTagExist(ctx, ctx.Repo.Repository, refShortName) {
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refShortName)