Skip to content

Commit 66762d4

Browse files
committed
prompt to retry with force
1 parent eab5948 commit 66762d4

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 { getNameWithoutRemote, 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';
@@ -527,7 +527,23 @@ export class BranchGitCommand extends QuickCommand {
527527
} catch (ex) {
528528
// TODO likely need some better error handling here
529529
Logger.error(ex);
530-
return showGenericErrorMessage(ex);
530+
if (ex instanceof BranchError && ex.reason === BranchErrorReason.BranchNotFullyMerged) {
531+
const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt(ref.name);
532+
if (shouldRetryWithForce) {
533+
try {
534+
await state.repo.git.deleteBranch(ref, {
535+
force: true,
536+
remote: state.flags.includes('--remotes'),
537+
});
538+
} catch (ex) {
539+
Logger.error(ex);
540+
await showGenericErrorMessage(ex);
541+
}
542+
}
543+
continue;
544+
}
545+
546+
await showGenericErrorMessage(ex);
531547
}
532548
}
533549
}

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)