Ver a proveniência

Adds icons to quickpick commands

Adds file history choices to commit quickpick
Adds repo history choice to file history quickpick
Adds commit message to quickpick placeholder in a few places
main
Eric Amodio há 7 anos
ascendente
cometimento
beb6740120
4 ficheiros alterados com 153 adições e 115 eliminações
  1. +3
    -6
      src/commands/quickPickItems.ts
  2. +55
    -42
      src/commands/showQuickCommitDetails.ts
  3. +34
    -22
      src/commands/showQuickFileHistory.ts
  4. +61
    -45
      src/commands/showQuickRepoHistory.ts

+ 3
- 6
src/commands/quickPickItems.ts Ver ficheiro

@ -5,8 +5,9 @@ import { GitCommit, GitUri } from '../gitProvider';
import * as moment from 'moment';
import * as path from 'path';
export interface BackQuickPickItem extends QuickPickItem {
export interface CommandQuickPickItem extends QuickPickItem {
command: Commands;
args?: any[];
}
export class CommitQuickPickItem implements QuickPickItem {
@ -22,10 +23,6 @@ export class CommitQuickPickItem implements QuickPickItem {
}
}
export interface CompareQuickPickItem extends QuickPickItem {
command: Commands;
}
export class FileQuickPickItem implements QuickPickItem {
label: string;
@ -48,7 +45,7 @@ export class ShowAllCommitsQuickPickItem implements QuickPickItem {
detail: string;
constructor(maxItems: number) {
this.label = `\u21BB Show All Commits`;
this.label = `$(sync) Show Full History`;
this.description = `\u2014 Currently only showing the first ${maxItems} commits`;
this.detail = `This may take a while`;
}

+ 55
- 42
src/commands/showQuickCommitDetails.ts Ver ficheiro

@ -5,7 +5,7 @@ import { EditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { BackQuickPickItem, CommitQuickPickItem, CompareQuickPickItem, FileQuickPickItem } from './quickPickItems';
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem } from './quickPickItems';
import * as moment from 'moment';
export default class ShowQuickCommitDetailsCommand extends EditorCommand {
@ -43,10 +43,10 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
}
try {
const log = await this.git.getLogForRepo(repoPath, sha, 0);
let log = await this.git.getLogForRepo(repoPath, sha, 0);
if (!log) return window.showWarningMessage(`Unable to show commit details`);
const commit = Iterables.first(log.commits.values());
let commit = Iterables.first(log.commits.values());
const commitPick = new CommitQuickPickItem(commit, ` \u2014 ${commit.fileName}`);
const files = commitPick.commit.fileName
.split(', ')
@ -56,52 +56,65 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
const filePick = await window.showQuickPick(files, {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()}`
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()} \u2022 ${commitPick.commit.message}`
} as QuickPickOptions);
if (filePick) {
// 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);
const 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);
let command: Commands | undefined = Commands.DiffWithWorking;
const items: CompareQuickPickItem[] = [
{
label: `Compare with Working Tree`,
description: `\u2022 ${commit.sha} $(git-compare) ${(workingCommit || commit).fileName}`,
command: Commands.DiffWithWorking
}
];
if (commit.previousSha) {
items.push({
label: `Compare with Previous Commit`,
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
command: Commands.DiffWithPrevious
});
}
if (!filePick) return undefined;
items.push({
label: `go back \u21A9`,
description: null,
command: Commands.ShowQuickCommitDetails
} as BackQuickPickItem);
// 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);
const comparePick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
} as QuickPickOptions);
log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha, undefined, undefined, 2);
if (!log) return window.showWarningMessage(`Unable to open diff`);
command = comparePick ? comparePick.command : undefined;
commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
if (command) {
if (command === Commands.ShowQuickCommitDetails) return commands.executeCommand(command, uri), sha;
return commands.executeCommand(command, commit.uri, commit);
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}`,
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({
label: `$(reply) go back \u21A9`,
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;

+ 34
- 22
src/commands/showQuickFileHistory.ts Ver ficheiro

@ -5,7 +5,7 @@ import { EditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { BackQuickPickItem, CommitQuickPickItem, CompareQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
import { CommandQuickPickItem, CommitQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
import * as moment from 'moment';
export default class ShowQuickFileHistoryCommand extends EditorCommand {
@ -31,60 +31,72 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
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 placeHolderSuffix = '';
if (maxCount !== 0 && commits.length === this.git.config.advanced.maxQuickHistory) {
placeHolderSuffix = ` \u2014 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));
}
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}${placeHolderSuffix}`
placeHolder: `${Iterables.first(log.commits.values()).fileName}`
} as QuickPickOptions);
if (!pick) return undefined;
if (pick instanceof ShowAllCommitsQuickPickItem) {
return commands.executeCommand(Commands.ShowQuickFileHistory, uri, 0);
}
if (!(pick instanceof CommitQuickPickItem)) {
const commandPick = pick && pick as CommandQuickPickItem;
if (commandPick) {
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
}
}
const commitPick = pick as CommitQuickPickItem;
const commit = commitPick.commit;
let command: Commands | undefined = Commands.DiffWithWorking;
const items: (CompareQuickPickItem | BackQuickPickItem)[] = [
const items: CommandQuickPickItem[] = [
{
label: `Compare with Working Tree`,
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
command: Commands.DiffWithWorking
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: `Compare with Previous Commit`,
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
command: Commands.DiffWithPrevious
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
} as BackQuickPickItem);
command: Commands.ShowQuickFileHistory,
args: [uri, maxCount]
} as CommandQuickPickItem);
const comparePick = await window.showQuickPick(items, {
const commandPick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
} as QuickPickOptions);
command = comparePick ? comparePick.command : undefined;
if (command) {
if (command === Commands.ShowQuickFileHistory) return commands.executeCommand(command, uri, maxCount);
return commands.executeCommand(command, uri, commit);
if (commandPick) {
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
}
return undefined;
}
catch (ex) {
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);

+ 61
- 45
src/commands/showQuickRepoHistory.ts Ver ficheiro

@ -5,7 +5,7 @@ import { Command } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { BackQuickPickItem, CommitQuickPickItem, CompareQuickPickItem, FileQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
import * as moment from 'moment';
export default class ShowQuickRepoHistoryCommand extends Command {
@ -43,7 +43,7 @@ export default class ShowQuickRepoHistoryCommand extends Command {
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
const log = await this.git.getLogForRepo(repoPath, undefined, maxCount);
let log = await this.git.getLogForRepo(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[];
@ -70,7 +70,7 @@ export default class ShowQuickRepoHistoryCommand extends Command {
commitPick = pick as CommitQuickPickItem;
}
const files: (FileQuickPickItem | BackQuickPickItem)[] = commitPick.commit.fileName
const files: (FileQuickPickItem | CommandQuickPickItem)[] = commitPick.commit.fileName
.split(', ')
.filter(_ => !!_)
.map(f => new FileQuickPickItem(commitPick.commit, f));
@ -78,8 +78,9 @@ export default class ShowQuickRepoHistoryCommand extends Command {
files.push({
label: `go back \u21A9`,
description: null,
command: Commands.ShowQuickRepoHistory
} as BackQuickPickItem);
command: Commands.ShowQuickRepoHistory,
args: [uri, maxCount]
} as CommandQuickPickItem);
pick = await window.showQuickPick(files, {
matchOnDescription: true,
@ -87,55 +88,70 @@ export default class ShowQuickRepoHistoryCommand extends Command {
placeHolder: `${commitPick.commit.sha} \u2022 ${commitPick.commit.author}, ${moment(commitPick.commit.date).fromNow()}`
} as QuickPickOptions);
const command = pick && (pick as BackQuickPickItem).command;
if (command) {
return commands.executeCommand(command, uri, maxCount);
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;
if (filePick) {
// 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);
const 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);
let command: Commands | undefined = Commands.DiffWithWorking;
const items: CompareQuickPickItem[] = [
{
label: `Compare with Working Tree`,
description: `\u2022 ${commit.sha} $(git-compare) ${(workingCommit || commit).fileName}`,
command: Commands.DiffWithWorking
}
];
if (commit.previousSha) {
items.push({
label: `Compare with Previous Commit`,
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
command: Commands.DiffWithPrevious
});
// 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: `go back \u21A9`,
description: null,
command: Commands.ShowQuickRepoHistory
} as BackQuickPickItem);
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]
});
}
const comparePick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
} as QuickPickOptions);
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);
command = comparePick ? comparePick.command : undefined;
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 (command) {
if (command === Commands.ShowQuickRepoHistory) return commands.executeCommand(command, uri, maxCount, commitPick);
return commands.executeCommand(command, commit.uri, commit);
}
if (commandPick) {
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
}
return undefined;

Carregando…
Cancelar
Guardar