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:
parent
5194bd15ef
commit
0f79122053
3 changed files with 61 additions and 23 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue