Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent NPE if trying to restore an already restored deleted branch (#21940) #21944

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export function initGlobalLinkActions() {
e.preventDefault();
const $this = $(this);
const redirect = $this.data('redirect');
$this.prop('disabled', true);
$.post($this.data('url'), {
_csrf: csrfToken
}).done((data) => {
Expand All @@ -270,6 +271,8 @@ export function initGlobalLinkActions() {
} else {
window.location.reload();
}
}).always(() => {
$this.prop('disabled', false);
});
}

Expand All @@ -283,11 +286,14 @@ export function initGlobalLinkActions() {
// FIXME: this is only used once, and should be replace with `link-action` instead
$('.undo-button').on('click', function () {
const $this = $(this);
$this.prop('disabled', true);
$.post($this.data('url'), {
_csrf: csrfToken,
id: $this.data('id')
}).done((data) => {
window.location.href = data.redirect;
}).always(() => {
$this.prop('disabled', false);
});
});
}
Expand Down