mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Protect default branch against deletion (#11115)
Although default branch is not offered for deletion in the templates, we need to prevent it both at the router level and in the pre-receive hook. Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
a1f11a05e9
commit
505e456f26
3 changed files with 14 additions and 1 deletions
|
@ -57,8 +57,12 @@ func Branches(ctx *context.Context) {
|
|||
// DeleteBranchPost responses for delete merged branch
|
||||
func DeleteBranchPost(ctx *context.Context) {
|
||||
defer redirect(ctx)
|
||||
|
||||
branchName := ctx.Query("name")
|
||||
if branchName == ctx.Repo.Repository.DefaultBranch {
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.default_deletion_failed", branchName))
|
||||
return
|
||||
}
|
||||
|
||||
isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User)
|
||||
if err != nil {
|
||||
log.Error("DeleteBranch: %v", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue