1
0
Fork 0
forked from forgejo/forgejo

[BUG] Detect protected branch on branch rename

- If a branch cannot be renamed due to a protected branch rule, show
this error in the UI instead of throwing an internal server error.
- Add integration test (also simplify the existing one).
- Resolves #2751
This commit is contained in:
Gusted 2024-03-26 01:39:15 +01:00
parent 5194bd15ef
commit 0f79122053
No known key found for this signature in database
GPG key ID: FD821B732837125F
3 changed files with 61 additions and 23 deletions

View file

@ -4,6 +4,7 @@
package setting
import (
"errors"
"fmt"
"net/http"
"net/url"
@ -316,7 +317,12 @@ func RenameBranchPost(ctx *context.Context) {
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To)
if err != nil {
ctx.ServerError("RenameBranch", err)
if errors.Is(err, git_model.ErrBranchIsProtected) {
ctx.Flash.Error(ctx.Tr("repo.settings.rename_branch_failed_protected", form.To))
ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink))
} else {
ctx.ServerError("RenameBranch", err)
}
return
}