@@ -26,6 +26,8 @@ const (
2626func 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}
0 commit comments