Skip to content

Commit 4e2de8b

Browse files
appleboywxiaoguangGiteaBot
authored andcommitted
fix(api): refactor branch and tag existence checks (#30618)
- Update branch existence check to also include tag existence check - Adjust error message for branch/tag existence check ref: go-gitea/gitea#30349 --------- Signed-off-by: appleboy <appleboy.tw@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io> (cherry picked from commit 6459c50278906893f3cbc2bf3e52eff65e739b37)
1 parent e64e8d2 commit 4e2de8b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

routers/api/v1/repo/pull.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,10 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
10791079
}
10801080

10811081
ctx.Repo.PullRequest.SameRepo = isSameRepo
1082-
log.Info("Base branch: %s", baseBranch)
1083-
log.Info("Repo path: %s", ctx.Repo.GitRepo.Path)
1082+
log.Trace("Repo path: %q, base branch: %q, head branch: %q", ctx.Repo.GitRepo.Path, baseBranch, headBranch)
10841083
// Check if base branch is valid.
1085-
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
1086-
ctx.NotFound("IsBranchExist")
1084+
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) {
1085+
ctx.NotFound("BaseNotExist")
10871086
return nil, nil, nil, nil, "", ""
10881087
}
10891088

@@ -1146,7 +1145,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
11461145
}
11471146

11481147
// Check if head branch is valid.
1149-
if !headGitRepo.IsBranchExist(headBranch) {
1148+
if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) {
11501149
headGitRepo.Close()
11511150
ctx.NotFound()
11521151
return nil, nil, nil, nil, "", ""

0 commit comments

Comments
 (0)