diff options
author | zeripath <art27@cantab.net> | 2022-11-25 20:58:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 20:58:20 +0000 |
commit | d7f12af805e33e327ec0c7a250ad8ed09a88e8fd (patch) | |
tree | bb78847a996b9a0381332536fab00da9280182aa /routers | |
parent | abecf632d2886149474471a0e41e14dc3e15340e (diff) | |
download | gitea-d7f12af805e33e327ec0c7a250ad8ed09a88e8fd.tar.gz gitea-d7f12af805e33e327ec0c7a250ad8ed09a88e8fd.zip |
Prevent NPE if trying to restore an already restored deleted branch (#21940)
If a deleted-branch has already been restored, a request to restore it
again will cause a NPE. This PR adds detection for this case, but also
disables buttons when they're clicked in order to help prevent
accidental repeat requests.
Fix #21930
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/branch.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index a7588d275d..43e6d43134 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -126,6 +126,10 @@ func RestoreBranchPost(ctx *context.Context) { log.Error("GetDeletedBranchByID: %v", err) ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) return + } else if deletedBranch == nil { + log.Debug("RestoreBranch: Can't restore branch[%d] '%s', as it does not exist", branchID, branchName) + ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) + return } if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{ |