From 231b0077b9871e0a0407cf720e3921227b377239 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 22 Nov 2019 23:54:24 -0500 Subject: [PATCH] Fixes #910 - show in search failed from views --- src/commands/showCommitsInView.ts | 42 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/commands/showCommitsInView.ts b/src/commands/showCommitsInView.ts index 9c6d3a7..228e82a 100644 --- a/src/commands/showCommitsInView.ts +++ b/src/commands/showCommitsInView.ts @@ -23,8 +23,6 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand { args = { ...args }; if (args.refs === undefined) { - if (editor == null) return undefined; - uri = getCommandUri(uri, editor); if (uri == null) return undefined; @@ -32,23 +30,33 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand { args.repoPath = gitUri.repoPath; - try { - // Check for any uncommitted changes in the range - const blame = editor.document.isDirty - ? await Container.git.getBlameForRangeContents(gitUri, editor.selection, editor.document.getText()) - : await Container.git.getBlameForRange(gitUri, editor.selection); - if (blame === undefined) { - return Messages.showFileNotUnderSourceControlWarningMessage( - 'Unable to show commits in Search Commits view' - ); + if (editor != null) { + try { + // Check for any uncommitted changes in the range + const blame = editor.document.isDirty + ? await Container.git.getBlameForRangeContents( + gitUri, + editor.selection, + editor.document.getText() + ) + : await Container.git.getBlameForRange(gitUri, editor.selection); + if (blame === undefined) { + return Messages.showFileNotUnderSourceControlWarningMessage( + 'Unable to show commits in Search Commits view' + ); + } + + args.refs = [ + ...Iterables.filterMap(blame.commits.values(), c => (c.isUncommitted ? undefined : c.ref)) + ]; + } catch (ex) { + Logger.error(ex, 'ShowCommitsInViewCommand', 'getBlameForRange'); + return Messages.showGenericErrorMessage('Unable to show commits in Search Commits view'); } + } else { + if (gitUri.sha == null) return undefined; - args.refs = [ - ...Iterables.filterMap(blame.commits.values(), c => (c.isUncommitted ? undefined : c.ref)) - ]; - } catch (ex) { - Logger.error(ex, 'ShowCommitsInViewCommand', 'getBlameForRange'); - return Messages.showGenericErrorMessage('Unable to show commits in Search Commits view'); + args.refs = [gitUri.sha]; } }