From 6ac6ebda3b8e70440f19955792f7dc6147bca285 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 25 Jul 2018 18:57:48 -0400 Subject: [PATCH] Changes commit search by sha to jump to commit directly --- CHANGELOG.md | 4 +++ src/commands/showCommitSearch.ts | 74 +++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce3f4c..c63615d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Changed +- Changes commit search by sha to jump directly to the commit (if one is found), rather than having to click through to the commit + ## [8.5.3] - 2018-07-25 ### Fixed - Fixes [#454](https://github.com/eamodio/vscode-gitlens/issues/454) - Search for string returns merge commits (unlike raw `git log -S`) diff --git a/src/commands/showCommitSearch.ts b/src/commands/showCommitSearch.ts index d547f05..75f0a82 100644 --- a/src/commands/showCommitSearch.ts +++ b/src/commands/showCommitSearch.ts @@ -6,6 +6,7 @@ import { GitRepoSearchBy, GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, CommitsQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickpicks'; import { Strings } from '../system'; +import { Iterables } from '../system/iterable'; import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common'; import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails'; @@ -125,7 +126,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { if (progressCancellation.token.isCancellationRequested) return undefined; - const goBackCommand = + let goBackCommand: CommandQuickPickItem | undefined = args.goBackCommand || new CommandQuickPickItem( { @@ -136,37 +137,48 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { [uri, originalArgs] ); - const pick = await CommitsQuickPick.show(log, searchLabel!, progressCancellation, { - goBackCommand: goBackCommand, - showAllCommand: - log !== undefined && log.truncated - ? new CommandQuickPickItem( - { - label: `$(sync) Show All Commits`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` - }, - Commands.ShowCommitSearch, - [uri, { ...args, maxCount: 0, goBackCommand: goBackCommand }] - ) - : undefined, - showInResultsExplorerCommand: - log !== undefined ? new ShowCommitsSearchInResultsQuickPickItem(log, searchLabel!) : undefined - }); - if (pick === undefined) return undefined; - - if (pick instanceof CommandQuickPickItem) return pick.execute(); + let commit; + if (args.searchBy !== GitRepoSearchBy.Sha || log === undefined || log.count !== 1) { + const pick = await CommitsQuickPick.show(log, searchLabel!, progressCancellation, { + goBackCommand: goBackCommand, + showAllCommand: + log !== undefined && log.truncated + ? new CommandQuickPickItem( + { + label: `$(sync) Show All Commits`, + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` + }, + Commands.ShowCommitSearch, + [uri, { ...args, maxCount: 0, goBackCommand: goBackCommand }] + ) + : undefined, + showInResultsExplorerCommand: + log !== undefined ? new ShowCommitsSearchInResultsQuickPickItem(log, searchLabel!) : undefined + }); + if (pick === undefined) return undefined; + + if (pick instanceof CommandQuickPickItem) return pick.execute(); + + commit = pick.commit; + goBackCommand = undefined; + } + else { + commit = Iterables.first(log.commits.values()); + } - return commands.executeCommand(Commands.ShowQuickCommitDetails, pick.commit.toGitUri(), { - sha: pick.commit.sha, - commit: pick.commit, - goBackCommand: new CommandQuickPickItem( - { - label: `go back ${GlyphChars.ArrowBack}`, - description: `${Strings.pad(GlyphChars.Dash, 2, 2)} to search for ${searchLabel}` - }, - Commands.ShowCommitSearch, - [uri, args] - ) + return commands.executeCommand(Commands.ShowQuickCommitDetails, commit.toGitUri(), { + sha: commit.sha, + commit: commit, + goBackCommand: + goBackCommand || + new CommandQuickPickItem( + { + label: `go back ${GlyphChars.ArrowBack}`, + description: `${Strings.pad(GlyphChars.Dash, 2, 2)} to search for ${searchLabel}` + }, + Commands.ShowCommitSearch, + [uri, args] + ) } as ShowQuickCommitDetailsCommandArgs); } catch (ex) {