From a182660a4db87c391b15c7b89e89b9293a0f2bbd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 21 Jan 2020 21:53:24 -0500 Subject: [PATCH] Fixes issues with stash command errors --- src/commands/git/stash.ts | 18 +++++++++++------- src/system/decorators/gate.ts | 25 ++++++++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index e8df61c..a92440f 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -274,11 +274,15 @@ export class StashGitCommand extends QuickCommandBase { ) ) { void window.showWarningMessage( - 'Unable to apply stash. Your working tree changes would be overwritten' + 'Unable to apply stash. Your working tree changes would be overwritten. Please commit or stash your changes before trying again' ); return undefined; - } else if (ex.message.includes('Auto-merging') && ex.message.includes('CONFLICT')) { + } else if ( + (ex.message.includes('Auto-merging') && ex.message.includes('CONFLICT')) || + (ex.stdout?.includes('Auto-merging') && ex.stdout?.includes('CONFLICT')) || + ex.stdout?.includes('needs merge') + ) { void window.showInformationMessage('Stash applied with conflicts'); return undefined; @@ -445,7 +449,7 @@ export class StashGitCommand extends QuickCommandBase { state.subcommand = selection[0].command; } - void state.repo.stashApply(state.stash!.stashName, { deleteAfter: state.subcommand === 'pop' }); + void (await state.repo.stashApply(state.stash!.stashName, { deleteAfter: state.subcommand === 'pop' })); throw new BreakQuickCommand(); } @@ -556,7 +560,7 @@ export class StashGitCommand extends QuickCommandBase { break; } - void state.repo.stashDelete(state.stash.stashName); + void (await state.repo.stashDelete(state.stash.stashName)); throw new BreakQuickCommand(); } @@ -653,7 +657,7 @@ export class StashGitCommand extends QuickCommandBase { const command = selection[0]; if (command instanceof CommandQuickPickItem) { - command.execute(); + void (await command.execute()); throw new BreakQuickCommand(); } @@ -743,10 +747,10 @@ export class StashGitCommand extends QuickCommandBase { state.flags = selection[0].item; } - void state.repo.stashSave(state.message, state.uris, { + void (await state.repo.stashSave(state.message, state.uris, { includeUntracked: state.flags.includes('--include-untracked'), keepIndex: state.flags.includes('--keep-index') - }); + })); throw new BreakQuickCommand(); } diff --git a/src/system/decorators/gate.ts b/src/system/decorators/gate.ts index 3159833..b28ae5d 100644 --- a/src/system/decorators/gate.ts +++ b/src/system/decorators/gate.ts @@ -45,15 +45,26 @@ export function gate any>(resolver?: (...args: Parame let promise = this[prop]; if (promise === undefined) { - const result = fn!.apply(this, args); - if (result == null || !Promises.is(result)) { - return result; - } + let result; + try { + result = fn!.apply(this, args); + if (result == null || !Promises.is(result)) { + return result; + } - this[prop] = promise = result.then((r: any) => { + this[prop] = promise = result + .then((r: any) => { + this[prop] = undefined; + return r; + }) + .catch(ex => { + this[prop] = undefined; + throw ex; + }); + } catch (ex) { this[prop] = undefined; - return r; - }); + throw ex; + } } return promise;