mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Changes behavior of showing uncommit changes
Now shows the previous commit details
This commit is contained in:
@@ -3,7 +3,7 @@ import { Iterables } from '../system';
|
|||||||
import { QuickPickOptions, Uri, window, workspace } from 'vscode';
|
import { QuickPickOptions, Uri, window, workspace } from 'vscode';
|
||||||
import { IAdvancedConfig } from '../configuration';
|
import { IAdvancedConfig } from '../configuration';
|
||||||
import { Commands } from '../constants';
|
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 { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPickItems';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
@@ -14,9 +14,18 @@ function getQuickPickIgnoreFocusOut() {
|
|||||||
|
|
||||||
export class CommitQuickPick {
|
export class CommitQuickPick {
|
||||||
|
|
||||||
static async show(commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise<CommandQuickPickItem | undefined> {
|
static async show(git: GitProvider, commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise<CommandQuickPickItem | undefined> {
|
||||||
const items: CommandQuickPickItem[] = [];
|
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) {
|
if (commit.previousSha) {
|
||||||
items.push(new CommandQuickPickItem({
|
items.push(new CommandQuickPickItem({
|
||||||
label: `$(git-compare) Compare with Previous Commit`,
|
label: `$(git-compare) Compare with Previous Commit`,
|
||||||
@@ -71,7 +80,7 @@ export class CommitQuickPick {
|
|||||||
|
|
||||||
return await window.showQuickPick(items, {
|
return await window.showQuickPick(items, {
|
||||||
matchOnDescription: true,
|
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()
|
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||||
} as QuickPickOptions);
|
} as QuickPickOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export default class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
|||||||
workingFileName = !workingCommit ? commit.fileName : undefined;
|
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
|
// Create a command to get back to where we are right now
|
||||||
new CommandQuickPickItem({
|
new CommandQuickPickItem({
|
||||||
label: `go back \u21A9`,
|
label: `go back \u21A9`,
|
||||||
|
|||||||
Reference in New Issue
Block a user