diff options
author | 6543 <6543@obermui.de> | 2021-05-08 14:11:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-08 14:11:36 +0200 |
commit | e2786147539909eaef2bc39fb728a10b88277d31 (patch) | |
tree | f6670b39eb552a094c0882b8c954c0d65f16c398 /routers | |
parent | 272bbb200d77ca520e335588c771301f9439f393 (diff) | |
download | gitea-e2786147539909eaef2bc39fb728a10b88277d31.tar.gz gitea-e2786147539909eaef2bc39fb728a10b88277d31.zip |
[API] make change repo settings work on empty repos (#15778)
* API: Fix #15602
* Add TEST
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 16 |
2 files changed, 9 insertions, 9 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 05b95d6d5f..0876f3273c 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -712,7 +712,7 @@ func Routes() *web.Route { m.Group("/{username}/{reponame}", func() { m.Combo("").Get(reqAnyRepoReader(), repo.Get). Delete(reqToken(), reqOwner(), repo.Delete). - Patch(reqToken(), reqAdmin(), context.RepoRefForAPI, bind(api.EditRepoOption{}), repo.Edit) + Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), repo.Edit) m.Post("/transfer", reqOwner(), bind(api.TransferRepoOption{}), repo.Transfer) m.Combo("/notifications"). Get(reqToken(), notify.ListRepoNotifications). diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index c422feb043..d8600c0fcd 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -578,7 +578,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err repo.IsTemplate = *opts.Template } - if ctx.Repo.GitRepo == nil { + if ctx.Repo.GitRepo == nil && !repo.IsEmpty { var err error ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath()) if err != nil { @@ -589,13 +589,13 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err } // Default branch only updated if changed and exist or the repository is empty - if opts.DefaultBranch != nil && - repo.DefaultBranch != *opts.DefaultBranch && - (ctx.Repo.Repository.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) { - if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil { - if !git.IsErrUnsupportedVersion(err) { - ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err) - return err + if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) { + if !repo.IsEmpty { + if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil { + if !git.IsErrUnsupportedVersion(err) { + ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err) + return err + } } } repo.DefaultBranch = *opts.DefaultBranch |