Skip to content

Commit d7f12af

Browse files
authored
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>
1 parent abecf63 commit d7f12af

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

routers/web/repo/branch.go

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ func RestoreBranchPost(ctx *context.Context) {
126126
log.Error("GetDeletedBranchByID: %v", err)
127127
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
128128
return
129+
} else if deletedBranch == nil {
130+
log.Debug("RestoreBranch: Can't restore branch[%d] '%s', as it does not exist", branchID, branchName)
131+
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
132+
return
129133
}
130134

131135
if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{

web_src/js/features/common-global.js

+6
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export function initGlobalLinkActions() {
260260
e.preventDefault();
261261
const $this = $(this);
262262
const redirect = $this.data('redirect');
263+
$this.prop('disabled', true);
263264
$.post($this.data('url'), {
264265
_csrf: csrfToken
265266
}).done((data) => {
@@ -270,6 +271,8 @@ export function initGlobalLinkActions() {
270271
} else {
271272
window.location.reload();
272273
}
274+
}).always(() => {
275+
$this.prop('disabled', false);
273276
});
274277
}
275278

@@ -283,11 +286,14 @@ export function initGlobalLinkActions() {
283286
// FIXME: this is only used once, and should be replace with `link-action` instead
284287
$('.undo-button').on('click', function () {
285288
const $this = $(this);
289+
$this.prop('disabled', true);
286290
$.post($this.data('url'), {
287291
_csrf: csrfToken,
288292
id: $this.data('id')
289293
}).done((data) => {
290294
window.location.href = data.redirect;
295+
}).always(() => {
296+
$this.prop('disabled', false);
291297
});
292298
});
293299
}

0 commit comments

Comments
 (0)