mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-05 20:36:17 +00:00
refactor(git): clarify GetBranch behavior to make it only gets an existing branch (#38662)
`GetBranch` silently returned soft-deleted branches, contradicting `IsBranchExist` and forcing callers to manually check `branch.IsDeleted` everywhere. Refactored it to `GetBranchExisting` to have a clear behavior: it only returns the existing branch. --------- Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -173,14 +173,9 @@ func (prInfo *pullRequestViewInfo) setTemplateDataMergeTarget(ctx *context.Conte
|
||||
ctx.Data["BaseTarget"] = pull.BaseBranch
|
||||
headBranchLink := ""
|
||||
if pull.Flow == issues_model.PullRequestFlowGithub {
|
||||
b, err := git_model.GetBranch(ctx, pull.HeadRepoID, pull.HeadBranch)
|
||||
switch {
|
||||
case err == nil:
|
||||
if !b.IsDeleted {
|
||||
headBranchLink = pull.GetHeadBranchLink(ctx)
|
||||
}
|
||||
case !git_model.IsErrBranchNotExist(err):
|
||||
log.Error("GetBranch: %v", err)
|
||||
headBranchExists, _ := git_model.IsBranchExist(ctx, pull.HeadRepoID, pull.HeadBranch)
|
||||
if headBranchExists {
|
||||
headBranchLink = pull.GetHeadBranchLink(ctx)
|
||||
}
|
||||
}
|
||||
ctx.Data["HeadBranchLink"] = headBranchLink
|
||||
|
||||
Reference in New Issue
Block a user