feat: add delete whitelist to branch protection rules #696
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Branch protection currently blocks all deletion of protected branches with no whitelist mechanism. The pre-receive hook unconditionally blocks deletion. This prevents workflows like auto-release from cleaning up ephemeral branches (e.g. rc).
Solution
Add a delete whitelist following the same pattern as force-push allowlist:
Use Case
The rc branch is ephemeral -- created by promote-rc, deleted by auto-release. It needs push protection while alive but must be deletable by CI.
Implementation complete in PR #706 (
feature/delete-whitelist→dev).What was added:
ProtectedBranch:CanDelete,EnableDeleteAllowlist,DeleteAllowlistUserIDs,DeleteAllowlistTeamIDs,DeleteAllowlistDeployKeys,DeleteAllowlistActionsUserCanUserDelete()method — defaults to admin access when no allowlist is enabled (higher threshold than force-push which defaults to write)protected_branchtableCanUserDeletecheck (handles both deploy key and user scenarios)CanDeleteBranchservice: usesGetFirstMatchProtectedBranchRule+CanUserDeleteinstead ofIsBranchProtectedFiles changed (13):
models/git/protected_branch.go,models/migrations/migrations.go,models/migrations/v1_27/v361.go,modules/structs/repo_branch.go,options/locale/locale_en-US.json,routers/api/v1/repo/branch.go,routers/private/hook_pre_receive.go,routers/web/repo/setting/protected_branch.go,services/convert/convert.go,services/forms/repo_form.go,services/repository/branch.go,templates/repo/settings/protected_branch.tmpl,CHANGELOG.mdImplemented in PR #706 (merged to dev).
Changes (13 files, +345/-20):
ProtectedBranchmodel:CanDelete,EnableDeleteAllowlist,DeleteAllowlistUserIDs/TeamIDs,DeleteAllowlistDeployKeys,DeleteAllowlistActionsUserCanUserDelete()method — defaults to admin access when no allowlist (higher threshold than force-push which uses write access)protected_branchtableCanUserDeleteinstead of unconditionally blocking deletionCanDeleteBranchuses allowlist-aware check