|
| 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'; |
7 | | -import { showGenericErrorMessage } from '../../messages'; |
| 9 | +import { showGenericErrorMessage, showShouldCommitOrStashPrompt } from '../../messages'; |
8 | 10 | import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; |
9 | 11 | import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; |
10 | 12 | import { Logger } from '../../system/logger'; |
| 13 | +import { executeCommand, executeCoreCommand } from '../../system/vscode/command'; |
11 | 14 | import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; |
12 | 15 | import type { |
13 | 16 | PartialStepState, |
@@ -74,11 +77,37 @@ export class RevertGitCommand extends QuickCommand<State> { |
74 | 77 | } |
75 | 78 |
|
76 | 79 | async execute(state: RevertStepState<State<GitRevisionReference[]>>) { |
77 | | - const references = state.references.map(c => c.ref).reverse(); |
78 | | - for (const ref of references) { |
| 80 | + for (const ref of state.references.reverse()) { |
79 | 81 | try { |
80 | | - await state.repo.git.revert(ref, state.flags); |
| 82 | + await state.repo.git.revert(ref.ref, state.flags); |
81 | 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 | + |
82 | 111 | Logger.error(ex, this.title); |
83 | 112 | void showGenericErrorMessage(ex.message); |
84 | 113 | } |
|
0 commit comments