Skip to content

Commit

Permalink
check also stderr for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Dec 12, 2024
1 parent 00c91d2 commit 05dff06
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
25 changes: 14 additions & 11 deletions src/commands/git/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ interface Context {
title: string;
}

type Flags = '--hard' | '--soft';
type ResetOptions = {
hard?: boolean;
soft?: boolean;
};

interface State {
repo: string | Repository;
reference: GitRevisionReference | GitTagReference;
flags: Flags[];
options: ResetOptions;
}

export interface ResetGitCommandArgs {
Expand Down Expand Up @@ -73,7 +76,7 @@ export class ResetGitCommand extends QuickCommand<State> {

async execute(state: ResetStepState) {
try {
await state.repo.git.reset(state.flags, state.reference.ref);
await state.repo.git.reset(state.options, state.reference.ref);
} catch (ex) {
Logger.error(ex, this.title);
void showGenericErrorMessage(ex.message);
Expand All @@ -89,8 +92,8 @@ export class ResetGitCommand extends QuickCommand<State> {
title: this.title,
};

if (state.flags == null) {
state.flags = [];
if (state.options == null) {
state.options = {};
}

let skippedStepOne = false;
Expand Down Expand Up @@ -159,7 +162,7 @@ export class ResetGitCommand extends QuickCommand<State> {
const result = yield* this.confirmStep(state as ResetStepState, context);
if (result === StepResultBreak) continue;

state.flags = result;
state.options = Object.assign({}, ...result);
}

endSteps(state);
Expand All @@ -169,24 +172,24 @@ export class ResetGitCommand extends QuickCommand<State> {
return state.counter < 0 ? StepResultBreak : undefined;
}

private *confirmStep(state: ResetStepState, context: Context): StepResultGenerator<Flags[]> {
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
private *confirmStep(state: ResetStepState, context: Context): StepResultGenerator<ResetOptions[]> {
const step: QuickPickStep<FlagsQuickPickItem<ResetOptions>> = this.createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<Flags>(state.flags, [], {
createFlagsQuickPickItem<ResetOptions>([], [], {
label: this.title,
detail: `Will reset (leaves changes in the working tree) ${getReferenceLabel(
context.destination,
)} to ${getReferenceLabel(state.reference)}`,
}),
createFlagsQuickPickItem<Flags>(state.flags, ['--soft'], {
createFlagsQuickPickItem<ResetOptions>([], [{ soft: true }], {
label: `Soft ${this.title}`,
description: '--soft',
detail: `Will soft reset (leaves changes in the index and working tree) ${getReferenceLabel(
context.destination,
)} to ${getReferenceLabel(state.reference)}`,
}),
createFlagsQuickPickItem<Flags>(state.flags, ['--hard'], {
createFlagsQuickPickItem<ResetOptions>([], [{ hard: true }], {
label: `Hard ${this.title}`,
description: '--hard',
detail: `Will hard reset (discards all changes) ${getReferenceLabel(
Expand Down
2 changes: 1 addition & 1 deletion src/env/node/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ export class Git {
} catch (ex) {
const msg: string = ex?.toString() ?? '';
for (const [error, reason] of resetErrorAndReason) {
if (error.test(msg)) {
if (error.test(msg) || error.test(ex.stderr ?? '')) {
throw new ResetError(reason, ex);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/git/actions/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export function rebase(repo?: string | Repository, ref?: GitReference, interacti
export function reset(
repo?: string | Repository,
ref?: GitRevisionReference | GitTagReference,
flags?: NonNullable<ResetGitCommandArgs['state']>['flags'],
options?: NonNullable<ResetGitCommandArgs['state']>['options'],
) {
return executeGitCommand({
command: 'reset',
confirm: flags == null || flags.includes('--hard'),
state: { repo: repo, reference: ref, flags: flags },
confirm: options == null || options.hard,
state: { repo: repo, reference: ref, options: options },
});
}

Expand Down
16 changes: 1 addition & 15 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,24 +1335,10 @@ export class GitProviderService implements Disposable {
}

@log()
async reset(repoPath: string, flags: string[], ref: string): Promise<void> {
async reset(repoPath: string, options: { hard?: boolean; soft?: boolean } = {}, ref: string): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
if (provider.reset == null) throw new ProviderNotSupportedError(provider.descriptor.name);

const options: { hard?: boolean; soft?: boolean } = {};
for (const flag of flags) {
switch (flag) {
case '--hard':
options.hard = true;
break;
case '--soft':
options.soft = true;
break;
default:
break;
}
}

return provider.reset(path, ref, options);
}

Expand Down

0 comments on commit 05dff06

Please sign in to comment.