Skip to content

Commit fad418e

Browse files
committed
prompt to retry with force
1 parent 0d3796c commit fad418e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/commands/git/branch.ts

+19-3
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';
@@ -554,7 +554,23 @@ export class BranchGitCommand extends QuickCommand {
554554
} catch (ex) {
555555
// TODO likely need some better error handling here
556556
Logger.error(ex);
557-
return showGenericErrorMessage(ex);
557+
if (ex instanceof BranchError && ex.reason === BranchErrorReason.BranchNotFullyMerged) {
558+
const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt(ref.name);
559+
if (shouldRetryWithForce) {
560+
try {
561+
await state.repo.git.deleteBranch(ref, {
562+
force: true,
563+
remote: state.flags.includes('--remotes'),
564+
});
565+
} catch (ex) {
566+
Logger.error(ex);
567+
await showGenericErrorMessage(ex);
568+
}
569+
}
570+
continue;
571+
}
572+
573+
await showGenericErrorMessage(ex);
558574
}
559575
}
560576
}

src/messages.ts

+1-1
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)