@@ -176,53 +176,6 @@ func redirect(ctx *context.Context) {
176176 ctx .JSONRedirect (ctx .Repo .RepoLink + "/branches?page=" + url .QueryEscape (ctx .FormString ("page" )))
177177}
178178
179- func handleCreateBranchError (ctx * context.Context , err error , form * forms.NewBranchForm ) {
180- if models .IsErrProtectedTagName (err ) {
181- ctx .Flash .Error (ctx .Tr ("repo.release.tag_name_protected" ))
182- ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
183- return
184- }
185-
186- if models .IsErrTagAlreadyExists (err ) {
187- e := err .(models.ErrTagAlreadyExists )
188- ctx .Flash .Error (ctx .Tr ("repo.branch.tag_collision" , e .TagName ))
189- ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
190- return
191- }
192- if git_model .IsErrBranchAlreadyExists (err ) || git .IsErrPushOutOfDate (err ) {
193- ctx .Flash .Error (ctx .Tr ("repo.branch.branch_already_exists" , form .NewBranchName ))
194- ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
195- return
196- }
197- if git_model .IsErrBranchNameConflict (err ) {
198- e := err .(git_model.ErrBranchNameConflict )
199- ctx .Flash .Error (ctx .Tr ("repo.branch.branch_name_conflict" , form .NewBranchName , e .BranchName ))
200- ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
201- return
202- }
203- if git .IsErrPushRejected (err ) {
204- e := err .(* git.ErrPushRejected )
205- if len (e .Message ) == 0 {
206- ctx .Flash .Error (ctx .Tr ("repo.editor.push_rejected_no_message" ))
207- } else {
208- flashError , err := ctx .RenderToHTML (tplAlertDetails , map [string ]any {
209- "Message" : ctx .Tr ("repo.editor.push_rejected" ),
210- "Summary" : ctx .Tr ("repo.editor.push_rejected_summary" ),
211- "Details" : utils .SanitizeFlashErrorString (e .Message ),
212- })
213- if err != nil {
214- ctx .ServerError ("UpdatePullRequest.HTMLString" , err )
215- return
216- }
217- ctx .Flash .Error (flashError )
218- }
219- ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
220- return
221- }
222-
223- ctx .ServerError ("CreateNewBranch" , err )
224- }
225-
226179// CreateBranch creates new branch in repository
227180func CreateBranch (ctx * context.Context ) {
228181 form := web .GetForm (ctx ).(* forms.NewBranchForm )
@@ -251,7 +204,50 @@ func CreateBranch(ctx *context.Context) {
251204 err = repo_service .CreateNewBranchFromCommit (ctx , ctx .Doer , ctx .Repo .Repository , ctx .Repo .GitRepo , ctx .Repo .CommitID , form .NewBranchName )
252205 }
253206 if err != nil {
254- handleCreateBranchError (ctx , err , form )
207+ if models .IsErrProtectedTagName (err ) {
208+ ctx .Flash .Error (ctx .Tr ("repo.release.tag_name_protected" ))
209+ ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
210+ return
211+ }
212+
213+ if models .IsErrTagAlreadyExists (err ) {
214+ e := err .(models.ErrTagAlreadyExists )
215+ ctx .Flash .Error (ctx .Tr ("repo.branch.tag_collision" , e .TagName ))
216+ ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
217+ return
218+ }
219+ if git_model .IsErrBranchAlreadyExists (err ) || git .IsErrPushOutOfDate (err ) {
220+ ctx .Flash .Error (ctx .Tr ("repo.branch.branch_already_exists" , form .NewBranchName ))
221+ ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
222+ return
223+ }
224+ if git_model .IsErrBranchNameConflict (err ) {
225+ e := err .(git_model.ErrBranchNameConflict )
226+ ctx .Flash .Error (ctx .Tr ("repo.branch.branch_name_conflict" , form .NewBranchName , e .BranchName ))
227+ ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
228+ return
229+ }
230+ if git .IsErrPushRejected (err ) {
231+ e := err .(* git.ErrPushRejected )
232+ if len (e .Message ) == 0 {
233+ ctx .Flash .Error (ctx .Tr ("repo.editor.push_rejected_no_message" ))
234+ } else {
235+ flashError , err := ctx .RenderToHTML (tplAlertDetails , map [string ]any {
236+ "Message" : ctx .Tr ("repo.editor.push_rejected" ),
237+ "Summary" : ctx .Tr ("repo.editor.push_rejected_summary" ),
238+ "Details" : utils .SanitizeFlashErrorString (e .Message ),
239+ })
240+ if err != nil {
241+ ctx .ServerError ("UpdatePullRequest.HTMLString" , err )
242+ return
243+ }
244+ ctx .Flash .Error (flashError )
245+ }
246+ ctx .Redirect (ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ())
247+ return
248+ }
249+
250+ ctx .ServerError ("CreateNewBranch" , err )
255251 return
256252 }
257253
0 commit comments