@@ -21,7 +21,9 @@ import (
2121	"code.gitea.io/gitea/modules/gitrepo" 
2222	"code.gitea.io/gitea/modules/log" 
2323	"code.gitea.io/gitea/modules/private" 
24+ 	"code.gitea.io/gitea/modules/util" 
2425	"code.gitea.io/gitea/modules/web" 
26+ 	"code.gitea.io/gitea/services/agit" 
2527	gitea_context "code.gitea.io/gitea/services/context" 
2628	pull_service "code.gitea.io/gitea/services/pull" 
2729)
@@ -452,25 +454,18 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) {
452454		return 
453455	}
454456
455- 	baseBranchName   :=  refFullName .ForBranchName ()
456- 
457- 	baseBranchExist   :=   gitrepo . IsBranchExist ( ctx ,  ctx . Repo . Repository ,  baseBranchName ) 
458- 
459- 	if   ! baseBranchExist  { 
460- 		for   p ,  v   :=   range   baseBranchName  { 
461- 			 if   v   ==   '/'   &&   gitrepo . IsBranchExist ( ctx ,  ctx . Repo . Repository ,  baseBranchName [: p ])  &&   p   !=   len ( baseBranchName ) - 1  {
462- 				 baseBranchExist   =   true 
463- 				break 
464- 			}
457+ 	_ ,  _ ,  err   :=  agit . GetAgitBranchInfo ( ctx ,  ctx . Repo . Repository . ID ,  refFullName .ForBranchName () )
458+ 	 if   err   !=   nil  { 
459+ 		 if   ! errors . Is ( err ,  util . ErrNotExist ) { 
460+ 			 ctx . JSON ( http . StatusForbidden , private. Response { 
461+ 				 UserMsg :  fmt . Sprintf ( "Unexpected ref: %s" ,  refFullName ), 
462+ 			}) 
463+ 		}  else  {
464+ 			ctx . JSON ( http . StatusInternalServerError , private. Response { 
465+ 				Err :  err . Error (), 
466+ 			}) 
465467		}
466468	}
467- 
468- 	if  ! baseBranchExist  {
469- 		ctx .JSON (http .StatusForbidden , private.Response {
470- 			UserMsg : fmt .Sprintf ("Unexpected ref: %s" , refFullName ),
471- 		})
472- 		return 
473- 	}
474469}
475470
476471func  generateGitEnv (opts  * private.HookOptions ) (env  []string ) {
0 commit comments