Restrict branch naming when new change matches with protection rules (#36405)

Resolves #36381 by only allowing admins to perform branch renames that
match to branch protection rules.

---------

Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
Kemal Zebari
2026-01-23 02:42:24 -08:00
committed by GitHub
parent e42a1dbb6b
commit 56c5d5e819
4 changed files with 45 additions and 3 deletions
+1 -1
View File
@@ -515,7 +515,7 @@ func RenameBranch(ctx *context.APIContext) {
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
ctx.APIError(http.StatusForbidden, "User must be a repo or site admin to rename default or protected branches.")
case errors.Is(err, git_model.ErrBranchIsProtected):
ctx.APIError(http.StatusForbidden, "Branch is protected by glob-based protection rules.")
ctx.APIError(http.StatusForbidden, "Failed to rename branch due to branch protection rules.")
default:
ctx.APIErrorInternal(err)
}