Browse Source

Adds Open Branches in Remote command

Adds Open Branches in Remote command to the Branches custom view item
Adds Open Repository in Remote command to the Repository Status custom view item
main
Eric Amodio 7 years ago
parent
commit
f58d085352
10 changed files with 86 additions and 2 deletions
  1. +19
    -0
      package.json
  2. +1
    -0
      src/commands.ts
  3. +2
    -0
      src/commands/common.ts
  4. +37
    -0
      src/commands/openBranchesInRemote.ts
  5. +2
    -1
      src/extension.ts
  6. +4
    -0
      src/git/remotes/bitbucket.ts
  7. +4
    -0
      src/git/remotes/github.ts
  8. +9
    -1
      src/git/remotes/provider.ts
  9. +4
    -0
      src/git/remotes/visualStudio.ts
  10. +4
    -0
      src/quickPicks/remotes.ts

+ 19
- 0
package.json View File

@ -950,6 +950,11 @@
"category": "GitLens"
},
{
"command": "gitlens.openBranchesInRemote",
"title": "Open Branches in Remote",
"category": "GitLens"
},
{
"command": "gitlens.openBranchInRemote",
"title": "Open Branch in Remote",
"category": "GitLens"
@ -1184,6 +1189,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.openBranchesInRemote",
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.openBranchInRemote",
"when": "gitlens:hasRemotes"
},
@ -1473,6 +1482,11 @@
],
"view/item/context": [
{
"command": "gitlens.openBranchesInRemote",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:branches",
"group": "1_gitlens@1"
},
{
"command": "gitlens.openBranchInRemote",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:branch-history",
"group": "1_gitlens@1"
@ -1618,6 +1632,11 @@
"group": "5_gitlens@1"
},
{
"command": "gitlens.openRepoInRemote",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:status",
"group": "1_gitlens@1"
},
{
"command": "gitlens.gitExplorer.refresh",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem != gitlens:commit-file && viewItem != gitlens:stash-file",
"group": "9_gitlens@1"

+ 1
- 0
src/commands.ts View File

@ -14,6 +14,7 @@ export * from './commands/diffWithPrevious';
export * from './commands/diffWithRevision';
export * from './commands/diffWithWorking';
export * from './commands/openChangedFiles';
export * from './commands/openBranchesInRemote';
export * from './commands/openBranchInRemote';
export * from './commands/openCommitInRemote';
export * from './commands/openFileInRemote';

+ 2
- 0
src/commands/common.ts View File

@ -19,6 +19,7 @@ export type Commands =
'gitlens.diffWithWorking' |
'gitlens.diffLineWithWorking' |
'gitlens.openChangedFiles' |
'gitlens.openBranchesInRemote' |
'gitlens.openBranchInRemote' |
'gitlens.openCommitInRemote' |
'gitlens.openFileInRemote' |
@ -59,6 +60,7 @@ export const Commands = {
DiffWithWorking: 'gitlens.diffWithWorking' as Commands,
DiffLineWithWorking: 'gitlens.diffLineWithWorking' as Commands,
OpenChangedFiles: 'gitlens.openChangedFiles' as Commands,
OpenBranchesInRemote: 'gitlens.openBranchesInRemote' as Commands,
OpenBranchInRemote: 'gitlens.openBranchInRemote' as Commands,
OpenCommitInRemote: 'gitlens.openCommitInRemote' as Commands,
OpenFileInRemote: 'gitlens.openFileInRemote' as Commands,

+ 37
- 0
src/commands/openBranchesInRemote.ts View File

@ -0,0 +1,37 @@
'use strict';
import { Arrays } from '../system';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { OpenInRemoteCommandArgs } from './openInRemote';
export class OpenBranchesInRemoteCommand extends ActiveEditorCommand {
constructor(private git: GitService) {
super(Commands.OpenBranchesInRemote);
}
async execute(editor?: TextEditor, uri?: Uri) {
uri = getCommandUri(uri, editor);
const gitUri = uri && await GitUri.fromUri(uri, this.git);
const repoPath = gitUri === undefined ? this.git.repoPath : gitUri.repoPath;
if (!repoPath) return undefined;
try {
const remotes = Arrays.uniqueBy(await this.git.getRemotes(repoPath), _ => _.url, _ => !!_.provider);
return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'branches'
},
remotes
} as OpenInRemoteCommandArgs);
}
catch (ex) {
Logger.error(ex, 'OpenBranchesInRemoteCommand');
return window.showErrorMessage(`Unable to open branches in remote provider. See output channel for more details`);
}
}
}

+ 2
- 1
src/extension.ts View File

