[PORT] gitea#30430: Fix rename branch 500 when the target branch is deleted but exist in database

Fix https://github.com/go-gitea/gitea/issues/30428

---

Conflict resolution: trivial and move test to own subtest run directly
after `Normal`.

(cherrypicked commit 9466fec879f4f2c88c7c1e7a5cffba319282ab66)
This commit is contained in:
Gusted 2024-04-15 16:03:09 +02:00
parent 6f4827b3e0
commit db39b8f4a7
No known key found for this signature in database
GPG key ID: FD821B732837125F
3 changed files with 123 additions and 6 deletions

View file

@ -321,6 +321,9 @@ func RenameBranchPost(ctx *context.Context) {
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 if git_model.IsErrBranchAlreadyExists(err) {
ctx.Flash.Error(ctx.Tr("repo.branch.branch_already_exists", form.To))
ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink))
} else {
ctx.ServerError("RenameBranch", err)
}