]> source.dussan.org Git - gitea.git/commitdiff
Fix 500 when pushing release to an empty repo (#29554) (#29564)
authorGiteabot <teabot@gitea.io>
Sun, 3 Mar 2024 17:10:22 +0000 (01:10 +0800)
committerGitHub <noreply@github.com>
Sun, 3 Mar 2024 17:10:22 +0000 (17:10 +0000)
Backport #29554 by @lng2020

As title.
The former code directly used `ctx.Repo.GitRepo`, causing 500.

https://github.com/go-gitea/gitea/blob/22b4f0c09f1de5e581929bd10f39833d30d2c482/routers/api/v1/repo/release.go#L241

Co-authored-by: Nanguan Lin <nanguanlin6@gmail.com>
routers/api/v1/repo/release.go

index 6c70bffca33be40f6a65d114f808182f7631173b..dee6ae58bb7422d9d1f937d19c9a320a34ecbdd8 100644 (file)
@@ -4,6 +4,7 @@
 package repo
 
 import (
+       "fmt"
        "net/http"
 
        "code.gitea.io/gitea/models"
@@ -221,6 +222,10 @@ func CreateRelease(ctx *context.APIContext) {
        //   "409":
        //     "$ref": "#/responses/error"
        form := web.GetForm(ctx).(*api.CreateReleaseOption)
+       if ctx.Repo.Repository.IsEmpty {
+               ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
+               return
+       }
        rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
        if err != nil {
                if !repo_model.IsErrReleaseNotExist(err) {