Skip to content

Commit 28625fb

Browse files
Redirect to the commit page after applying patch (#23056) (#23127)
Backport #23056 Fixes #22621 Co-authored-by: yp05327 <576951401@qq.com>
1 parent 7c3196c commit 28625fb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

routers/web/repo/patch.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ func NewDiffPatch(ctx *context.Context) {
2727

2828
ctx.Data["PageIsPatch"] = true
2929

30-
ctx.Data["TreePath"] = ""
31-
3230
ctx.Data["commit_summary"] = ""
3331
ctx.Data["commit_message"] = ""
3432
if canCommit {
@@ -54,7 +52,6 @@ func NewDiffPatchPost(ctx *context.Context) {
5452
branchName = form.NewBranchName
5553
}
5654
ctx.Data["PageIsPatch"] = true
57-
ctx.Data["TreePath"] = ""
5855
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
5956
ctx.Data["FileContent"] = form.Content
6057
ctx.Data["commit_summary"] = form.CommitSummary
@@ -89,13 +86,14 @@ func NewDiffPatchPost(ctx *context.Context) {
8986
message += "\n\n" + form.CommitMessage
9087
}
9188

92-
if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
89+
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
9390
LastCommitID: form.LastCommit,
9491
OldBranch: ctx.Repo.BranchName,
9592
NewBranch: branchName,
9693
Message: message,
9794
Content: strings.ReplaceAll(form.Content, "\r", ""),
98-
}); err != nil {
95+
})
96+
if err != nil {
9997
if models.IsErrBranchAlreadyExists(err) {
10098
// User has specified a branch that already exists
10199
branchErr := err.(models.ErrBranchAlreadyExists)
@@ -114,6 +112,6 @@ func NewDiffPatchPost(ctx *context.Context) {
114112
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(ctx, unit.TypePullRequests) {
115113
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName))
116114
} else {
117-
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath))
115+
ctx.Redirect(ctx.Repo.RepoLink + "/commit/" + fileResponse.Commit.SHA)
118116
}
119117
}

0 commit comments

Comments
 (0)