From 797194d2d00eff7421b27d4238d96d2683895755 Mon Sep 17 00:00:00 2001 From: 6543 <24977596+6543@users.noreply.github.com> Date: Mon, 7 Oct 2019 03:28:18 +0200 Subject: [PATCH] Fix editor commit to new branch if PR disabled (#8375) (#8401) --- options/locale/locale_en-US.ini | 1 + routers/repo/editor.go | 6 +++--- templates/repo/editor/commit_form.tmpl | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f0d5b07cb2..f633a811d7 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -694,6 +694,7 @@ editor.delete = Delete '%s' editor.commit_message_desc = Add an optional extended description… editor.commit_directly_to_this_branch = Commit directly to the %s branch. editor.create_new_branch = Create a new branch for this commit and start a pull request. +editor.create_new_branch_np = Create a new branch for this commit. editor.propose_file_change = Propose file change editor.new_branch_name_desc = New branch name… editor.cancel = Cancel diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 5b95b9391c..ef8107311b 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -269,7 +269,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo } } - if form.CommitChoice == frmCommitChoiceNewBranch { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName) } else { ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath)) @@ -434,7 +434,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) { } ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath)) - if form.CommitChoice == frmCommitChoiceNewBranch { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName) } else { treePath := filepath.Dir(ctx.Repo.TreePath) @@ -589,7 +589,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { return } - if form.CommitChoice == frmCommitChoiceNewBranch { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName) } else { ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath)) diff --git a/templates/repo/editor/commit_form.tmpl b/templates/repo/editor/commit_form.tmpl index d22cd07b03..2ff08e3931 100644 --- a/templates/repo/editor/commit_form.tmpl +++ b/templates/repo/editor/commit_form.tmpl @@ -19,11 +19,21 @@
+ {{$pullRequestEnabled := .Repository.UnitEnabled $.UnitTypePullRequests}} + {{$prUnit := .Repository.MustGetUnit $.UnitTypePullRequests}}
- + {{if $pullRequestEnabled}} + + {{else}} + + {{end}}