Skip to content

Commit 8755618

Browse files
committed
check also stderr for errors
1 parent 56582fb commit 8755618

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

src/commands/git/reset.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ interface Context {
2929
title: string;
3030
}
3131

32-
type Flags = '--hard' | '--soft';
32+
type ResetOptions = {
33+
hard?: boolean;
34+
soft?: boolean;
35+
};
3336

3437
interface State {
3538
repo: string | Repository;
3639
reference: GitRevisionReference | GitTagReference;
37-
flags: Flags[];
40+
options: ResetOptions;
3841
}
3942

4043
export interface ResetGitCommandArgs {
@@ -73,7 +76,7 @@ export class ResetGitCommand extends QuickCommand<State> {
7376

7477
async execute(state: ResetStepState) {
7578
try {
76-
await state.repo.git.reset(state.flags, state.reference.ref);
79+
await state.repo.git.reset(state.options, state.reference.ref);
7780
} catch (ex) {
7881
Logger.error(ex, this.title);
7982
void showGenericErrorMessage(ex.message);
@@ -89,8 +92,8 @@ export class ResetGitCommand extends QuickCommand<State> {
8992
title: this.title,
9093
};
9194

92-
if (state.flags == null) {
93-
state.flags = [];
95+
if (state.options == null) {
96+
state.options = {};
9497
}
9598

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

162-
state.flags = result;
165+
state.options = Object.assign({}, ...result);
163166
}
164167

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

172-
private *confirmStep(state: ResetStepState, context: Context): StepResultGenerator<Flags[]> {
173-
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
175+
private *confirmStep(state: ResetStepState, context: Context): StepResultGenerator<ResetOptions[]> {
176+
const step: QuickPickStep<FlagsQuickPickItem<ResetOptions>> = this.createConfirmStep(
174177
appendReposToTitle(`Confirm ${context.title}`, state, context),
175178
[
176-
createFlagsQuickPickItem<Flags>(state.flags, [], {
179+
createFlagsQuickPickItem<ResetOptions>([], [], {
177180
label: this.title,
178181
detail: `Will reset (leaves changes in the working tree) ${getReferenceLabel(
179182
context.destination,
180183
)} to ${getReferenceLabel(state.reference)}`,
181184
}),
182-
createFlagsQuickPickItem<Flags>(state.flags, ['--soft'], {
185+
createFlagsQuickPickItem<ResetOptions>([], [{ soft: true }], {
183186
label: `Soft ${this.title}`,
184187
description: '--soft',
185188
detail: `Will soft reset (leaves changes in the index and working tree) ${getReferenceLabel(
186189
context.destination,
187190
)} to ${getReferenceLabel(state.reference)}`,
188191
}),
189-
createFlagsQuickPickItem<Flags>(state.flags, ['--hard'], {
192+
createFlagsQuickPickItem<ResetOptions>([], [{ hard: true }], {
190193
label: `Hard ${this.title}`,
191194
description: '--hard',
192195
detail: `Will hard reset (discards all changes) ${getReferenceLabel(

src/env/node/git/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ export class Git {
16031603
} catch (ex) {
16041604
const msg: string = ex?.toString() ?? '';
16051605
for (const [error, reason] of resetErrorAndReason) {
1606-
if (error.test(msg)) {
1606+
if (error.test(msg) || error.test(ex.stderr ?? '')) {
16071607
throw new ResetError(reason, ex);
16081608
}
16091609
}

src/git/actions/repository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export function rebase(repo?: string | Repository, ref?: GitReference, interacti
4141
export function reset(
4242
repo?: string | Repository,
4343
ref?: GitRevisionReference | GitTagReference,
44-
flags?: NonNullable<ResetGitCommandArgs['state']>['flags'],
44+
options?: NonNullable<ResetGitCommandArgs['state']>['options'],
4545
) {
4646
return executeGitCommand({
4747
command: 'reset',
48-
confirm: flags == null || flags.includes('--hard'),
49-
state: { repo: repo, reference: ref, flags: flags },
48+
confirm: options == null || options.hard,
49+
state: { repo: repo, reference: ref, options: options },
5050
});
5151
}
5252

src/git/gitProviderService.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,24 +1335,10 @@ export class GitProviderService implements Disposable {
13351335
}
13361336

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

1342-
const options: { hard?: boolean; soft?: boolean } = {};
1343-
for (const flag of flags) {
1344-
switch (flag) {
1345-
case '--hard':
1346-
options.hard = true;
1347-
break;
1348-
case '--soft':
1349-
options.soft = true;
1350-
break;
1351-
default:
1352-
break;
1353-
}
1354-
}
1355-
13561342
return provider.reset(path, ref, options);
13571343
}
13581344

0 commit comments

Comments
 (0)