fix(api): answer 409 when repository files already exist on disk (#40095)

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Signed-off-by: hktitof <hktitof@users.noreply.github.com>
Co-authored-by: hktitof <hktitof@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-10-30 20:37:37 +00:00
1 parent fa41fc94d4
commit 1aff9b8cd6
3 files changed
+4 -15

No files matched your search

+1 -1
View File
@@ -77,7 +77,7 @@ func IsErrRepoAlreadyExist(err error) bool {
}
func (err ErrRepoAlreadyExist) Error() string {
return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
return fmt.Sprintf("repository already exists [owner: %s, repo: %s]", err.Uname, err.Name)
}
func (err ErrRepoAlreadyExist) Unwrap() error {
+1 -12
View File
@@ -23,7 +23,6 @@ import (
unit_model "gitea.dev/models/unit"
user_model "gitea.dev/models/user"
"gitea.dev/modules/git"
"gitea.dev/modules/label"
"gitea.dev/modules/log"
"gitea.dev/modules/markup"
"gitea.dev/modules/optional"
@@ -254,17 +253,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
ObjectFormatName: string(opt.ObjectFormatName),
})
if err != nil {
if repo_model.IsErrRepoAlreadyExist(err) {
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
} else if db.IsErrNameReserved(err) ||
db.IsErrNamePatternNotAllowed(err) ||
label.IsErrTemplateLoad(err) {
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
} else if errors.Is(err, util.ErrPermissionDenied) {
ctx.APIError(http.StatusForbidden, err.Error())
} else {
ctx.APIErrorInternal(err)
}
ctx.APIErrorAuto(err)
return
}
+2 -2
View File
@@ -517,7 +517,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
AddTokenAuth(httpContext.Token)
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
respJSON := DecodeJSON(t, resp, map[string]string{})
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
assert.Contains(t, respJSON["message"], "already exists")
})
}
@@ -574,7 +574,7 @@ func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
AddTokenAuth(httpContext.Token)
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
respJSON := DecodeJSON(t, resp, map[string]string{})
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
assert.Contains(t, respJSON["message"], "already exists")
})
}