-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3530 Change revert
terminal-run commands into normal commands w/ proper error handling
#3789
base: main
Are you sure you want to change the base?
3530 Change revert
terminal-run commands into normal commands w/ proper error handling
#3789
Conversation
b3280b6
to
5d90ed8
Compare
5d90ed8
to
bf93067
Compare
bf93067
to
87b29d1
Compare
async revert(repoPath: string | Uri, ref: string, flags: string[] | undefined = []): Promise<void> { | ||
const { provider, path } = this.getProvider(repoPath); | ||
if (provider.revert == null) throw new ProviderNotSupportedError(provider.descriptor.name); | ||
|
||
const options: { edit?: boolean } = {}; | ||
for (const flag of flags) { | ||
switch (flag) { | ||
case '--edit': | ||
options.edit = true; | ||
break; | ||
case '--no-edit': | ||
options.edit = false; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
return provider.revert(path, ref, options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is a pattern in other places or not but, why at the git provider service level should the caller provide flags instead of just passing in options? Flags feel like low-level terminal args that should be abstracted down to the git.ts
level and anything coming in from above should really only be dealing with a list of options.
async revert(repoPath: string, ...args: string[]) { | ||
try { | ||
await this.git<string>({ cwd: repoPath }, 'revert', ...args); | ||
} catch (ex) { | ||
const msg: string = ex?.toString() ?? ''; | ||
for (const [error, reason] of revertErrorAndReason) { | ||
if (error.test(msg) || error.test(ex.stderr ?? '')) { | ||
throw new RevertError(reason, ex); | ||
} | ||
} | ||
|
||
throw new RevertError(RevertErrorReason.Other, ex); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take constrained options, generate the flags and params necessary off of those options, and then run the command with the args it generated.
for (const ref of state.references.reverse()) { | ||
try { | ||
await state.repo.git.revert(ref.ref, state.flags); | ||
} catch (ex) { | ||
if (ex instanceof RevertError) { | ||
let shouldRetry = false; | ||
if (ex.reason === RevertErrorReason.LocalChangesWouldBeOverwritten) { | ||
const response = await showShouldCommitOrStashPrompt(); | ||
if (response === 'Stash') { | ||
await executeCommand(Commands.GitCommandsStashPush); | ||
shouldRetry = true; | ||
} else if (response === 'Commit') { | ||
await executeCoreCommand('workbench.view.scm'); | ||
shouldRetry = true; | ||
} else { | ||
continue; | ||
} | ||
} | ||
|
||
if (shouldRetry) { | ||
try { | ||
await state.repo.git.revert(ref.ref, state.flags); | ||
} catch (ex) { | ||
Logger.error(ex, this.title); | ||
void showGenericErrorMessage(ex.message); | ||
} | ||
} | ||
|
||
continue; | ||
} | ||
|
||
Logger.error(ex, this.title); | ||
void showGenericErrorMessage(ex.message); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably going to result in me receiving a crash course on git revert flows, but for my own education, can you explain what this is doing?
Description
This task creates the git revert commands to move away from runTerminalCommand
Solves #3530
Checklist
Fixes $XXX -
orCloses #XXX -
prefix to auto-close the issue that your PR addresses