mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 13:44:16 +09:00
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:
3 files changed
+4
-15
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user