mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 01:25:43 -05:00
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
This commit is contained in:
19
package.json
19
package.json
@@ -949,6 +949,11 @@
|
||||
"title": "Open Changed Files",
|
||||
"category": "GitLens"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.openBranchesInRemote",
|
||||
"title": "Open Branches in Remote",
|
||||
"category": "GitLens"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.openBranchInRemote",
|
||||
"title": "Open Branch in Remote",
|
||||
@@ -1183,6 +1188,10 @@
|
||||
"command": "gitlens.openChangedFiles",
|
||||
"when": "gitlens:enabled"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.openBranchesInRemote",
|
||||
"when": "gitlens:hasRemotes"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.openBranchInRemote",
|
||||
"when": "gitlens:hasRemotes"
|
||||
@@ -1472,6 +1481,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",
|
||||
@@ -1617,6 +1631,11 @@
|
||||
"when": "gitlens:isTracked && view == gitlens.gitExplorer && viewItem == gitlens:stash-file",
|
||||
"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",
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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
src/commands/openBranchesInRemote.ts
Normal file
37
src/commands/openBranchesInRemote.ts
Normal 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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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`;
|
||||
}
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user