Skip to content

Commit

Permalink
fix(api): refactor branch and tag existence checks (#30618)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
appleboy authored and earl-warren committed Apr 28, 2024
1 parent e64e8d2 commit 4e2de8b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,10 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}

ctx.Repo.PullRequest.SameRepo = isSameRepo
log.Info("Base branch: %s", baseBranch)
log.Info("Repo path: %s", ctx.Repo.GitRepo.Path)
log.Trace("Repo path: %q, base branch: %q, head branch: %q", ctx.Repo.GitRepo.Path, baseBranch, headBranch)
// Check if base branch is valid.
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
ctx.NotFound("IsBranchExist")
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) {
ctx.NotFound("BaseNotExist")
return nil, nil, nil, nil, "", ""
}

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

// Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) {
if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) {
headGitRepo.Close()
ctx.NotFound()
return nil, nil, nil, nil, "", ""
Expand Down

0 comments on commit 4e2de8b

Please sign in to comment.