@ -3,7 +3,7 @@
import { commands, ExtensionContext, extensions, languages, window, workspace } from 'vscode';
import { AnnotationController } from './annotations/annotationController';
import { CloseUnchangedFilesCommand, OpenChangedFilesCommand } from './commands';
import { OpenBranchInRemoteCommand, OpenCommitInRemoteCommand, OpenFileInRemoteCommand, OpenInRemoteCommand, OpenRepoInRemoteCommand } from './commands';
import { OpenBranchesInRemoteCommand, OpenBranchInRemoteCommand, OpenCommitInRemoteCommand, OpenFileInRemoteCommand, OpenInRemoteCommand, OpenRepoInRemoteCommand } from './commands';
import { CopyMessageToClipboardCommand, CopyShaToClipboardCommand } from './commands';
import { DiffDirectoryCommand, DiffLineWithPreviousCommand, DiffLineWithWorkingCommand, DiffWithBranchCommand, DiffWithNextCommand, DiffWithPreviousCommand, DiffWithRevisionCommand, DiffWithWorkingCommand } from './commands';
import { ResetSuppressedWarningsCommand } from './commands';
@ -108,6 +108,7 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(new DiffWithPreviousCommand(git));
context.subscriptions.push(new DiffWithRevisionCommand(git));
context.subscriptions.push(new DiffWithWorkingCommand(git));
context.subscriptions.push(new OpenBranchesInRemoteCommand(git));
context.subscriptions.push(new OpenBranchInRemoteCommand(git));
context.subscriptions.push(new OpenCommitInRemoteCommand(git));
context.subscriptions.push(new OpenFileInRemoteCommand(git));

+ 4
- 0
src/git/remotes/bitbucket.ts View File

@ -12,6 +12,10 @@ export class BitbucketService extends RemoteProvider {
return 'Bitbucket';
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/commits/branch/${branch}`;
}

+ 4
- 0
src/git/remotes/github.ts View File

@ -12,6 +12,10 @@ export class GitHubService extends RemoteProvider {
return 'GitHub';
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/commits/${branch}`;
}

+ 9
- 1
src/git/remotes/provider.ts View File

@ -3,9 +3,10 @@ import { commands, Range, Uri } from 'vscode';
import { BuiltInCommands } from '../../constants';
import { GitLogCommit } from '../../gitService';
export type RemoteResourceType = 'branch' | 'commit' | 'file' | 'repo' | 'revision';
export type RemoteResourceType = 'branch' | 'branches' | 'commit' | 'file' | 'repo' | 'revision';
export type RemoteResource =
{ type: 'branch', branch: string } |
{ type: 'branches' } |
{ type: 'commit', sha: string } |
{ type: 'file', branch?: string, fileName: string, range?: Range } |
{ type: 'repo' } |
@ -14,6 +15,7 @@ export type RemoteResource =
export function getNameFromRemoteResource(resource: RemoteResource) {
switch (resource.type) {
case 'branch': return 'Branch';
case 'branches': return 'Branches';
case 'commit': return 'Commit';
case 'file': return 'File';
case 'repo': return 'Repository';
@ -32,6 +34,7 @@ export abstract class RemoteProvider {
return `https://${this.domain}/${this.path}`;
}
protected abstract getUrlForBranches(): string;
protected abstract getUrlForBranch(branch: string): string;
protected abstract getUrlForCommit(sha: string): string;
protected abstract getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string;
@ -45,6 +48,7 @@ export abstract class RemoteProvider {
open(resource: RemoteResource): Promise<{} | undefined> {
switch (resource.type) {
case 'branch': return this.openBranch(resource.branch);
case 'branches': return this.openBranches();
case 'commit': return this.openCommit(resource.sha);
case 'file': return this.openFile(resource.fileName, resource.branch, undefined, resource.range);
case 'repo': return this.openRepo();
@ -56,6 +60,10 @@ export abstract class RemoteProvider {
return this._openUrl(this.baseUrl);
}
openBranches() {
return this._openUrl(this.getUrlForBranches());
}
openBranch(branch: string) {
return this._openUrl(this.getUrlForBranch(branch));
}

+ 4
- 0
src/git/remotes/visualStudio.ts View File

@ -12,6 +12,10 @@ export class VisualStudioService extends RemoteProvider {
return 'Visual Studio Team Services';
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/?version=GB${branch}&_a=history`;
}

+ 4
- 0
src/quickPicks/remotes.ts View File

@ -38,6 +38,10 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
description = `$(git-branch) ${resource.branch}`;
break;
case 'branches':
description = `$(git-branch) Branches`;
break;
case 'commit':
const shortSha = resource.sha.substring(0, 8);
description = `$(git-commit) ${shortSha}`;

Loading…
Cancel
Save