Browse Source

Adds alt copy commands for open * on remote cmds

main
Eric Amodio 4 years ago
parent
commit
237ad2e0ff
12 changed files with 191 additions and 188 deletions
  1. +1
    -1
      CHANGELOG.md
  2. +1
    -1
      README.md
  3. +73
    -20
      package.json
  4. +0
    -2
      src/commands.ts
  5. +5
    -2
      src/commands/common.ts
  6. +0
    -46
      src/commands/copyRemoteCommitUrlToClipboard.ts
  7. +0
    -81
      src/commands/copyRemoteFileUrlToClipboard.ts
  8. +28
    -11
      src/commands/openBranchOnRemote.ts
  9. +13
    -4
      src/commands/openBranchesOnRemote.ts
  10. +12
    -5
      src/commands/openCommitOnRemote.ts
  11. +43
    -11
      src/commands/openFileOnRemote.ts
  12. +15
    -4
      src/commands/openRepoOnRemote.ts

+ 1
- 1
CHANGELOG.md View File

@ -29,7 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Shows a changes hover with the full set of changes (diff hunk) and even with unsaved changes
- Adds a new _Follow the Cursor_ command to the _File History_ view — which will ultimately replace the _Line History_ view, although, for now, it will just be disabled by default
- Adds a new _Open File from Remote_ (`gitlens.openFileFromRemote`) command — opens the local file from a remote file url
- Adds a new _Copy Remote Commit Url_ (`gitlens.copyRemoteCommitUrlToClipboard`) command — copies the remote url of the current line commit to the clipboard
- Adds a new _Copy Remote Commit Url_ (`gitlens.copyRemoteCommitUrl`) command — copies the remote url of the current line commit to the clipboard
- Adds much improved co-author support
- Provides an updatable quick pick of co-authors
- Adds the _Add Co-authors_ (`gitlens.addAuthors`) command to the Source Control toolbar

+ 1
- 1
README.md View File

@ -639,7 +639,7 @@ The compare view provides the following features,
- Adds a _Copy Commit Message to Clipboard_ command (`gitlens.copyMessageToClipboard`) to copy the commit message of the current line to the clipboard or from the most recent commit to the current branch, if there is no current editor
- Adds a _Copy Remote Commit Url to Clipboard_ command (`gitlens.copyRemoteCommitUrlToClipboard`) to copy the remote url of the commit of the current line to the clipboard
- Adds a _Copy Remote Commit Url to Clipboard_ command (`gitlens.copyRemoteCommitUrl`) to copy the remote url of the commit of the current line to the clipboard
- Adds a _Copy Remote File Url to Clipboard_ command (`gitlens.copyRemoteFileUrlToClipboard`) to copy the remote url of the current file and line to the clipboard

+ 73
- 20
package.json View File

