summaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2024-03-26 01:39:15 +0100
committerGusted <postmaster@gusted.xyz>2024-03-26 15:58:52 +0100
commit0f791220532c39aaa258b68a7c70238e18893054 (patch)
tree21a7ecd0741d9f9bc3cac338fa1e7a7b19d9e2d7 /routers/web/repo
parentMerge pull request 'Update module github.com/editorconfig/editorconfig-core-g... (diff)
downloadforgejo-0f791220532c39aaa258b68a7c70238e18893054.tar.xz
forgejo-0f791220532c39aaa258b68a7c70238e18893054.zip
[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
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/setting/protected_branch.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/routers/web/repo/setting/protected_branch.go b/routers/web/repo/setting/protected_branch.go
index b37520a390..7ee67e5925 100644
--- a/routers/web/repo/setting/protected_branch.go
+++ b/routers/web/repo/setting/protected_branch.go
@@ -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
}