Skip to content

Commit 028b32d

Browse files
committedDec 12, 2024··
simplify exception handler & remove retry
1 parent a8da06d commit 028b32d

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed
 

‎src/commands/git/revert.ts

+12-28
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ interface Context {
3232
title: string;
3333
}
3434

35-
type Flags = '--edit' | '--no-edit';
3635
type RevertOptions = { edit?: boolean };
3736

3837
interface State<Refs = GitRevisionReference | GitRevisionReference[]> {
3938
repo: string | Repository;
4039
references: Refs;
41-
flags: Flags[];
4240
options: RevertOptions;
4341
}
4442

@@ -83,28 +81,16 @@ export class RevertGitCommand extends QuickCommand<State> {
8381
try {
8482
await state.repo.git.revert(ref.ref, state.options);
8583
} catch (ex) {
86-
if (ex instanceof RevertError) {
87-
let shouldRetry = false;
88-
if (ex.reason === RevertErrorReason.LocalChangesWouldBeOverwritten) {
89-
const response = await showShouldCommitOrStashPrompt();
90-
if (response === 'Stash') {
91-
await executeCommand(Commands.GitCommandsStashPush);
92-
shouldRetry = true;
93-
} else if (response === 'Commit') {
94-
await executeCoreCommand('workbench.view.scm');
95-
shouldRetry = true;
96-
} else {
97-
continue;
98-
}
84+
if (RevertError.is(ex, RevertErrorReason.LocalChangesWouldBeOverwritten)) {
85+
const response = await showShouldCommitOrStashPrompt();
86+
if (response == null || response === 'Cancel') {
87+
continue;
9988
}
10089

101-
if (shouldRetry) {
102-
try {
103-
await state.repo.git.revert(ref.ref, state.flags);
104-
} catch (ex) {
105-
Logger.error(ex, this.title);
106-
void showGenericErrorMessage(ex.message);
107-
}
90+
if (response === 'Stash') {
91+
await executeCommand(Commands.GitCommandsStashPush);
92+
} else if (response === 'Commit') {
93+
await executeCoreCommand('workbench.view.scm');
10894
}
10995

11096
continue;
@@ -125,8 +111,8 @@ export class RevertGitCommand extends QuickCommand<State> {
125111
title: this.title,
126112
};
127113

128-
if (state.flags == null) {
129-
state.flags = [];
114+
if (state.options == null) {
115+
state.options = {};
130116
}
131117

132118
if (state.references != null && !Array.isArray(state.references)) {
@@ -208,23 +194,21 @@ export class RevertGitCommand extends QuickCommand<State> {
208194
}
209195

210196
private *confirmStep(state: RevertStepState, context: Context): StepResultGenerator<RevertOptions[]> {
211-
const optionsArr: RevertOptions[] = [];
212197
const step: QuickPickStep<FlagsQuickPickItem<RevertOptions>> = this.createConfirmStep(
213198
appendReposToTitle(`Confirm ${context.title}`, state, context),
214199
[
215-
createFlagsQuickPickItem<RevertOptions>(optionsArr, [{ edit: false }], {
200+
createFlagsQuickPickItem<RevertOptions>([], [{ edit: false }], {
216201
label: this.title,
217202
description: '--no-edit',
218203
detail: `Will revert ${getReferenceLabel(state.references)}`,
219204
}),
220-
createFlagsQuickPickItem<RevertOptions>(optionsArr, [{ edit: true }], {
205+
createFlagsQuickPickItem<RevertOptions>([], [{ edit: true }], {
221206
label: `${this.title} & Edit`,
222207
description: '--edit',
223208
detail: `Will revert and edit ${getReferenceLabel(state.references)}`,
224209
}),
225210
],
226211
);
227-
state.options = Object.assign({}, ...optionsArr);
228212
const selection: StepSelection<typeof step> = yield step;
229213
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
230214
}

0 commit comments

Comments
 (0)
Please sign in to comment.