Uses current branch when opening remote file

Adds current branch name to quick pick description
This commit is contained in:
Eric Amodio
2017-03-24 13:32:32 -04:00
parent e906bfcb9e
commit e859f697ec
7 changed files with 60 additions and 45 deletions

View File

@@ -81,9 +81,10 @@ export class CommitFileDetailsQuickPick {
const remotes = Arrays.uniqueBy(await git.getRemotes(git.repoPath), _ => _.url, _ => !!_.provider);
if (remotes.length) {
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'file', commit.fileName, commit.sha, undefined, currentCommand));
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'file', commit.fileName, undefined, commit.sha, currentCommand));
if (commit.workingFileName) {
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'file', commit.workingFileName, undefined, 'Working File', currentCommand));
const branch = await git.getBranch(commit.repoPath || git.repoPath);
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'working-file', commit.workingFileName, branch.name, undefined, currentCommand));
}
}

View File

@@ -73,6 +73,8 @@ export class FileHistoryQuickPick {
}
}
const branch = await git.getBranch(uri.repoPath || git.repoPath);
const currentCommand = new CommandQuickPickItem({
label: `go back \u21A9`,
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(uri.fsPath)}${uri.sha ? ` from \u00a0$(git-commit) ${uri.shortSha}` : ''}`
@@ -82,7 +84,7 @@ export class FileHistoryQuickPick {
if (!goBackCommand) {
items.splice(index++, 0, new CommandQuickPickItem({
label: `$(history) Show Branch History`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows the current branch history`
description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch.name} history`
}, Commands.ShowQuickCurrentBranchHistory,
[
undefined,
@@ -92,7 +94,7 @@ export class FileHistoryQuickPick {
const remotes = Arrays.uniqueBy(await git.getRemotes(git.repoPath), _ => _.url, _ => !!_.provider);
if (remotes.length) {
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, 'file', uri.getRelativePath(), uri.sha, undefined, currentCommand));
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, 'file', uri.getRelativePath(), branch.name, uri.sha, currentCommand));
}
if (goBackCommand) {

View File

@@ -1,29 +1,34 @@
'use strict';
import { QuickPickOptions, window } from 'vscode';
import { Commands } from '../commands';
import { GitRemote, RemoteProviderOpenType } from '../gitService';
import { GitRemote, RemoteOpenType } from '../gitService';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
import * as path from 'path';
function getNameFromRemoteOpenType(type: RemoteOpenType) {
switch (type) {
case 'branch': return 'Branch';
case 'commit': return 'Commit';
case 'file': return 'File';
case 'working-file': return 'Working File';
default: return '';
}
}
export class OpenRemoteCommandQuickPickItem extends CommandQuickPickItem {
private type: RemoteProviderOpenType;
private remote: GitRemote;
private type: RemoteOpenType;
constructor(remote: GitRemote, type: RemoteProviderOpenType, ...args: string[]);
constructor(remote: GitRemote, type: RemoteProviderOpenType, branchOrShaOrFileName: string, fileSha?: string, name?: string) {
if (!name) {
name = `${type[0].toUpperCase()}${type.substring(1)}`;
}
constructor(remote: GitRemote, type: RemoteOpenType, ...args: string[]) {
super({
label: `$(link-external) Open ${name} in ${remote.provider.name}`,
label: `$(link-external) Open ${getNameFromRemoteOpenType(type)} in ${remote.provider.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider.path}`
}, undefined, undefined);
this.type = type;
this.remote = remote;
this.args = [branchOrShaOrFileName, fileSha];
this.type = type;
this.args = args;
}
async execute(): Promise<{}> {
@@ -35,37 +40,37 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
constructor(remotes: GitRemote[], type: 'branch', branch: string, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: 'commit', sha: string, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: 'file', fileName: string, sha?: string, name?: string, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: RemoteProviderOpenType, branchOrShaOrFileName: string, shaOrGoBackCommand?: string | CommandQuickPickItem, name?: string, goBackCommand?: CommandQuickPickItem) {
let fileSha: string;
if (typeof shaOrGoBackCommand === 'string') {
fileSha = shaOrGoBackCommand;
constructor(remotes: GitRemote[], type: 'file' | 'working-file', fileName: string, branch?: string, sha?: string, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: RemoteOpenType, branchOrShaOrFileName: string, goBackCommandOrFileBranch?: CommandQuickPickItem | string, fileSha?: string, goBackCommand?: CommandQuickPickItem) {
let fileBranch: string;
if (typeof goBackCommandOrFileBranch === 'string') {
fileBranch = goBackCommandOrFileBranch;
}
else if (!goBackCommand) {
goBackCommand = shaOrGoBackCommand;
goBackCommand = goBackCommandOrFileBranch;
}
const name = getNameFromRemoteOpenType(type);
let description: string;
let placeHolder: string;
switch (type) {
case 'branch':
name = name || 'Branch';
description = `$(git-branch) ${branchOrShaOrFileName}`;
placeHolder = `open ${branchOrShaOrFileName} ${name.toLowerCase()} in\u2026`;
break;
case 'commit':
const shortSha = branchOrShaOrFileName.substring(0, 8);
name = name || 'Commit';
description = `$(git-commit) ${shortSha}`;
placeHolder = `open ${name.toLowerCase()} ${shortSha} in\u2026`;
break;
case 'file':
case 'working-file':
const fileName = path.basename(branchOrShaOrFileName);
const shortFileSha = (fileSha && fileSha.substring(0, 8)) || '';
const shaSuffix = shortFileSha ? ` \u00a0\u2022\u00a0 ${shortFileSha}` : '';
name = name || 'File';
description = `$(file-text) ${fileName}${shortFileSha ? ` in \u00a0$(git-commit) ${shortFileSha}` : ''}`;
placeHolder = `open ${branchOrShaOrFileName}${shaSuffix} in\u2026`;
break;
@@ -76,7 +81,7 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
super({
label: `$(link-external) Open ${name} in ${remote.provider.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider.path} \u00a0\u2022\u00a0 ${description}`
}, Commands.OpenInRemote, [undefined, remotes, type, [branchOrShaOrFileName, fileSha], name, goBackCommand]);
}, Commands.OpenInRemote, [undefined, remotes, type, [branchOrShaOrFileName, fileBranch, fileSha], goBackCommand]);
return;
}
@@ -88,15 +93,15 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
super({
label: `$(link-external) Open ${name} in ${provider}\u2026`,
description: `\u00a0 \u2014 \u00a0\u00a0 ${description}`
}, Commands.OpenInRemote, [undefined, remotes, type, [branchOrShaOrFileName, fileSha], name, goBackCommand]);
}, Commands.OpenInRemote, [undefined, remotes, type, [branchOrShaOrFileName, fileBranch, fileSha], goBackCommand]);
}
}
export class RemotesQuickPick {
static async show(remotes: GitRemote[], placeHolder: string, type: RemoteProviderOpenType, args: string[], name: string, goBackCommand?: CommandQuickPickItem): Promise<OpenRemoteCommandQuickPickItem | CommandQuickPickItem | undefined> {
static async show(remotes: GitRemote[], placeHolder: string, type: RemoteOpenType, args: string[], goBackCommand?: CommandQuickPickItem): Promise<OpenRemoteCommandQuickPickItem | CommandQuickPickItem | undefined> {
const items = remotes.map(_ => new OpenRemoteCommandQuickPickItem(_, type, ...args, name)) as (OpenRemoteCommandQuickPickItem | CommandQuickPickItem)[];
const items = remotes.map(_ => new OpenRemoteCommandQuickPickItem(_, type, ...args)) as (OpenRemoteCommandQuickPickItem | CommandQuickPickItem)[];
if (goBackCommand) {
items.splice(0, 0, goBackCommand);