mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Refactors the quickpick menus
Consolidated lots of duplicate functionality go back navigation should be robust now
This commit is contained in:
@@ -1,13 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { QuickPickItem, Uri } from 'vscode';
|
import { commands, QuickPickItem, Uri } from 'vscode';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import { GitCommit, GitUri } from '../gitProvider';
|
import { GitCommit, GitUri } from '../gitProvider';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export interface CommandQuickPickItem extends QuickPickItem {
|
export class CommandQuickPickItem implements QuickPickItem {
|
||||||
command: Commands;
|
label: string;
|
||||||
args?: any[];
|
description: string;
|
||||||
|
detail: string;
|
||||||
|
|
||||||
|
constructor(item: QuickPickItem, public command: Commands, public args?: any[]) {
|
||||||
|
Object.assign(this, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
execute() {
|
||||||
|
return commands.executeCommand(this.command, ...(this.args || []));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CommitQuickPickItem implements QuickPickItem {
|
export class CommitQuickPickItem implements QuickPickItem {
|
||||||
@@ -28,25 +37,14 @@ export class FileQuickPickItem implements QuickPickItem {
|
|||||||
label: string;
|
label: string;
|
||||||
description: string;
|
description: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
|
|
||||||
sha: string;
|
sha: string;
|
||||||
uri: GitUri;
|
uri: GitUri;
|
||||||
|
|
||||||
constructor(commit: GitCommit, public fileName: string) {
|
constructor(commit: GitCommit, public fileName: string) {
|
||||||
this.label = fileName;
|
this.label = fileName;
|
||||||
|
|
||||||
this.sha = commit.sha;
|
this.sha = commit.sha;
|
||||||
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName)));
|
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export class ShowAllCommitsQuickPickItem implements QuickPickItem {
|
|
||||||
|
|
||||||
label: string;
|
|
||||||
description: string;
|
|
||||||
detail: string;
|
|
||||||
|
|
||||||
constructor(maxItems: number) {
|
|
||||||
this.label = `$(sync) Show Full History`;
|
|
||||||
this.description = `\u2014 Currently only showing the first ${maxItems} commits`;
|
|
||||||
this.detail = `This may take a while`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
132
src/commands/quickPicks.ts
Normal file
132
src/commands/quickPicks.ts
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
'use strict';
|
||||||
|
import { Iterables } from '../system';
|
||||||
|
import { QuickPickOptions, Uri, window } from 'vscode';
|
||||||
|
import { Commands } from '../constants';
|
||||||
|
import { GitCommit, GitUri, IGitLog } from '../gitProvider';
|
||||||
|
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem } from './quickPickItems';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export class CommitQuickPick {
|
||||||
|
|
||||||
|
static async show(commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise<CommandQuickPickItem | undefined> {
|
||||||
|
const fileName = path.basename(commit.fileName);
|
||||||
|
|
||||||
|
const items: CommandQuickPickItem[] = [
|
||||||
|
new CommandQuickPickItem({
|
||||||
|
label: `$(diff) Compare with Working Tree`,
|
||||||
|
description: `$(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${workingFileName || commit.fileName}`
|
||||||
|
}, Commands.DiffWithWorking, [uri, commit])
|
||||||
|
];
|
||||||
|
|
||||||
|
if (commit.previousSha) {
|
||||||
|
items.push(new CommandQuickPickItem({
|
||||||
|
label: `$(diff) Compare with Previous Commit`,
|
||||||
|
description: `$(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}`
|
||||||
|
}, Commands.DiffWithPrevious, [commit.uri, commit]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.showFileHistory) {
|
||||||
|
items.push(new CommandQuickPickItem({
|
||||||
|
label: `$(versions) Show History of ${fileName}`,
|
||||||
|
description: `\u2022 since $(git-commit) ${commit.sha}`
|
||||||
|
}, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, currentCommand]));
|
||||||
|
|
||||||
|
if (workingFileName) {
|
||||||
|
items.push(new CommandQuickPickItem({
|
||||||
|
label: `$(versions) Show Full History of ${fileName}`,
|
||||||
|
description: null
|
||||||
|
}, Commands.ShowQuickFileHistory, [commit.uri, undefined, currentCommand]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goBackCommand) {
|
||||||
|
items.splice(0, 0, goBackCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await window.showQuickPick(items, {
|
||||||
|
matchOnDescription: true,
|
||||||
|
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
||||||
|
} as QuickPickOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CommitFilesQuickPick {
|
||||||
|
|
||||||
|
static async show(commit: GitCommit, uri: Uri, goBackCommand?: CommandQuickPickItem): Promise<FileQuickPickItem | CommandQuickPickItem | undefined> {
|
||||||
|
const items: (FileQuickPickItem | CommandQuickPickItem)[] = commit.fileName
|
||||||
|
.split(', ')
|
||||||
|
.filter(_ => !!_)
|
||||||
|
.map(f => new FileQuickPickItem(commit, f));
|
||||||
|
|
||||||
|
if (goBackCommand) {
|
||||||
|
items.splice(0, 0, goBackCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await window.showQuickPick(items, {
|
||||||
|
matchOnDescription: true,
|
||||||
|
matchOnDetail: true,
|
||||||
|
placeHolder: `${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
||||||
|
} as QuickPickOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FileCommitsQuickPick {
|
||||||
|
|
||||||
|
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||||
|
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
|
||||||
|
|
||||||
|
// Only show the full repo option if we are the root
|
||||||
|
if (!goBackCommand) {
|
||||||
|
items.splice(0, 0, new CommandQuickPickItem({
|
||||||
|
label: `$(repo) Show Repository History`,
|
||||||
|
description: null
|
||||||
|
}, Commands.ShowQuickRepoHistory, [undefined, undefined, undefined, new CommandQuickPickItem({
|
||||||
|
label: `go back \u21A9`,
|
||||||
|
description: null
|
||||||
|
}, Commands.ShowQuickFileHistory, [uri, maxCount])]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxCount !== 0 && items.length === defaultMaxCount) {
|
||||||
|
items.splice(0, 0, new CommandQuickPickItem({
|
||||||
|
label: `$(sync) Show Full History`,
|
||||||
|
description: `\u2014 Currently only showing the first ${defaultMaxCount} commits`,
|
||||||
|
detail: `This may take a while`
|
||||||
|
}, Commands.ShowQuickFileHistory, [uri, 0, goBackCommand]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goBackCommand) {
|
||||||
|
items.splice(0, 0, goBackCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await window.showQuickPick(items, {
|
||||||
|
matchOnDescription: true,
|
||||||
|
matchOnDetail: true,
|
||||||
|
placeHolder: `${Iterables.first(log.commits.values()).fileName}`
|
||||||
|
} as QuickPickOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RepoCommitsQuickPick {
|
||||||
|
|
||||||
|
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||||
|
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`))) as (CommitQuickPickItem | CommandQuickPickItem)[];
|
||||||
|
if (maxCount !== 0 && items.length === defaultMaxCount) {
|
||||||
|
items.splice(0, 0, new CommandQuickPickItem({
|
||||||
|
label: `$(sync) Show Full History`,
|
||||||
|
description: `\u2014 Currently only showing the first ${defaultMaxCount} commits`,
|
||||||
|
detail: `This may take a while`
|
||||||
|
}, Commands.ShowQuickRepoHistory, [uri, 0, undefined, goBackCommand]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goBackCommand) {
|
||||||
|
items.splice(0, 0, goBackCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await window.showQuickPick(items, {
|
||||||
|
matchOnDescription: true,
|
||||||
|
matchOnDetail: true,
|
||||||
|
placeHolder: 'Search by commit message, filename, or sha'
|
||||||
|
} as QuickPickOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { commands, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
import { TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||||
import { EditorCommand } from './commands';
|
import { EditorCommand } from './commands';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import GitProvider, { GitUri } from '../gitProvider';
|
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem } from './quickPickItems';
|
import { CommandQuickPickItem, FileQuickPickItem } from './quickPickItems';
|
||||||
import * as moment from 'moment';
|
import { CommitQuickPick, CommitFilesQuickPick } from './quickPicks';
|
||||||
|
|
||||||
export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
|||||||
super(Commands.ShowQuickCommitDetails);
|
super(Commands.ShowQuickCommitDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string) {
|
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, commit?: GitCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }) {
|
||||||
if (!(uri instanceof Uri)) {
|
if (!(uri instanceof Uri)) {
|
||||||
if (!editor.document) return undefined;
|
if (!editor.document) return undefined;
|
||||||
uri = editor.document.uri;
|
uri = editor.document.uri;
|
||||||
@@ -43,78 +43,60 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let log = await this.git.getLogForRepo(repoPath, sha, 0);
|
let pick: FileQuickPickItem | CommandQuickPickItem;
|
||||||
if (!log) return window.showWarningMessage(`Unable to show commit details`);
|
let alreadyPickedCommit = !!commit;
|
||||||
|
let workingFileName: string;
|
||||||
|
if (!alreadyPickedCommit) {
|
||||||
|
let log = await this.git.getLogForRepo(repoPath, sha, 0);
|
||||||
|
if (!log) return window.showWarningMessage(`Unable to show commit details`);
|
||||||
|
|
||||||
let commit = Iterables.first(log.commits.values());
|
commit = Iterables.first(log.commits.values());
|
||||||
const commitPick = new CommitQuickPickItem(commit, ` \u2014 ${commit.fileName}`);
|
|
||||||
const files = commitPick.commit.fileName
|
|
||||||
.split(', ')
|
|
||||||
.filter(_ => !!_)
|
|
||||||
.map(f => new FileQuickPickItem(commitPick.commit, f));
|
|
||||||
|
|
||||||
const filePick = await window.showQuickPick(files, {
|
pick = await CommitFilesQuickPick.show(commit, uri, goBackCommand);
|
||||||
matchOnDescription: true,
|
if (!pick) return undefined;
|
||||||
matchOnDetail: true,
|
|
||||||
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()} \u2022 ${commitPick.commit.message}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (!filePick) return undefined;
|
if (pick instanceof CommandQuickPickItem) {
|
||||||
|
return pick.execute();
|
||||||
// Get the most recent commit -- so that we can find the real working filename if there was a rename
|
|
||||||
const workingCommit = await this.git.findMostRecentCommitForFile(filePick.uri.fsPath, filePick.sha);
|
|
||||||
|
|
||||||
log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha, undefined, undefined, 2);
|
|
||||||
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
|
||||||
|
|
||||||
commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
|
||||||
|
|
||||||
const items: CommandQuickPickItem[] = [
|
|
||||||
{
|
|
||||||
label: `$(diff) Compare with Working Tree`,
|
|
||||||
description: `$(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${(workingCommit || commit).fileName}`,
|
|
||||||
command: Commands.DiffWithWorking,
|
|
||||||
args: [commit.uri, commit]
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
if (commit.previousSha) {
|
// Attempt to the most recent commit -- so that we can find the real working filename if there was a rename
|
||||||
items.push({
|
const workingCommit = await this.git.findMostRecentCommitForFile(pick.uri.fsPath, pick.sha);
|
||||||
label: `$(diff) Compare with Previous Commit`,
|
// TODO: Leave this at undefined until findMostRecentCommitForFile actually works
|
||||||
description: `$(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}`,
|
workingFileName = !workingCommit ? pick.fileName : undefined;
|
||||||
command: Commands.DiffWithPrevious,
|
|
||||||
args: [commit.uri, commit]
|
log = await this.git.getLogForFile(pick.uri.fsPath, pick.sha, undefined, undefined, 2);
|
||||||
});
|
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
||||||
|
|
||||||
|
commit = Iterables.find(log.commits.values(), c => c.sha === commit.sha);
|
||||||
|
uri = pick.uri || uri;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Attempt to the most recent commit -- so that we can find the real working filename if there was a rename
|
||||||
|
const workingCommit = await this.git.findMostRecentCommitForFile(commit.uri.fsPath, commit.sha);
|
||||||
|
// TODO: Leave this at undefined until findMostRecentCommitForFile actually works
|
||||||
|
workingFileName = !workingCommit ? commit.fileName : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
pick = await CommitQuickPick.show(commit, workingFileName, uri,
|
||||||
label: `$(versions) Show History of ${commit.fileName}`,
|
// Create a command to get back to where we are right now
|
||||||
description: `\u2022 since $(git-commit) ${commit.sha}`,
|
new CommandQuickPickItem({
|
||||||
command: Commands.ShowQuickFileHistory,
|
label: `go back \u21A9`,
|
||||||
args: [new GitUri(commit.uri, commit)]
|
description: null
|
||||||
} as CommandQuickPickItem);
|
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand, options]),
|
||||||
|
// If we have already picked a commit, just jump back to the previous (since we skipped a quickpick menu)
|
||||||
|
// Otherwise setup a normal back command
|
||||||
|
alreadyPickedCommit
|
||||||
|
? goBackCommand
|
||||||
|
: new CommandQuickPickItem({
|
||||||
|
label: `go back \u21A9`,
|
||||||
|
description: null
|
||||||
|
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, undefined, goBackCommand, options]),
|
||||||
|
{ showFileHistory: options.showFileHistory });
|
||||||
|
|
||||||
items.push({
|
if (!pick) return undefined;
|
||||||
label: `$(versions) Show Full History of ${commit.fileName}`,
|
|
||||||
command: Commands.ShowQuickFileHistory,
|
|
||||||
description: `\u2022 this could fail if the file was renamed`,
|
|
||||||
args: [commit.uri] // TODO: This won't work for renames
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
items.push({
|
if (pick instanceof CommandQuickPickItem) {
|
||||||
label: `$(reply) go back \u21A9`,
|
return pick.execute();
|
||||||
description: null,
|
|
||||||
command: Commands.ShowQuickCommitDetails,
|
|
||||||
args: [uri]
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
const commandPick = await window.showQuickPick(items, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (commandPick) {
|
|
||||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||||
import { commands, QuickPickItem, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
|
||||||
import { EditorCommand } from './commands';
|
import { EditorCommand } from './commands';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import GitProvider, { GitUri } from '../gitProvider';
|
import GitProvider, { GitUri } from '../gitProvider';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { CommandQuickPickItem, CommitQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
|
import { CommandQuickPickItem } from './quickPickItems';
|
||||||
import * as moment from 'moment';
|
import { FileCommitsQuickPick } from './quickPicks';
|
||||||
|
|
||||||
export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
|||||||
super(Commands.ShowQuickFileHistory);
|
super(Commands.ShowQuickFileHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number) {
|
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
|
||||||
if (!(uri instanceof Uri)) {
|
if (!(uri instanceof Uri)) {
|
||||||
if (!editor.document) return undefined;
|
if (!editor.document) return undefined;
|
||||||
uri = editor.document.uri;
|
uri = editor.document.uri;
|
||||||
@@ -30,73 +29,21 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
|||||||
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||||
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
||||||
|
|
||||||
const commits = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as QuickPickItem[];
|
let pick = await FileCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||||
if (maxCount !== 0 && commits.length === this.git.config.advanced.maxQuickHistory) {
|
|
||||||
commits.splice(0, 0, new ShowAllCommitsQuickPickItem(this.git.config.advanced.maxQuickHistory));
|
|
||||||
}
|
|
||||||
|
|
||||||
commits.splice(0, 0, {
|
|
||||||
label: `$(repo) Show Repository History`,
|
|
||||||
command: Commands.ShowQuickRepoHistory
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
const pick = await window.showQuickPick(commits, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
matchOnDetail: true,
|
|
||||||
placeHolder: `${Iterables.first(log.commits.values()).fileName}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (!pick) return undefined;
|
if (!pick) return undefined;
|
||||||
|
|
||||||
if (pick instanceof ShowAllCommitsQuickPickItem) {
|
if (pick instanceof CommandQuickPickItem) {
|
||||||
return commands.executeCommand(Commands.ShowQuickFileHistory, uri, 0);
|
return pick.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pick instanceof CommitQuickPickItem)) {
|
return commands.executeCommand(Commands.ShowQuickCommitDetails,
|
||||||
const commandPick = pick && pick as CommandQuickPickItem;
|
new GitUri(pick.commit.uri, pick.commit),
|
||||||
if (commandPick) {
|
pick.commit.sha, pick.commit,
|
||||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
new CommandQuickPickItem({
|
||||||
}
|
label: `go back \u21A9`,
|
||||||
}
|
description: null
|
||||||
|
}, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand]),
|
||||||
const commitPick = pick as CommitQuickPickItem;
|
{ showFileHistory: false });
|
||||||
const commit = commitPick.commit;
|
|
||||||
|
|
||||||
const items: CommandQuickPickItem[] = [
|
|
||||||
{
|
|
||||||
label: `$(diff) Compare with Working Tree`,
|
|
||||||
description: `$(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${commit.fileName}`,
|
|
||||||
command: Commands.DiffWithWorking,
|
|
||||||
args: [commit.uri, commit]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
if (commit.previousSha) {
|
|
||||||
items.push({
|
|
||||||
label: `$(diff) Compare with Previous Commit`,
|
|
||||||
description: `$(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}`,
|
|
||||||
command: Commands.DiffWithPrevious,
|
|
||||||
args: [commit.uri, commit]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
label: `go back \u21A9`,
|
|
||||||
description: null,
|
|
||||||
command: Commands.ShowQuickFileHistory,
|
|
||||||
args: [uri, maxCount]
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
const commandPick = await window.showQuickPick(items, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (commandPick) {
|
|
||||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);
|
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { commands, Uri, window } from 'vscode';
|
||||||
import { commands, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
|
||||||
import { Command } from './commands';
|
import { Command } from './commands';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import GitProvider, { GitUri } from '../gitProvider';
|
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
|
import { CommandQuickPickItem } from './quickPickItems';
|
||||||
import * as moment from 'moment';
|
import { RepoCommitsQuickPick } from './quickPicks';
|
||||||
|
|
||||||
export default class ShowQuickRepoHistoryCommand extends Command {
|
export default class ShowQuickRepoHistoryCommand extends Command {
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ export default class ShowQuickRepoHistoryCommand extends Command {
|
|||||||
super(Commands.ShowQuickRepoHistory);
|
super(Commands.ShowQuickRepoHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(uri?: Uri, maxCount?: number, commitPick?: CommitQuickPickItem) {
|
async execute(uri?: Uri, maxCount?: number, commit?: GitCommit, goBackCommand?: CommandQuickPickItem) {
|
||||||
if (!(uri instanceof Uri)) {
|
if (!(uri instanceof Uri)) {
|
||||||
const document = window.activeTextEditor && window.activeTextEditor.document;
|
const document = window.activeTextEditor && window.activeTextEditor.document;
|
||||||
if (document) {
|
if (document) {
|
||||||
@@ -40,121 +39,29 @@ export default class ShowQuickRepoHistoryCommand extends Command {
|
|||||||
if (!repoPath) {
|
if (!repoPath) {
|
||||||
repoPath = this.repoPath;
|
repoPath = this.repoPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
||||||
|
|
||||||
let log = await this.git.getLogForRepo(repoPath, undefined, maxCount);
|
if (!commit) {
|
||||||
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
const log = await this.git.getLogForRepo(this.repoPath, undefined, maxCount);
|
||||||
|
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
||||||
const commits = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`))) as QuickPickItem[];
|
|
||||||
let placeHolder = 'Search by commit message, filename, or sha';
|
|
||||||
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));
|
|
||||||
commits.splice(0, 0, new ShowAllCommitsQuickPickItem(this.git.config.advanced.maxQuickHistory));
|
|
||||||
}
|
|
||||||
|
|
||||||
let pick: QuickPickItem;
|
|
||||||
if (!commitPick) {
|
|
||||||
pick = await window.showQuickPick(commits, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
matchOnDetail: true,
|
|
||||||
placeHolder: placeHolder
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
|
const pick = await RepoCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||||
if (!pick) return undefined;
|
if (!pick) return undefined;
|
||||||
if (pick instanceof ShowAllCommitsQuickPickItem) {
|
|
||||||
return commands.executeCommand(Commands.ShowQuickRepoHistory, uri, 0);
|
if (pick instanceof CommandQuickPickItem) {
|
||||||
|
return pick.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
commitPick = pick as CommitQuickPickItem;
|
commit = pick.commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
const files: (FileQuickPickItem | CommandQuickPickItem)[] = commitPick.commit.fileName
|
return commands.executeCommand(Commands.ShowQuickCommitDetails,
|
||||||
.split(', ')
|
new GitUri(commit.uri, commit),
|
||||||
.filter(_ => !!_)
|
commit.sha, undefined,
|
||||||
.map(f => new FileQuickPickItem(commitPick.commit, f));
|
new CommandQuickPickItem({
|
||||||
|
label: `go back \u21A9`,
|
||||||
files.push({
|
description: null
|
||||||
label: `go back \u21A9`,
|
}, Commands.ShowQuickRepoHistory, [uri, maxCount, undefined, goBackCommand]));
|
||||||
description: null,
|
|
||||||
command: Commands.ShowQuickRepoHistory,
|
|
||||||
args: [uri, maxCount]
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
pick = await window.showQuickPick(files, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
matchOnDetail: true,
|
|
||||||
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (!pick) return undefined;
|
|
||||||
|
|
||||||
if (!(pick instanceof FileQuickPickItem)) {
|
|
||||||
const commandPick = pick && pick as CommandQuickPickItem;
|
|
||||||
if (commandPick) {
|
|
||||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const filePick = pick as FileQuickPickItem;
|
|
||||||
// Get the most recent commit -- so that we can find the real working filename if there was a rename
|
|
||||||
const workingCommit = await this.git.findMostRecentCommitForFile(filePick.uri.fsPath, filePick.sha);
|
|
||||||
|
|
||||||
log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha, undefined, undefined, 2);
|
|
||||||
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
|
||||||
|
|
||||||
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
|
||||||
|
|
||||||
const items: CommandQuickPickItem[] = [
|
|
||||||
{
|
|
||||||
label: `$(diff) Compare with Working Tree`,
|
|
||||||
description: `$(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${(workingCommit || commit).fileName}`,
|
|
||||||
command: Commands.DiffWithWorking,
|
|
||||||
args: [commit.uri, commit]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
if (commit.previousSha) {
|
|
||||||
items.push({
|
|
||||||
label: `$(diff) Compare with Previous Commit`,
|
|
||||||
description: `$(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}`,
|
|
||||||
command: Commands.DiffWithPrevious,
|
|
||||||
args: [commit.uri, commit]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
label: `$(versions) Show History of ${commit.fileName}`,
|
|
||||||
description: `\u2022 since $(git-commit) ${commit.sha}`,
|
|
||||||
command: Commands.ShowQuickFileHistory,
|
|
||||||
args: [new GitUri(commit.uri, commit)]
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
label: `$(versions) Show Full History of ${commit.fileName}`,
|
|
||||||
description: `\u2022 this could fail if the file was renamed`,
|
|
||||||
command: Commands.ShowQuickFileHistory,
|
|
||||||
args: [commit.uri] // TODO: This won't work for renames
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
label: `go back \u21A9`,
|
|
||||||
description: null,
|
|
||||||
command: Commands.ShowQuickRepoHistory,
|
|
||||||
args: [uri, maxCount, commitPick]
|
|
||||||
} as CommandQuickPickItem);
|
|
||||||
|
|
||||||
const commandPick = await window.showQuickPick(items, {
|
|
||||||
matchOnDescription: true,
|
|
||||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
|
||||||
} as QuickPickOptions);
|
|
||||||
|
|
||||||
if (commandPick) {
|
|
||||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', ex);
|
Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', ex);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class GitUri extends Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileUri() {
|
fileUri() {
|
||||||
return Uri.file(this.fsPath);
|
return Uri.file(this.sha ? this.path : this.fsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromUri(uri: Uri, git?: GitProvider) {
|
static fromUri(uri: Uri, git?: GitProvider) {
|
||||||
|
|||||||
Reference in New Issue
Block a user