Skip to content

Commit d093bc3

Browse files
committed
prompt to retry with force
1 parent b3ee512 commit d093bc3

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,12 +1,12 @@
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 { getReferenceLabel, isRevisionReference } from '../../git/models/reference';
66
import { Repository } from '../../git/models/repository';
77
import type { GitWorktree } from '../../git/models/worktree';
88
import { getWorktreesByBranch } from '../../git/models/worktree';
9-
import { showGenericErrorMessage } from '../../messages';
9+
import { showGenericErrorMessage, showGitBranchNotFullyMergedPrompt } from '../../messages';
1010
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
1111
import { createQuickPickSeparator } from '../../quickpicks/items/common';
1212
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
@@ -531,7 +531,23 @@ export class BranchGitCommand extends QuickCommand {
531531
} catch (ex) {
532532
// TODO likely need some better error handling here
533533
Logger.error(ex);
534-
return showGenericErrorMessage(ex);
534+
if (ex instanceof BranchError && ex.reason === BranchErrorReason.BranchNotFullyMerged) {
535+
const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt(ref.name);
536+
if (shouldRetryWithForce) {
537+
try {
538+
await state.repo.git.deleteBranch(ref, {
539+
force: true,
540+
remote: state.flags.includes('--remotes'),
541+
});
542+
} catch (ex) {
543+
Logger.error(ex);
544+
await showGenericErrorMessage(ex);
545+
}
546+
}
547+
continue;
548+
}
549+
550+
await showGenericErrorMessage(ex);
535551
}
536552
}
537553
}

src/messages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function showGitVersionUnsupportedErrorMessage(
137137
);
138138
}
139139

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

0 commit comments

Comments
 (0)