From 9107a87ff6680bcfc88327856d5b25de3943e3a8 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 15 Mar 2023 00:06:02 +0000 Subject: [PATCH] Redirect to the commit page after applying patch (#23056) & Fix commit name in Apply Patch page (#23086) (#23131) Backport #23056 Backport #23086 Fixes https://github.com/go-gitea/gitea/issues/22621 Fixes https://github.com/go-gitea/gitea/issues/22621#issuecomment-1439309200 Co-authored-by: yp05327 <576951401@qq.com> --- routers/web/repo/patch.go | 10 +++++++--- templates/repo/editor/commit_form.tmpl | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/patch.go b/routers/web/repo/patch.go index cd731337baa97..0c0663dd5feee 100644 --- a/routers/web/repo/patch.go +++ b/routers/web/repo/patch.go @@ -26,6 +26,8 @@ const ( func NewDiffPatch(ctx *context.Context) { canCommit := renderCommitRights(ctx) + ctx.Data["PageIsPatch"] = true + ctx.Data["TreePath"] = "" ctx.Data["commit_summary"] = "" @@ -52,6 +54,7 @@ func NewDiffPatchPost(ctx *context.Context) { if form.CommitChoice == frmCommitChoiceNewBranch { branchName = form.NewBranchName } + ctx.Data["PageIsPatch"] = true ctx.Data["TreePath"] = "" ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL() ctx.Data["FileContent"] = form.Content @@ -87,13 +90,14 @@ func NewDiffPatchPost(ctx *context.Context) { message += "\n\n" + form.CommitMessage } - if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{ + fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{ LastCommitID: form.LastCommit, OldBranch: ctx.Repo.BranchName, NewBranch: branchName, Message: message, Content: strings.ReplaceAll(form.Content, "\r", ""), - }); err != nil { + }) + if err != nil { if models.IsErrBranchAlreadyExists(err) { // User has specified a branch that already exists branchErr := err.(models.ErrBranchAlreadyExists) @@ -112,6 +116,6 @@ func NewDiffPatchPost(ctx *context.Context) { if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(unit.TypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName)) } else { - ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath)) + ctx.Redirect(ctx.Repo.RepoLink + "/commit/" + fileResponse.Commit.SHA) } } diff --git a/templates/repo/editor/commit_form.tmpl b/templates/repo/editor/commit_form.tmpl index 95fcf2b8555be..762171319630b 100644 --- a/templates/repo/editor/commit_form.tmpl +++ b/templates/repo/editor/commit_form.tmpl @@ -9,7 +9,7 @@ {{.locale.Tr "repo.editor.commit_changes"}} {{- end}}
- +