diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2019-11-17 07:30:01 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-11-17 01:30:00 -0500 |
commit | 184e47f6ce5587dfb13b3b8aaf49f566d778d896 (patch) | |
tree | d469f19bd515394401c9299227498d67228bde87 /routers/api/v1 | |
parent | 86cff86b46116353e4d6605ccf5a77a7ac65bc78 (diff) | |
download | gitea-184e47f6ce5587dfb13b3b8aaf49f566d778d896.tar.gz gitea-184e47f6ce5587dfb13b3b8aaf49f566d778d896.zip |
Handle setting default branch via API (#9030)
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 6fdd0d074c..ec6ec191d7 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -606,7 +606,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/:username/:reponame", func() { m.Combo("").Get(reqAnyRepoReader(), repo.Get). Delete(reqToken(), reqOwner(), repo.Delete). - Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), repo.Edit) + Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit) m.Group("/hooks", func() { m.Combo("").Get(repo.ListHooks). Post(bind(api.CreateHookOption{}), repo.CreateHook) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 151475a8e9..05ab9cb38b 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/migrations" "code.gitea.io/gitea/modules/notification" @@ -687,6 +688,17 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err repo.IsTemplate = *opts.Template } + // Default branch only updated if changed and exist + if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && 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 + } + } + repo.DefaultBranch = *opts.DefaultBranch + } + if err := models.UpdateRepository(repo, visibilityChanged); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRepository", err) return err |