Skip to content

Commit 9107a87

Browse files
zeripathyp05327
andauthored
Redirect to the commit page after applying patch (#23056) & Fix commit name in Apply Patch page (#23086) (#23131)
Backport #23056 Backport #23086 Fixes #22621 Fixes #22621 (comment) Co-authored-by: yp05327 <[email protected]>
1 parent 3dc2724 commit 9107a87

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

routers/web/repo/patch.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
func NewDiffPatch(ctx *context.Context) {
2727
canCommit := renderCommitRights(ctx)
2828

29+
ctx.Data["PageIsPatch"] = true
30+
2931
ctx.Data["TreePath"] = ""
3032

3133
ctx.Data["commit_summary"] = ""
@@ -52,6 +54,7 @@ func NewDiffPatchPost(ctx *context.Context) {
5254
if form.CommitChoice == frmCommitChoiceNewBranch {
5355
branchName = form.NewBranchName
5456
}
57+
ctx.Data["PageIsPatch"] = true
5558
ctx.Data["TreePath"] = ""
5659
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
5760
ctx.Data["FileContent"] = form.Content
@@ -87,13 +90,14 @@ func NewDiffPatchPost(ctx *context.Context) {
8790
message += "\n\n" + form.CommitMessage
8891
}
8992

90-
if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
93+
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
9194
LastCommitID: form.LastCommit,
9295
OldBranch: ctx.Repo.BranchName,
9396
NewBranch: branchName,
9497
Message: message,
9598
Content: strings.ReplaceAll(form.Content, "\r", ""),
96-
}); err != nil {
99+
})
100+
if err != nil {
97101
if models.IsErrBranchAlreadyExists(err) {
98102
// User has specified a branch that already exists
99103
branchErr := err.(models.ErrBranchAlreadyExists)
@@ -112,6 +116,6 @@ func NewDiffPatchPost(ctx *context.Context) {
112116
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(unit.TypePullRequests) {
113117
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName))
114118
} else {
115-
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath))
119+
ctx.Redirect(ctx.Repo.RepoLink + "/commit/" + fileResponse.Commit.SHA)
116120
}
117121
}

templates/repo/editor/commit_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{.locale.Tr "repo.editor.commit_changes"}}
1010
{{- end}}</h3>
1111
<div class="field">
12-
<input name="commit_summary" placeholder="{{if .PageIsDelete}}{{.locale.Tr "repo.editor.delete" .TreePath}}{{else if .PageIsUpload}}{{.locale.Tr "repo.editor.upload_files_to_dir" .TreePath}}{{else if .IsNewFile}}{{.locale.Tr "repo.editor.add_tmpl"}}{{else}}{{.locale.Tr "repo.editor.update" .TreePath}}{{end}}" value="{{.commit_summary}}" autofocus>
12+
<input name="commit_summary" placeholder="{{if .PageIsDelete}}{{.locale.Tr "repo.editor.delete" .TreePath}}{{else if .PageIsUpload}}{{.locale.Tr "repo.editor.upload_files_to_dir" .TreePath}}{{else if .IsNewFile}}{{.locale.Tr "repo.editor.add_tmpl"}}{{else if .PageIsPatch}}{{.locale.Tr "repo.editor.patch"}}{{else}}{{.locale.Tr "repo.editor.update" .TreePath}}{{end}}" value="{{.commit_summary}}" autofocus>
1313
</div>
1414
<div class="field">
1515
<textarea name="commit_message" placeholder="{{.locale.Tr "repo.editor.commit_message_desc"}}" rows="5">{{.commit_message}}</textarea>

0 commit comments

Comments
 (0)