Skip to content

Commit

Permalink
#427 Display a new force deletion dialog when a force delete is requi…
Browse files Browse the repository at this point in the history
…red but not set when deleting a branch that isn't fully merged.
  • Loading branch information
mhutchie committed Dec 5, 2020
1 parent d896e99 commit e1b4811
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,18 @@ export class GitGraphView extends Disposable {
break;
case 'deleteBranch':
errorInfos = [await this.dataSource.deleteBranch(msg.repo, msg.branchName, msg.forceDelete)];
for (let i = 0; i < msg.deleteOnRemotes.length; i++) {
errorInfos.push(await this.dataSource.deleteRemoteBranch(msg.repo, msg.branchName, msg.deleteOnRemotes[i]));
if (errorInfos[0] === null) {
for (let i = 0; i < msg.deleteOnRemotes.length; i++) {
errorInfos.push(await this.dataSource.deleteRemoteBranch(msg.repo, msg.branchName, msg.deleteOnRemotes[i]));
}
}
this.sendMessage({ command: 'deleteBranch', errors: errorInfos });
this.sendMessage({
command: 'deleteBranch',
repo: msg.repo,
branchName: msg.branchName,
deleteOnRemotes: msg.deleteOnRemotes,
errors: errorInfos
});
break;
case 'deleteRemote':
this.sendMessage({
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ export interface RequestDeleteBranch extends RepoRequest {
}
export interface ResponseDeleteBranch extends ResponseWithMultiErrorInfo {
readonly command: 'deleteBranch';
readonly repo: string;
readonly branchName: string;
readonly deleteOnRemotes: ReadonlyArray<string>;
}

export interface RequestDeleteRemote extends RepoRequest {
Expand Down
14 changes: 12 additions & 2 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ class GitGraphView {
value: false
});
}
dialog.showForm('Are you sure you want to delete the branch <b><i>' + escapeHtml(refName) + '</i></b>?', inputs, 'Delete Branch', (values) => {
dialog.showForm('Are you sure you want to delete the branch <b><i>' + escapeHtml(refName) + '</i></b>?', inputs, 'Yes, delete', (values) => {
runAction({ command: 'deleteBranch', repo: this.currentRepo, branchName: refName, forceDelete: <boolean>values[0], deleteOnRemotes: remotesWithBranch.length > 0 && <boolean>values[1] ? remotesWithBranch : [] }, 'Deleting Branch');
}, target);
}
Expand Down Expand Up @@ -2889,7 +2889,7 @@ window.addEventListener('load', () => {
}, true);
break;
case 'deleteBranch':
refreshAndDisplayErrors(msg.errors, 'Unable to Delete Branch');
handleResponseDeleteBranch(msg);
break;
case 'deleteRemote':
refreshOrDisplayError(msg.error, 'Unable to Delete Remote');
Expand Down Expand Up @@ -3032,6 +3032,16 @@ window.addEventListener('load', () => {
}
});

function handleResponseDeleteBranch(msg: GG.ResponseDeleteBranch) {
if (msg.errors.length > 0 && msg.errors[0] !== null && msg.errors[0].includes('git branch -D')) {
dialog.showConfirmation('The branch <b><i>' + escapeHtml(msg.branchName) + '</i></b> is not fully merged. Would you like to force delete it?', 'Yes, force delete branch', () => {
runAction({ command: 'deleteBranch', repo: msg.repo, branchName: msg.branchName, forceDelete: true, deleteOnRemotes: msg.deleteOnRemotes }, 'Deleting Branch');
}, { type: TargetType.Repo });
} else {
refreshAndDisplayErrors(msg.errors, 'Unable to Delete Branch');
}
}

function refreshOrDisplayError(error: GG.ErrorInfo, errorMessage: string) {
if (error === null) {
gitGraph.refresh(false);
Expand Down

0 comments on commit e1b4811

Please sign in to comment.