Skip to content

Commit 149bdcb

Browse files
committed
prompt to retry with force
1 parent 1279905 commit 149bdcb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/commands/git/branch.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { QuickInputButtons } from 'vscode';
22
import type { Container } from '../../container';
3-
import { BranchError } from '../../git/errors';
3+
import { BranchError, BranchErrorReason } from '../../git/errors';
44
import type { GitBranchReference, GitReference } from '../../git/models/reference';
55
import {
66
getNameWithoutRemote,
@@ -11,7 +11,7 @@ import {
1111
import { Repository } from '../../git/models/repository';
1212
import type { GitWorktree } from '../../git/models/worktree';
1313
import { getWorktreesByBranch } from '../../git/models/worktree';
14-
import { showGenericErrorMessage } from '../../messages';
14+
import { showGenericErrorMessage, showGitBranchNotFullyMergedPrompt } from '../../messages';
1515
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
1616
import { createQuickPickSeparator } from '../../quickpicks/items/common';
1717
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
@@ -569,7 +569,23 @@ export class BranchGitCommand extends QuickCommand {
569569
} catch (ex) {
570570
// TODO likely need some better error handling here
571571
Logger.error(ex);
572-
return showGenericErrorMessage(ex);
572+
if (ex instanceof BranchError && ex.reason === BranchErrorReason.BranchNotFullyMerged) {
573+
const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt(ref.name);
574+
if (shouldRetryWithForce) {
575+
try {
576+
await state.repo.git.deleteBranch(ref, {
577+
force: true,
578+
remote: state.flags.includes('--remotes'),
579+
});
580+
} catch (ex) {
581+
Logger.error(ex);
582+
await showGenericErrorMessage(ex);
583+
}
584+
}
585+
continue;
586+
}
587+
588+
await showGenericErrorMessage(ex);
573589
}
574590
}
575591
}

src/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function showGitVersionUnsupportedErrorMessage(
138138
);
139139
}
140140

141-
export async function showGitBranchNotFullyMergedPrompt(branchName: string) {
141+
export async function showGitBranchNotFullyMergedPrompt(branchName: string): Promise<boolean> {
142142
const confirm = { title: 'Retry with --force flag' };
143143
const result = await showMessage(
144144
'warn',

0 commit comments

Comments
 (0)