@@ -95,7 +95,8 @@ type preparedEditorCommitForm[T any] struct {
9595 form T
9696 commonForm * forms.CommitCommonForm
9797 CommitFormOptions * context.CommitFormOptions
98- TargetBranchName string
98+ OldBranchName string
99+ NewBranchName string
99100 GitCommitter * files_service.IdentityOptions
100101}
101102
@@ -142,6 +143,7 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
142143 return nil
143144 }
144145
146+ oldBranchName := ctx .Repo .BranchName
145147 fromBaseBranch := ctx .FormString ("from_base_branch" )
146148 if fromBaseBranch != "" {
147149 err = editorPushBranchToForkedRepository (ctx , ctx .Doer , ctx .Repo .Repository .BaseRepo , fromBaseBranch , ctx .Repo .Repository , targetBranchName )
@@ -150,13 +152,16 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
150152 ctx .JSONError (ctx .Tr ("repo.editor.fork_failed_to_push_branch" , targetBranchName ))
151153 return nil
152154 }
155+ // since we have pushed the branch from base branch, so now we need to commit the changes directly
156+ oldBranchName = targetBranchName
153157 }
154158
155159 return & preparedEditorCommitForm [T ]{
156160 form : form ,
157161 commonForm : commonForm ,
158162 CommitFormOptions : commitFormOptions ,
159- TargetBranchName : targetBranchName ,
163+ OldBranchName : oldBranchName ,
164+ NewBranchName : targetBranchName ,
160165 GitCommitter : gitCommitter ,
161166 }
162167}
@@ -166,7 +171,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
166171 if parsed .commonForm .CommitChoice == editorCommitChoiceNewBranch {
167172 // Redirect to a pull request when possible
168173 redirectToPullRequest := false
169- repo , baseBranch , headBranch := ctx .Repo .Repository , ctx . Repo . BranchName , parsed .TargetBranchName
174+ repo , baseBranch , headBranch := ctx .Repo .Repository , parsed . OldBranchName , parsed .NewBranchName
170175 if ctx .Repo .Repository .IsFork && parsed .CommitFormOptions .CanCreateBasePullRequest {
171176 redirectToPullRequest = true
172177 baseBranch = repo .BaseRepo .DefaultBranch
@@ -183,7 +188,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
183188
184189 returnURI := ctx .FormString ("return_uri" )
185190 if returnURI == "" || ! httplib .IsCurrentGiteaSiteURL (ctx , returnURI ) {
186- returnURI = util .URLJoin (ctx .Repo .RepoLink , "src/branch" , util .PathEscapeSegments (parsed .TargetBranchName ), util .PathEscapeSegments (treePath ))
191+ returnURI = util .URLJoin (ctx .Repo .RepoLink , "src/branch" , util .PathEscapeSegments (parsed .NewBranchName ), util .PathEscapeSegments (treePath ))
187192 }
188193 ctx .JSONRedirect (returnURI )
189194}
@@ -319,8 +324,8 @@ func EditFilePost(ctx *context.Context) {
319324
320325 _ , err := files_service .ChangeRepoFiles (ctx , ctx .Repo .Repository , ctx .Doer , & files_service.ChangeRepoFilesOptions {
321326 LastCommitID : parsed .form .LastCommit ,
322- OldBranch : ctx . Repo . BranchName ,
323- NewBranch : parsed .TargetBranchName ,
327+ OldBranch : parsed . OldBranchName ,
328+ NewBranch : parsed .NewBranchName ,
324329 Message : parsed .GetCommitMessage (defaultCommitMessage ),
325330 Files : []* files_service.ChangeRepoFile {
326331 {
@@ -335,7 +340,7 @@ func EditFilePost(ctx *context.Context) {
335340 Committer : parsed .GitCommitter ,
336341 })
337342 if err != nil {
338- editorHandleFileOperationError (ctx , parsed .TargetBranchName , err )
343+ editorHandleFileOperationError (ctx , parsed .NewBranchName , err )
339344 return
340345 }
341346
@@ -362,8 +367,8 @@ func DeleteFilePost(ctx *context.Context) {
362367 treePath := ctx .Repo .TreePath
363368 _ , err := files_service .ChangeRepoFiles (ctx , ctx .Repo .Repository , ctx .Doer , & files_service.ChangeRepoFilesOptions {
364369 LastCommitID : parsed .form .LastCommit ,
365- OldBranch : ctx . Repo . BranchName ,
366- NewBranch : parsed .TargetBranchName ,
370+ OldBranch : parsed . OldBranchName ,
371+ NewBranch : parsed .NewBranchName ,
367372 Files : []* files_service.ChangeRepoFile {
368373 {
369374 Operation : "delete" ,
@@ -376,12 +381,12 @@ func DeleteFilePost(ctx *context.Context) {
376381 Committer : parsed .GitCommitter ,
377382 })
378383 if err != nil {
379- editorHandleFileOperationError (ctx , parsed .TargetBranchName , err )
384+ editorHandleFileOperationError (ctx , parsed .NewBranchName , err )
380385 return
381386 }
382387
383388 ctx .Flash .Success (ctx .Tr ("repo.editor.file_delete_success" , treePath ))
384- redirectTreePath := getClosestParentWithFiles (ctx .Repo .GitRepo , parsed .TargetBranchName , treePath )
389+ redirectTreePath := getClosestParentWithFiles (ctx .Repo .GitRepo , parsed .NewBranchName , treePath )
385390 redirectForCommitChoice (ctx , parsed , redirectTreePath )
386391}
387392
@@ -406,8 +411,8 @@ func UploadFilePost(ctx *context.Context) {
406411 defaultCommitMessage := ctx .Locale .TrString ("repo.editor.upload_files_to_dir" , util .IfZero (parsed .form .TreePath , "/" ))
407412 err := files_service .UploadRepoFiles (ctx , ctx .Repo .Repository , ctx .Doer , & files_service.UploadRepoFileOptions {
408413 LastCommitID : parsed .form .LastCommit ,
409- OldBranch : ctx . Repo . BranchName ,
410- NewBranch : parsed .TargetBranchName ,
414+ OldBranch : parsed . OldBranchName ,
415+ NewBranch : parsed .NewBranchName ,
411416 TreePath : parsed .form .TreePath ,
412417 Message : parsed .GetCommitMessage (defaultCommitMessage ),
413418 Files : parsed .form .Files ,
@@ -416,7 +421,7 @@ func UploadFilePost(ctx *context.Context) {
416421 Committer : parsed .GitCommitter ,
417422 })
418423 if err != nil {
419- editorHandleFileOperationError (ctx , parsed .TargetBranchName , err )
424+ editorHandleFileOperationError (ctx , parsed .NewBranchName , err )
420425 return
421426 }
422427 redirectForCommitChoice (ctx , parsed , parsed .form .TreePath )
0 commit comments