Adds shortcut for gitlens.showQuickFileHistory

Adds shortcut for gitlens.showQuickRepoHistory
Adds gitlens.advanced.maxQuickHistory to limit the number of quick history entries to show
Adds gitlens.diffLineWithPrevious as alt context menu item for gitlens.diffWithPrevious
Adds gitlens.diffLineWithWorking as alt context menu item for gitlens.diffWithWorking
Adds gitlens.showFileHistory as alt context menu item for gitlens.showQuickFileHistory
Removes context menu for gitlens.diffLineWithPrevious
Removes context menu for gitlens.diffLineWithWorking
Replaces gitlens.menus.fileDiff.enabled & gitlens.menus.lineDiff.enabled with gitlens.menus.diff.enabled
This commit is contained in:
Eric Amodio
2017-01-02 00:39:26 -05:00
parent 567533622c
commit 680d31d43d
11 changed files with 260 additions and 191 deletions

View File

@@ -1,18 +1,19 @@
'use strict';
import { Iterables } from '../system';
import { commands, QuickPickOptions, Uri, window } from 'vscode';
import { commands, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Command } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { CommitQuickPickItem, CompareQuickPickItem, FileQuickPickItem } from './quickPickItems';
import { CommitQuickPickItem, CompareQuickPickItem, FileQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
import * as moment from 'moment';
export default class ShowQuickRepoHistoryCommand extends Command {
constructor(private git: GitProvider, public repoPath: string) {
super(Commands.ShowQuickRepoHistory);
}
async execute(uri?: Uri) {
async execute(uri?: Uri, maxCount?: number) {
if (!(uri instanceof Uri)) {
const document = window.activeTextEditor && window.activeTextEditor.document;
if (document) {
@@ -20,6 +21,10 @@ export default class ShowQuickRepoHistoryCommand extends Command {
}
}
if (maxCount == null) {
maxCount = this.git.config.advanced.maxQuickHistory;
}
try {
let repoPath: string;
if (uri instanceof Uri) {
@@ -37,57 +42,68 @@ export default class ShowQuickRepoHistoryCommand extends Command {
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
const log = await this.git.getLogForRepo(repoPath);
const log = await this.git.getLogForRepo(repoPath, maxCount);
if (!log) return window.showWarningMessage(`Unable to show repository history`);
const items = Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`));
const commitPick = await window.showQuickPick(Array.from(items), <QuickPickOptions>{
const commits = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`))) as QuickPickItem[];
let placeHolder = '';
if (maxCount !== 0 && commits.length === this.git.config.advanced.maxQuickHistory) {
placeHolder = `Only showing the first ${this.git.config.advanced.maxQuickHistory} commits`;
commits.push(new ShowAllCommitsQuickPickItem(this.git.config.advanced.maxQuickHistory));
}
const pick = await window.showQuickPick(commits, {
matchOnDescription: true,
matchOnDetail: true
});
matchOnDetail: true,
placeHolder: placeHolder
} as QuickPickOptions);
if (commitPick) {
const items = commitPick.commit.fileName.split(', ').map(f => new FileQuickPickItem(commitPick.commit, f));
const filePick = await window.showQuickPick(items, <QuickPickOptions>{
matchOnDescription: true,
matchOnDetail: true,
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()}`
});
if (!pick) return undefined;
if (pick instanceof ShowAllCommitsQuickPickItem) {
return commands.executeCommand(Commands.ShowQuickRepoHistory, uri, 0);
}
if (filePick) {
const log = await this.git.getLogForFile(filePick.uri.fsPath);
if (!log) return window.showWarningMessage(`Unable to open diff`);
const commitPick = pick as CommitQuickPickItem;
const files = commitPick.commit.fileName.split(', ').map(f => new FileQuickPickItem(commitPick.commit, f));
const filePick = await window.showQuickPick(files, {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()}`
} as QuickPickOptions);
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
if (filePick) {
const log = await this.git.getLogForFile(filePick.uri.fsPath);
if (!log) return window.showWarningMessage(`Unable to open diff`);
let command: Commands | undefined = Commands.DiffWithWorking;
if (commit.previousSha) {
const items: CompareQuickPickItem[] = [
{
label: `Compare with Working Tree`,
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
detail: null,
command: Commands.DiffWithWorking
},
{
label: `Compare with Previous Commit`,
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
detail: null,
command: Commands.DiffWithPrevious
}
];
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
const comparePick = await window.showQuickPick(items, <QuickPickOptions>{
matchOnDescription: true,
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
});
let command: Commands | undefined = Commands.DiffWithWorking;
if (commit.previousSha) {
const items: CompareQuickPickItem[] = [
{
label: `Compare with Working Tree`,
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
detail: null,
command: Commands.DiffWithWorking
},
{
label: `Compare with Previous Commit`,
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
detail: null,
command: Commands.DiffWithPrevious
}
];
command = comparePick ? comparePick.command : undefined;
}
const comparePick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
} as QuickPickOptions);
if (command) {
return commands.executeCommand(command, commit.uri, commit);
}
command = comparePick ? comparePick.command : undefined;
}
if (command) {
return commands.executeCommand(command, commit.uri, commit);
}
}