mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28: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:
@@ -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 ""
|
||||
|
@@ -269,7 +269,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
|
||||
} else if reallyEmpty {
|
||||
showEmpty = true // the repo is really empty
|
||||
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
|
||||
} else if branches, _, _ := ctx.Repo.GitRepo.GetBranches(0, 1); len(branches) == 0 {
|
||||
} else if branches, _, _ := ctx.Repo.GitRepo.GetBranchNames(0, 1); len(branches) == 0 {
|
||||
showEmpty = true // it is not really empty, but there is no branch
|
||||
// at the moment, other repo units like "actions" are not able to handle such case,
|
||||
// so we just mark the repo as empty to prevent from displaying these units.
|
||||
|
Reference in New Issue
Block a user