@@ -8,17 +8,15 @@ import (
88 "net/http"
99 "strings"
1010
11- "code.gitea.io/gitea/models/unit"
1211 "code.gitea.io/gitea/modules/git"
1312 "code.gitea.io/gitea/modules/util"
14- "code.gitea.io/gitea/modules/web"
1513 "code.gitea.io/gitea/services/context"
1614 "code.gitea.io/gitea/services/forms"
1715 "code.gitea.io/gitea/services/repository/files"
1816)
1917
2018func CherryPick (ctx * context.Context ) {
21- _ = prepareEditorCommitFormOptions (ctx , "_cherrypick" )
19+ prepareEditorCommitFormOptions (ctx , "_cherrypick" )
2220 if ctx .Written () {
2321 return
2422 }
@@ -46,41 +44,20 @@ func CherryPick(ctx *context.Context) {
4644}
4745
4846func CherryPickPost (ctx * context.Context ) {
49- form := web .GetForm (ctx ).(* forms.CherryPickForm )
50- if ctx .HasError () {
51- ctx .JSONError (ctx .GetErrMsg ())
52- return
53- }
54-
55- formOpts := prepareEditorCommitFormOptions (ctx , "_cherrypick" )
56- if ctx .Written () {
57- return
58- }
59-
6047 fromCommitID := ctx .PathParam ("sha" )
61-
62- branchName := util .Iif (form .CommitChoice == editorCommitChoiceNewBranch , form .NewBranchName , ctx .Repo .BranchName )
63- if branchName == ctx .Repo .BranchName && ! formOpts .CommitFormBehaviors .CanCommitToBranch {
64- ctx .JSONError (ctx .Tr ("repo.editor.cannot_commit_to_protected_branch" , branchName ))
65- return
66- }
67-
68- defaultMessage := util .Iif (form .Revert , ctx .Locale .TrString ("repo.commit.revert-header" , fromCommitID ), ctx .Locale .TrString ("repo.commit.cherry-pick-header" , fromCommitID ))
69- commitMessage := buildEditorCommitMessage (defaultMessage , form .CommitSummary , form .CommitMessage )
70-
71- gitCommitter , valid := WebGitOperationGetCommitChosenEmailIdentity (ctx , form .CommitEmail )
72- if ! valid {
73- ctx .JSONError (ctx .Tr ("repo.editor.invalid_commit_email" ))
48+ form , parsed := parseEditorCommitSubmittedForm [* forms.CherryPickForm ](ctx )
49+ if ctx .Written () {
7450 return
7551 }
7652
53+ defaultCommitMessage := util .Iif (form .Revert , ctx .Locale .TrString ("repo.commit.revert-header" , fromCommitID ), ctx .Locale .TrString ("repo.commit.cherry-pick-header" , fromCommitID ))
7754 opts := & files.ApplyDiffPatchOptions {
7855 LastCommitID : form .LastCommit ,
7956 OldBranch : ctx .Repo .BranchName ,
80- NewBranch : branchName ,
81- Message : commitMessage ,
82- Author : gitCommitter ,
83- Committer : gitCommitter ,
57+ NewBranch : parsed . TargetBranchName ,
58+ Message : parsed . GetCommitMessage ( defaultCommitMessage ) ,
59+ Author : parsed . GitCommitter ,
60+ Committer : parsed . GitCommitter ,
8461 }
8562
8663 // First try the simple plain read-tree -m approach
@@ -98,14 +75,9 @@ func CherryPickPost(ctx *context.Context) {
9875 _ , err = files .ApplyDiffPatch (ctx , ctx .Repo .Repository , ctx .Doer , opts )
9976 }
10077 if err != nil {
101- editorHandleFileOperationError (ctx , branchName , err )
78+ editorHandleFileOperationError (ctx , parsed . TargetBranchName , err )
10279 return
10380 }
10481 }
105-
106- if form .CommitChoice == editorCommitChoiceNewBranch && ctx .Repo .Repository .UnitEnabled (ctx , unit .TypePullRequests ) {
107- ctx .JSONRedirect (ctx .Repo .RepoLink + "/compare/" + util .PathEscapeSegments (ctx .Repo .BranchName ) + "..." + util .PathEscapeSegments (form .NewBranchName ))
108- } else {
109- ctx .JSONRedirect (ctx .Repo .RepoLink + "/src/branch/" + util .PathEscapeSegments (branchName ))
110- }
82+ redirectForCommitChoice (ctx , parsed , form .TreePath )
11183}
0 commit comments