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/repo/repo.go | |
parent | 86cff86b46116353e4d6605ccf5a77a7ac65bc78 (diff) | |
download | gitea-184e47f6ce5587dfb13b3b8aaf49f566d778d896.tar.gz gitea-184e47f6ce5587dfb13b3b8aaf49f566d778d896.zip |
Handle setting default branch via API (#9030)
Diffstat (limited to 'routers/api/v1/repo/repo.go')
-rw-r--r-- | routers/api/v1/repo/repo.go | 12 |
1 files changed, 12 insertions, 0 deletions
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 |