1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-19 08:48:37 +00:00

Refactor Branch struct in package modules/git (#33980)

The `Branch` struct in `modules/git` package is unnecessary. We can just
use a `string` to represent a branch
This commit is contained in:
Lunny Xiao
2025-04-02 10:31:32 -07:00
committed by GitHub
parent 285950a222
commit c27d87a9ac
16 changed files with 169 additions and 147 deletions

View File

@@ -668,7 +668,7 @@ func UploadFilePost(ctx *context.Context) {
}
if oldBranchName != branchName {
if _, err := ctx.Repo.GitRepo.GetBranch(branchName); err == nil {
if exist, err := git_model.IsBranchExist(ctx, ctx.Repo.Repository.ID, branchName); err == nil && exist {
ctx.Data["Err_NewBranchName"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), tplUploadFile, &form)
return
@@ -875,12 +875,11 @@ func GetUniquePatchBranchName(ctx *context.Context) string {
prefix := ctx.Doer.LowerName + "-patch-"
for i := 1; i <= 1000; i++ {
branchName := fmt.Sprintf("%s%d", prefix, i)
if _, err := ctx.Repo.GitRepo.GetBranch(branchName); err != nil {
if git.IsErrBranchNotExist(err) {
return branchName
}
if exist, err := git_model.IsBranchExist(ctx, ctx.Repo.Repository.ID, branchName); err != nil {
log.Error("GetUniquePatchBranchName: %v", err)
return ""
} else if !exist {
return branchName
}
}
return ""