@@ -594,12 +594,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
594594 return
595595 }
596596
597- isPlainRule := ! git_model .IsRuleNameSpecial (ruleName )
598- var isBranchExist bool
599- if isPlainRule {
600- isBranchExist = git .IsBranchExist (ctx .Req .Context (), ctx .Repo .Repository .RepoPath (), ruleName )
601- }
602-
603597 protectBranch , err := git_model .GetProtectedBranchRuleByName (ctx , repo .ID , ruleName )
604598 if err != nil {
605599 ctx .APIErrorInternal (err )
@@ -716,7 +710,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
716710 BlockAdminMergeOverride : form .BlockAdminMergeOverride ,
717711 }
718712
719- if err := git_model . UpdateProtectBranch (ctx , ctx .Repo .Repository , protectBranch , git_model.WhitelistOptions {
713+ if err := pull_service . CreateOrUpdateProtectedBranch (ctx , ctx .Repo .Repository , protectBranch , git_model.WhitelistOptions {
720714 UserIDs : whitelistUsers ,
721715 TeamIDs : whitelistTeams ,
722716 ForcePushUserIDs : forcePushAllowlistUsers ,
@@ -730,36 +724,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
730724 return
731725 }
732726
733- if isBranchExist {
734- if err := pull_service .CheckPRsForBaseBranch (ctx , ctx .Repo .Repository , ruleName ); err != nil {
735- ctx .APIErrorInternal (err )
736- return
737- }
738- } else {
739- if ! isPlainRule {
740- if ctx .Repo .GitRepo == nil {
741- ctx .Repo .GitRepo , err = gitrepo .RepositoryFromRequestContextOrOpen (ctx , ctx .Repo .Repository )
742- if err != nil {
743- ctx .APIErrorInternal (err )
744- return
745- }
746- }
747- // FIXME: since we only need to recheck files protected rules, we could improve this
748- matchedBranches , err := git_model .FindAllMatchedBranches (ctx , ctx .Repo .Repository .ID , ruleName )
749- if err != nil {
750- ctx .APIErrorInternal (err )
751- return
752- }
753-
754- for _ , branchName := range matchedBranches {
755- if err = pull_service .CheckPRsForBaseBranch (ctx , ctx .Repo .Repository , branchName ); err != nil {
756- ctx .APIErrorInternal (err )
757- return
758- }
759- }
760- }
761- }
762-
763727 // Reload from db to get all whitelists
764728 bp , err := git_model .GetProtectedBranchRuleByName (ctx , ctx .Repo .Repository .ID , ruleName )
765729 if err != nil {
0 commit comments