@ -2658,7 +2658,7 @@
}
},
{
"command": "gitlens.copyRemoteCommitUrlToClipboard",
"command": "gitlens.copyRemoteCommitUrl",
"title": "Copy Remote Commit Url",
"category": "GitLens",
"icon": {
@ -2701,12 +2701,30 @@
"icon": "$(globe)"
},
{
"command": "gitlens.copyRemoteBranchesUrl",
"title": "Copy Remote Branches Url",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openBranchInRemote",
"title": "Open Branch on Remote",
"category": "GitLens",
"icon": "$(globe)"
},
{
"command": "gitlens.copyRemoteBranchUrl",
"title": "Copy Remote Branch Url",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openCommitInRemote",
"title": "Open Commit on Remote",
"category": "GitLens",
@ -2748,6 +2766,15 @@
"icon": "$(globe)"
},
{
"command": "gitlens.copyRemoteRepositoryUrl",
"title": "Copy Remote Repository Url",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openRevisionFile",
"title": "Open File at Revision",
"category": "GitLens",
@ -4208,7 +4235,7 @@
"when": "gitlens:activeFileStatus =~ /blameable/"
},
{
"command": "gitlens.copyRemoteCommitUrlToClipboard",
"command": "gitlens.copyRemoteCommitUrl",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
@ -4232,10 +4259,18 @@
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.copyRemoteBranchesUrl",
"when": "false"
},
{
"command": "gitlens.openBranchInRemote",
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.copyRemoteBranchUrl",
"when": "false"
},
{
"command": "gitlens.openCommitInRemote",
"when": "gitlens:activeFileStatus =~ /blameable/ && gitlens:activeFileStatus =~ /remotes/"
},
@ -4256,6 +4291,10 @@
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.copyRemoteRepositoryUrl",
"when": "false"
},
{
"command": "gitlens.openRevisionFile",
"when": "gitlens:activeFileStatus =~ /revision/ && isInDiffEditor"
},
@ -5054,12 +5093,14 @@
{
"command": "gitlens.openFileInRemote",
"when": "editorTextFocus && gitlens:activeFileStatus =~ /remotes/ && config.gitlens.menus.editor.remote",
"group": "2_gitlens_remote@1"
"group": "2_gitlens_remote@1",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.openCommitInRemote",
"when": "editorTextFocus && gitlens:activeFileStatus =~ /remotes/ && config.gitlens.menus.editor.remote",
"group": "2_gitlens_remote@2"
"group": "2_gitlens_remote@2",
"alt": "gitlens.copyRemoteCommitUrl"
},
{
"command": "gitlens.diffLineWithPrevious",
@ -5092,7 +5133,7 @@
"group": "9_cutcopypaste_gitlens@2"
},
{
"command": "gitlens.copyRemoteCommitUrlToClipboard",
"command": "gitlens.copyRemoteCommitUrl",
"when": "editorTextFocus && gitlens:activeFileStatus =~ /remotes/ && config.gitlens.menus.editor.clipboard",
"group": "9_cutcopypaste_gitlens@3"
},
@ -5202,7 +5243,8 @@
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.editorTab.remote",
"group": "1_co_gitlens@3"
"group": "1_co_gitlens@3",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.diffWithPrevious",
@ -5239,7 +5281,8 @@
{
"command": "gitlens.openFileInRemote",
"when": "!explorerResourceIsRoot && !explorerResourceIsFolder && gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.explorer.remote",
"group": "1_gitlens@100"
"group": "1_gitlens@100",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.diffWithPrevious",
@ -5322,7 +5365,8 @@
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.scmItem.remote",
"group": "navigation"
"group": "navigation",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.externalDiff",
@ -5951,12 +5995,14 @@
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem =~ /gitlens:branches\\b(?=.*?\\b\\+remotes\\b)/",
"group": "inline@98"
"group": "inline@98",
"alt": "gitlens.copyRemoteBranchesUrl"
},
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem =~ /gitlens:branches\\b(?=.*?\\b\\+remotes\\b)/",
"group": "1_gitlens@1"
"group": "1_gitlens@1",
"alt": "gitlens.copyRemoteBranchesUrl"
},
{
"command": "gitlens.views.switchToBranch",
@ -6007,7 +6053,8 @@
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(tracking|remote)\\b)/",
"group": "inline@99"
"group": "inline@99",
"alt": "gitlens.copyRemoteBranchUrl"
},
{
"command": "gitlens.views.switchToAnotherBranch",
@ -6057,7 +6104,8 @@
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(tracking|remote)\\b)/",
"group": "2_gitlens_quickopen@1"
"group": "2_gitlens_quickopen@1",
"alt": "gitlens.copyRemoteBranchUrl"
},
{
"command": "gitlens.views.openDirectoryDiffWithWorking",
@ -6163,7 +6211,8 @@
{
"command": "gitlens.openCommitInRemote",
"when": "viewItem =~ /gitlens:commit\\b/ && gitlens:hasRemotes",
"group": "inline@99"
"group": "inline@99",
"alt": "gitlens.copyRemoteCommitUrl"
},
{
"command": "gitlens.views.cherryPick",
@ -6234,7 +6283,7 @@
"command": "gitlens.openCommitInRemote",
"when": "viewItem =~ /gitlens:commit\\b/ && gitlens:hasRemotes",
"group": "2_gitlens_quickopen_2@1",
"alt": "gitlens.copyRemoteCommitUrlToClipboard"
"alt": "gitlens.copyRemoteCommitUrl"
},
{
"command": "gitlens.revealCommitInView",
@ -6355,7 +6404,7 @@
"command": "gitlens.openCommitInRemote",
"when": "viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)/ && gitlens:hasRemotes",
"group": "2_gitlens_quickopen_2@3",
"alt": "gitlens.copyRemoteCommitUrlToClipboard"
"alt": "gitlens.copyRemoteCommitUrl"
},
{
"command": "gitlens.views.highlightChanges",
@ -6383,7 +6432,7 @@
"group": "3_gitlens_explore@4"
},
{
"command": "gitlens.copyRemoteCommitUrlToClipboard",
"command": "gitlens.copyRemoteCommitUrl",
"when": "viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)/ && gitlens:hasRemotes",
"group": "7_gitlens_cutcopypaste@3"
},
@ -6446,7 +6495,8 @@
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "inline@99"
"group": "inline@99",
"alt": "gitlens.copyRemoteRepositoryUrl"
},
{
"command": "gitlens.views.fetch",
@ -6461,12 +6511,14 @@
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "5_gitlens_open@1"
"group": "5_gitlens_open@1",
"alt": "gitlens.copyRemoteRepositoryUrl"
},
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "5_gitlens_open@2"
"group": "5_gitlens_open@2",
"alt": "gitlens.copyRemoteBranchesUrl"
},
{
"command": "gitlens.views.terminalRemoveRemote",
@ -6562,7 +6614,8 @@
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem =~ /gitlens:repository\\b/ && gitlens:hasRemotes",
"group": "2_gitlens_quickopen@2"
"group": "2_gitlens_quickopen@2",
"alt": "gitlens.copyRemoteRepositoryUrl"
},
{
"command": "gitlens.showCommitSearch",

+ 0
- 2
src/commands.ts View File

@ -5,8 +5,6 @@ export * from './commands/browseRepoAtRevision';
export * from './commands/closeUnchangedFiles';
export * from './commands/common';
export * from './commands/copyMessageToClipboard';
export * from './commands/copyRemoteCommitUrlToClipboard';
export * from './commands/copyRemoteFileUrlToClipboard';
export * from './commands/copyShaToClipboard';
export * from './commands/diffBranchWith';
export * from './commands/openDirectoryCompare';

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

@ -32,8 +32,11 @@ export enum Commands {
ComputingFileAnnotations = 'gitlens.computingFileAnnotations',
ConnectRemoteProvider = 'gitlens.connectRemoteProvider',
CopyMessageToClipboard = 'gitlens.copyMessageToClipboard',
CopyRemoteCommitUrlToClipboard = 'gitlens.copyRemoteCommitUrlToClipboard',
CopyRemoteFileUrlToClipboard = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemoteBranchesUrl = 'gitlens.copyRemoteBranchesUrl',
CopyRemoteBranchUrl = 'gitlens.copyRemoteBranchUrl',
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemoteRepositoryUrl = 'gitlens.copyRemoteRepositoryUrl',
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
DiffDirectory = 'gitlens.diffDirectory',
DiffDirectoryWithHead = 'gitlens.diffDirectoryWithHead',

+ 0
- 46
src/commands/copyRemoteCommitUrlToClipboard.ts View File

@ -1,46 +0,0 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
executeEditorCommand,
isCommandViewContextWithCommit,
} from './common';
import { OpenCommitOnRemoteCommandArgs } from './openCommitOnRemote';
export interface CopyRemoteCommitUrlToClipboardCommandArgs extends OpenCommitOnRemoteCommandArgs {
sha?: string;
}
@command()
export class CopyRemoteCommitUrlToClipboardCommand extends ActiveEditorCommand {
constructor() {
super(Commands.CopyRemoteCommitUrlToClipboard);
}
protected preExecute(context: CommandContext, args?: CopyRemoteCommitUrlToClipboardCommandArgs) {
if (context.type === 'uris' || context.type === 'scm-states') {
args = { ...args };
} else if (isCommandViewContextWithCommit(context)) {
if (context.node.commit.isUncommitted) return Promise.resolve(undefined);
args = { ...args, sha: context.node.commit.sha };
return this.execute(
context.editor,
context.node.commit.isFile ? context.node.commit.uri : context.node.uri,
args,
);
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: CopyRemoteCommitUrlToClipboardCommandArgs) {
void (await executeEditorCommand<OpenCommitOnRemoteCommandArgs>(Commands.OpenCommitInRemote, uri, {
...args,
clipboard: true,
}));
}
}

+ 0
- 81
src/commands/copyRemoteFileUrlToClipboard.ts View File

@ -1,81 +0,0 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
executeEditorCommand,
getCommandUri,
isCommandViewContextWithCommit,
} from './common';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { OpenFileOnRemoteCommandArgs } from './openFileOnRemote';
import { StatusFileNode } from '../views/nodes';
export interface CopyRemoteFileUrlToClipboardCommandArgs {
range?: boolean;
sha?: string;
}
@command()
export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand {
constructor() {
super(Commands.CopyRemoteFileUrlToClipboard);
}
protected preExecute(context: CommandContext, args?: CopyRemoteFileUrlToClipboardCommandArgs) {
if (context.type === 'uris' || context.type === 'scm-states') {
args = { ...args, range: false };
} else if (isCommandViewContextWithCommit(context)) {
args = { ...args, range: false, sha: context.node.commit.sha };
// If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet
if (context.node instanceof StatusFileNode) {
args.sha = undefined;
}
return this.execute(
context.editor,
context.node.commit.isFile ? context.node.commit.uri : context.node.uri,
args,
);
} else if (context.type === 'viewItem') {
args = { ...args, range: false };
return this.execute(context.editor, context.node.uri ?? context.uri, args);
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: CopyRemoteFileUrlToClipboardCommandArgs) {
args = { range: true, ...args };
if (args.sha == null) {
uri = getCommandUri(uri, editor);
if (uri == null) return;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return;
args = { ...args };
if (gitUri.sha == null) {
const commit = await Container.git.getCommitForFile(gitUri.repoPath, gitUri.fsPath, {
firstIfNotFound: true,
});
if (commit != null) {
args.sha = commit.sha;
}
} else {
args.sha = gitUri.sha;
}
}
void (await executeEditorCommand<OpenFileOnRemoteCommandArgs>(Commands.OpenFileInRemote, uri, {
...args,
clipboard: true,
}));
}
}

+ 28
- 11
src/commands/openBranchOnRemote.ts View File

@ -18,20 +18,27 @@ import { OpenOnRemoteCommandArgs } from './openOnRemote';
export interface OpenBranchOnRemoteCommandArgs {
branch?: string;
clipboard?: boolean;
remote?: string;
}
@command()
export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenBranchInRemote);
super([Commands.OpenBranchInRemote, Commands.CopyRemoteBranchUrl]);
}
protected preExecute(context: CommandContext, args?: OpenBranchOnRemoteCommandArgs) {
if (isCommandViewContextWithBranch(context)) {
args = { ...args };
args.branch = context.node.branch.name;
args.remote = context.node.branch.getRemoteName();
args = {
...args,
branch: context.node.branch.name,
remote: context.node.branch.getRemoteName(),
};
}
if (context.command === Commands.CopyRemoteBranchUrl) {
args = { ...args, clipboard: true };
}
return this.execute(context.editor, context.uri, args);
@ -42,19 +49,28 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && (await GitUri.fromUri(uri));
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Open Branch On Remote');
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branch Url' : 'Open Branch On Remote',
);
if (!repoPath) return;
args = { ...args };
try {
if (args.branch == null) {
const pick = await ReferencePicker.show(repoPath, 'Open Branch On Remote', 'Choose a branch to open', {
autoPick: true,
// checkmarks: false,
filterBranches: b => b.tracking != null,
include: ReferencesQuickPickIncludes.Branches,
});
const pick = await ReferencePicker.show(
repoPath,
args.clipboard ? 'Copy Remote Branch Url' : 'Open Branch On Remote',
args.clipboard ? 'Choose a branch to copy the url from' : 'Choose a branch to open',
{
autoPick: true,
// checkmarks: false,
filterBranches: b => b.tracking != null,
include: ReferencesQuickPickIncludes.Branches,
},
);
if (pick == null || pick instanceof CommandQuickPickItem) return;
args.branch = pick.ref;
@ -67,6 +83,7 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
},
repoPath: repoPath,
remote: args.remote,
clipboard: args.clipboard,
}));
} catch (ex) {
Logger.error(ex, 'OpenBranchOnRemoteCommand');

+ 13
- 4
src/commands/openBranchesOnRemote.ts View File

@ -16,19 +16,23 @@ import {
import { OpenOnRemoteCommandArgs } from './openOnRemote';
export interface OpenBranchesOnRemoteCommandArgs {
clipboard?: boolean;
remote?: string;
}
@command()
export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenBranchesInRemote);
super([Commands.OpenBranchesInRemote, Commands.CopyRemoteBranchesUrl]);
}
protected preExecute(context: CommandContext, args?: OpenBranchesOnRemoteCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
args = { ...args };
args.remote = context.node.remote.name;
args = { ...args, remote: context.node.remote.name };
}
if (context.command === Commands.CopyRemoteBranchesUrl) {
args = { ...args, clipboard: true };
}
return this.execute(context.editor, context.uri, args);
@ -39,7 +43,11 @@ export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && (await GitUri.fromUri(uri));
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Open Branches on Remote');
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branches Url' : 'Open Branches on Remote',
);
if (!repoPath) return;
try {
@ -49,6 +57,7 @@ export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
},
repoPath: repoPath,
remote: args?.remote,
clipboard: args?.clipboard,
}));
} catch (ex) {
Logger.error(ex, 'OpenBranchesOnRemoteCommand');

+ 12
- 5
src/commands/openCommitOnRemote.ts View File

@ -31,17 +31,24 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
}
constructor() {
super(Commands.OpenCommitInRemote);
super([Commands.OpenCommitInRemote, Commands.CopyRemoteCommitUrl]);
}
protected preExecute(context: CommandContext, args?: OpenCommitOnRemoteCommandArgs) {
let uri = context.uri;
if (isCommandViewContextWithCommit(context)) {
args = { ...args };
args.sha = context.node.commit.sha;
return this.execute(context.editor, context.node.commit.uri, args);
if (context.node.commit.isUncommitted) return Promise.resolve(undefined);
args = { ...args, sha: context.node.commit.sha };
uri = context.node.commit.isFile ? context.node.commit.uri : context.node.uri;
}
if (context.command === Commands.CopyRemoteCommitUrl) {
args = { ...args, clipboard: true };
}
return this.execute(context.editor, context.uri, args);
return this.execute(context.editor, uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: OpenCommitOnRemoteCommandArgs) {

+ 43
- 11
src/commands/openFileOnRemote.ts View File

@ -19,6 +19,7 @@ import { Logger } from '../logger';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
import { Strings } from '../system';
import { StatusFileNode } from '../views/nodes';
export interface OpenFileOnRemoteCommandArgs {
branch?: string;
@ -30,24 +31,55 @@ export interface OpenFileOnRemoteCommandArgs {
@command()
export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenFileInRemote);
super([Commands.OpenFileInRemote, Commands.CopyRemoteFileUrl]);
}
protected preExecute(context: CommandContext, args?: OpenFileOnRemoteCommandArgs) {
if (isCommandViewContextWithCommit(context)) {
protected async preExecute(context: CommandContext, args?: OpenFileOnRemoteCommandArgs) {
let uri = context.uri;
if (context.type === 'uris' || context.type === 'scm-states') {
args = { ...args, range: false };
} else if (isCommandViewContextWithCommit(context)) {
args = { ...args, range: false };
if (isCommandViewContextWithBranch(context)) {
args.branch = context.node.branch !== undefined ? context.node.branch.name : undefined;
if (context.command === Commands.CopyRemoteFileUrl) {
// If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet
args.sha = context.node instanceof StatusFileNode ? undefined : context.node.commit.sha;
} else if (isCommandViewContextWithBranch(context)) {
args.branch = context.node.branch?.name;
}
return this.execute(
context.editor,
context.node.commit.isFile ? context.node.commit.uri : context.node.uri,
args,
);
uri = context.node.commit.isFile ? context.node.commit.uri : context.node.uri;
} else if (context.type === 'viewItem') {
args = { ...args, range: false };
uri = context.node.uri ?? context.uri;
}
if (context.command === Commands.CopyRemoteFileUrl) {
args = { ...args, clipboard: true };
if (args.sha == null) {
const uri = getCommandUri(context.uri, context.editor);
if (uri != null) {
const gitUri = await GitUri.fromUri(uri);
if (gitUri.repoPath) {
if (gitUri.sha == null) {
const commit = await Container.git.getCommitForFile(gitUri.repoPath, gitUri.fsPath, {
firstIfNotFound: true,
});
if (commit != null) {
args.sha = commit.sha;
}
} else {
args.sha = gitUri.sha;
}
}
}
}
}
return this.execute(context.editor, context.uri, args);
return this.execute(context.editor, uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: OpenFileOnRemoteCommandArgs) {

+ 15
- 4
src/commands/openRepoOnRemote.ts View File

@ -16,19 +16,23 @@ import { Logger } from '../logger';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
export interface OpenRepoOnRemoteCommandArgs {
clipboard?: boolean;
remote?: string;
}
@command()
export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenRepoInRemote);
super([Commands.OpenRepoInRemote, Commands.CopyRemoteRepositoryUrl]);
}
protected preExecute(context: CommandContext, args?: OpenRepoOnRemoteCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
args = { ...args };
args.remote = context.node.remote.name;
args = { ...args, remote: context.node.remote.name };
}
if (context.command === Commands.CopyRemoteRepositoryUrl) {
args = { ...args, clipboard: true };
}
return this.execute(context.editor, context.uri, args);
@ -39,7 +43,13 @@ export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && (await GitUri.fromUri(uri));
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Choose which repository to open on remote');
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard
? 'Choose which repository to copy the url from'
: 'Choose which repository to open on remote',
);
if (!repoPath) return;
try {
@ -49,6 +59,7 @@ export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
},
repoPath: repoPath,
remote: args?.remote,
clipboard: args?.clipboard,
}));
} catch (ex) {
Logger.error(ex, 'OpenRepoOnRemoteCommand');

Loading…
Cancel
Save