From 92cc824fc7849b8c2be28c59a18923a2f4a0cc76 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 22 Feb 2023 11:01:20 +0900 Subject: [PATCH 1/2] redirect to commit page --- routers/web/repo/patch.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/patch.go b/routers/web/repo/patch.go index 12b26f38e9013..99d1dc4998c3d 100644 --- a/routers/web/repo/patch.go +++ b/routers/web/repo/patch.go @@ -25,8 +25,6 @@ const ( func NewDiffPatch(ctx *context.Context) { canCommit := renderCommitRights(ctx) - ctx.Data["TreePath"] = "" - ctx.Data["commit_summary"] = "" ctx.Data["commit_message"] = "" if canCommit { @@ -51,7 +49,7 @@ func NewDiffPatchPost(ctx *context.Context) { if form.CommitChoice == frmCommitChoiceNewBranch { branchName = form.NewBranchName } - ctx.Data["TreePath"] = "" + ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL() ctx.Data["FileContent"] = form.Content ctx.Data["commit_summary"] = form.CommitSummary @@ -86,13 +84,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) @@ -111,6 +110,6 @@ func NewDiffPatchPost(ctx *context.Context) { if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(ctx, 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) } } From 219fe8816ce047e8f45543232c6e9fc7deba497e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 24 Feb 2023 16:18:06 +0900 Subject: [PATCH 2/2] remove TreePath --- routers/web/repo/patch.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/routers/web/repo/patch.go b/routers/web/repo/patch.go index 6a1da08be5248..efb4662496c33 100644 --- a/routers/web/repo/patch.go +++ b/routers/web/repo/patch.go @@ -27,8 +27,6 @@ func NewDiffPatch(ctx *context.Context) { ctx.Data["PageIsPatch"] = true - ctx.Data["TreePath"] = "" - ctx.Data["commit_summary"] = "" ctx.Data["commit_message"] = "" if canCommit { @@ -54,7 +52,6 @@ func NewDiffPatchPost(ctx *context.Context) { 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 ctx.Data["commit_summary"] = form.CommitSummary