From 12630641500b92f75ac0ac215738a552487b7feb Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 18 Feb 2017 17:20:28 -0500 Subject: [PATCH] Changes behavior of showing uncommit changes Now shows the previous commit details --- src/commands/quickPicks.ts | 15 ++++++++++++--- src/commands/showQuickCommitDetails.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/commands/quickPicks.ts b/src/commands/quickPicks.ts index f91668f..ae20106 100644 --- a/src/commands/quickPicks.ts +++ b/src/commands/quickPicks.ts @@ -3,7 +3,7 @@ import { Iterables } from '../system'; import { QuickPickOptions, Uri, window, workspace } from 'vscode'; import { IAdvancedConfig } from '../configuration'; import { Commands } from '../constants'; -import { GitCommit, GitUri, IGitLog } from '../gitProvider'; +import GitProvider, { GitCommit, GitUri, IGitLog } from '../gitProvider'; import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPickItems'; import * as moment from 'moment'; import * as path from 'path'; @@ -14,9 +14,18 @@ function getQuickPickIgnoreFocusOut() { export class CommitQuickPick { - static async show(commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise { + static async show(git: GitProvider, commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise { const items: CommandQuickPickItem[] = []; + const isUncommitted = commit.isUncommitted; + if (isUncommitted) { + // Since we can't trust the previous sha on an uncommitted commit, find the last commit for this file + const log = await git.getLogForFile(commit.uri.fsPath, undefined, undefined, undefined, 2); + if (!log) return undefined; + + commit = Iterables.first(log.commits.values()); + } + if (commit.previousSha) { items.push(new CommandQuickPickItem({ label: `$(git-compare) Compare with Previous Commit`, @@ -71,7 +80,7 @@ export class CommitQuickPick { return await window.showQuickPick(items, { matchOnDescription: true, - placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, + placeHolder: `${commit.fileName} \u2022 ${isUncommitted ? 'Uncommitted changes showing ' : '' } ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, ignoreFocusOut: getQuickPickIgnoreFocusOut() } as QuickPickOptions); } diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index 709ec1f..7b7da65 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -80,7 +80,7 @@ export default class ShowQuickCommitDetailsCommand extends ActiveEditorCommand { workingFileName = !workingCommit ? commit.fileName : undefined; } - pick = await CommitQuickPick.show(commit, workingFileName, uri, + pick = await CommitQuickPick.show(this.git, commit, workingFileName, uri, // Create a command to get back to where we are right now new CommandQuickPickItem({ label: `go back \u21A9`,