11import { QuickInputButtons } from 'vscode' ;
22import type { Container } from '../../container' ;
3- import { BranchError } from '../../git/errors' ;
3+ import { BranchError , BranchErrorReason } from '../../git/errors' ;
44import type { GitBranchReference , GitReference } from '../../git/models/reference' ;
55import {
66 getNameWithoutRemote ,
@@ -11,7 +11,7 @@ import {
1111import { Repository } from '../../git/models/repository' ;
1212import type { GitWorktree } from '../../git/models/worktree' ;
1313import { getWorktreesByBranch } from '../../git/models/worktree' ;
14- import { showGenericErrorMessage } from '../../messages' ;
14+ import { showGenericErrorMessage , showGitBranchNotFullyMergedPrompt } from '../../messages' ;
1515import type { QuickPickItemOfT } from '../../quickpicks/items/common' ;
1616import { createQuickPickSeparator } from '../../quickpicks/items/common' ;
1717import type { FlagsQuickPickItem } from '../../quickpicks/items/flags' ;
@@ -540,7 +540,23 @@ export class BranchGitCommand extends QuickCommand {
540540 } catch ( ex ) {
541541 // TODO likely need some better error handling here
542542 Logger . error ( ex ) ;
543- return showGenericErrorMessage ( ex ) ;
543+ if ( ex instanceof BranchError && ex . reason === BranchErrorReason . BranchNotFullyMerged ) {
544+ const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt ( ref . name ) ;
545+ if ( shouldRetryWithForce ) {
546+ try {
547+ await state . repo . git . deleteBranch ( ref , {
548+ force : true ,
549+ remote : state . flags . includes ( '--remotes' ) ,
550+ } ) ;
551+ } catch ( ex ) {
552+ Logger . error ( ex ) ;
553+ await showGenericErrorMessage ( ex ) ;
554+ }
555+ }
556+ continue ;
557+ }
558+
559+ await showGenericErrorMessage ( ex ) ;
544560 }
545561 }
546562 }
0 commit comments