|
| 1 | +import { Commands } from '../../constants.commands'; |
1 | 2 | import type { Container } from '../../container';
|
| 3 | +import { RevertError, RevertErrorReason } from '../../git/errors'; |
2 | 4 | import type { GitBranch } from '../../git/models/branch';
|
3 | 5 | import type { GitLog } from '../../git/models/log';
|
4 | 6 | import type { GitRevisionReference } from '../../git/models/reference';
|
5 | 7 | import { getReferenceLabel } from '../../git/models/reference';
|
6 | 8 | import type { Repository } from '../../git/models/repository';
|
| 9 | +import { showGenericErrorMessage, showShouldCommitOrStashPrompt } from '../../messages'; |
7 | 10 | import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
|
8 | 11 | import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
|
| 12 | +import { Logger } from '../../system/logger'; |
| 13 | +import { executeCommand, executeCoreCommand } from '../../system/vscode/command'; |
9 | 14 | import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
|
10 | 15 | import type {
|
11 | 16 | PartialStepState,
|
@@ -71,8 +76,42 @@ export class RevertGitCommand extends QuickCommand<State> {
|
71 | 76 | return false;
|
72 | 77 | }
|
73 | 78 |
|
74 |
| - execute(state: RevertStepState<State<GitRevisionReference[]>>) { |
75 |
| - state.repo.revert(...state.flags, ...state.references.map(c => c.ref).reverse()); |
| 79 | + async execute(state: RevertStepState<State<GitRevisionReference[]>>) { |
| 80 | + for (const ref of state.references.reverse()) { |
| 81 | + try { |
| 82 | + await state.repo.git.revert(ref.ref, state.flags); |
| 83 | + } catch (ex) { |
| 84 | + if (ex instanceof RevertError) { |
| 85 | + let shouldRetry = false; |
| 86 | + if (ex.reason === RevertErrorReason.LocalChangesWouldBeOverwritten) { |
| 87 | + const response = await showShouldCommitOrStashPrompt(); |
| 88 | + if (response === 'Stash') { |
| 89 | + await executeCommand(Commands.GitCommandsStashPush); |
| 90 | + shouldRetry = true; |
| 91 | + } else if (response === 'Commit') { |
| 92 | + await executeCoreCommand('workbench.view.scm'); |
| 93 | + shouldRetry = true; |
| 94 | + } else { |
| 95 | + continue; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + if (shouldRetry) { |
| 100 | + try { |
| 101 | + await state.repo.git.revert(ref.ref, state.flags); |
| 102 | + } catch (ex) { |
| 103 | + Logger.error(ex, this.title); |
| 104 | + void showGenericErrorMessage(ex.message); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + continue; |
| 109 | + } |
| 110 | + |
| 111 | + Logger.error(ex, this.title); |
| 112 | + void showGenericErrorMessage(ex.message); |
| 113 | + } |
| 114 | + } |
76 | 115 | }
|
77 | 116 |
|
78 | 117 | protected async *steps(state: PartialStepState<State>): StepGenerator {
|
@@ -160,7 +199,7 @@ export class RevertGitCommand extends QuickCommand<State> {
|
160 | 199 | state.flags = result;
|
161 | 200 |
|
162 | 201 | endSteps(state);
|
163 |
| - this.execute(state as RevertStepState<State<GitRevisionReference[]>>); |
| 202 | + await this.execute(state as RevertStepState<State<GitRevisionReference[]>>); |
164 | 203 | }
|
165 | 204 |
|
166 | 205 | return state.counter < 0 ? StepResultBreak : undefined;
|
|
0 commit comments