Skip to content

Commit

Permalink
prompt to retry with force
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Oct 3, 2024
1 parent eab5948 commit 66762d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/commands/git/branch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { QuickInputButtons } from 'vscode';
import type { Container } from '../../container';
import { BranchError } from '../../git/errors';
import { BranchError, BranchErrorReason } from '../../git/errors';
import type { GitBranchReference, GitReference } from '../../git/models/reference';
import { getNameWithoutRemote, getReferenceLabel, isRevisionReference } from '../../git/models/reference';
import { Repository } from '../../git/models/repository';
import type { GitWorktree } from '../../git/models/worktree';
import { getWorktreesByBranch } from '../../git/models/worktree';
import { showGenericErrorMessage } from '../../messages';
import { showGenericErrorMessage, showGitBranchNotFullyMergedPrompt } from '../../messages';
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
import { createQuickPickSeparator } from '../../quickpicks/items/common';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
Expand Down Expand Up @@ -527,7 +527,23 @@ export class BranchGitCommand extends QuickCommand {
} catch (ex) {
// TODO likely need some better error handling here
Logger.error(ex);
return showGenericErrorMessage(ex);
if (ex instanceof BranchError && ex.reason === BranchErrorReason.BranchNotFullyMerged) {
const shouldRetryWithForce = await showGitBranchNotFullyMergedPrompt(ref.name);
if (shouldRetryWithForce) {
try {
await state.repo.git.deleteBranch(ref, {
force: true,
remote: state.flags.includes('--remotes'),
});
} catch (ex) {
Logger.error(ex);
await showGenericErrorMessage(ex);
}
}
continue;
}

await showGenericErrorMessage(ex);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function showGitVersionUnsupportedErrorMessage(
);
}

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

0 comments on commit 66762d4

Please sign in to comment.