Skip to content

Commit 2dad832

Browse files
committed
check rule name
1 parent f03b608 commit 2dad832

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

routers/web/repo/setting_protected_branch.go

+14
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
178178
ctx.ServerError("GetProtectBranchOfRepoByID", err)
179179
return
180180
}
181+
if protectBranch != nil && protectBranch.RuleName != f.RuleName {
182+
// RuleName changed. We need to check if there is a rule with the same name.
183+
// If a rule with the same name exists, an error should be returned.
184+
sameNameProtectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName)
185+
if err != nil {
186+
ctx.ServerError("GetProtectBranchOfRepoByName", err)
187+
return
188+
}
189+
if sameNameProtectBranch != nil {
190+
ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_duplicate_rule_name"))
191+
ctx.Redirect(fmt.Sprintf("%s/settings/branches/edit?rule_name=%s", ctx.Repo.RepoLink, protectBranch.RuleName))
192+
return
193+
}
194+
}
181195
} else {
182196
// The RuleID is 0, it should be a create operation. We can only get rule by name.
183197
protectBranch, err = git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName)

0 commit comments

Comments
 (0)