Skip to content

Commit

Permalink
Fixes #613 - Changes copy remote url to be the permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 8, 2019
1 parent c4c0624 commit 4816809
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- Fixes [#606](https://github.com/eamodio/vscode-gitlens/issues/606) - ID for xxx is already registered?!
- Fixes [#607](https://github.com/eamodio/vscode-gitlens/issues/607) - Open file in Remote Doesn't URL encode
- Fixes [#613](https://github.com/eamodio/vscode-gitlens/issues/613) - Change Copy Remote URL to Clipboard to always copy a permalink (e.g. revision link)

## [9.3.0] - 2019-01-02

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@
},
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"title": "Copy Remote File Url to Clipboard",
"title": "Copy Remote Url to Clipboard",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-remote.svg",
Expand Down
33 changes: 28 additions & 5 deletions src/commands/copyRemoteFileUrlToClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
'use strict';
import { commands, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import { GitUri } from '../git/gitService';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
isCommandViewContextWithBranch,
getCommandUri,
isCommandViewContextWithCommit
} from './common';

export interface CopyRemoteFileUrlToClipboardCommandArgs {
branch?: string;
range?: boolean;
sha?: string;
}

@command()
Expand All @@ -27,16 +29,37 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand {
if (isCommandViewContextWithCommit(context)) {
args = { ...args };
args.range = false;
if (isCommandViewContextWithBranch(context)) {
args.branch = context.node.branch !== undefined ? context.node.branch.name : undefined;
}
args.sha = context.node.commit.sha;

return this.execute(context.editor, context.node.commit.uri, args);
}

return this.execute(context.editor, context.uri, args);
}

async execute(editor?: TextEditor, uri?: Uri, args: CopyRemoteFileUrlToClipboardCommandArgs = { range: true }) {
if (args.sha === undefined) {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;

const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;

args = { ...args };
if (gitUri.sha === undefined) {
const commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, {
firstIfNotFound: true
});

if (commit !== undefined) {
args.sha = commit.sha;
}
}
else {
args.sha = gitUri.sha;
}
}

return commands.executeCommand(Commands.OpenFileInRemote, uri, { ...args, clipboard: true });
}
}
6 changes: 3 additions & 3 deletions src/commands/openCommitInRemote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import { GitUri } from '../git/gitService';
import { GitUri, RemoteResourceType } from '../git/gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import {
Expand All @@ -23,7 +23,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
static getMarkdownCommandArgs(sha: string): string;
static getMarkdownCommandArgs(args: OpenCommitInRemoteCommandArgs): string;
static getMarkdownCommandArgs(argsOrSha: OpenCommitInRemoteCommandArgs | string): string {
const args = typeof argsOrSha === 'string' ? { sha: argsOrSha } : argsOrSha;
const args: OpenCommitInRemoteCommandArgs = typeof argsOrSha === 'string' ? { sha: argsOrSha } : argsOrSha;
return super.getMarkdownCommandArgsCore<OpenCommitInRemoteCommandArgs>(Commands.OpenCommitInRemote, args);
}

Expand Down Expand Up @@ -80,7 +80,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {

return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'commit',
type: RemoteResourceType.Commit,
sha: args.sha
},
remotes
Expand Down
12 changes: 7 additions & 5 deletions src/commands/openFileInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitService';
import { GitUri, RemoteResourceType } from '../git/gitService';
import { Logger } from '../logger';
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickpicks';
import {
Expand All @@ -18,8 +18,9 @@ import { OpenInRemoteCommandArgs } from './openInRemote';

export interface OpenFileInRemoteCommandArgs {
branch?: string;
range?: boolean;
clipboard?: boolean;
range?: boolean;
sha?: string;
}

@command()
Expand Down Expand Up @@ -51,7 +52,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;

if (args.branch === undefined) {
if (args.branch === undefined && args.sha === undefined) {
const branch = await Container.git.getBranch(gitUri.repoPath);
if (branch === undefined || branch.tracking === undefined) {
const pick = await new BranchesAndTagsQuickPick(gitUri.repoPath).show(
Expand Down Expand Up @@ -84,14 +85,15 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
editor.selection.end.with({ line: editor.selection.end.line + 1 })
)
: undefined;
const sha = args.sha || gitUri.sha;

return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: gitUri.sha === undefined ? 'file' : 'revision',
type: sha === undefined ? RemoteResourceType.File : RemoteResourceType.Revision,
branch: args.branch || 'HEAD',
fileName: gitUri.getRelativePath(),
range: range,
sha: gitUri.sha
sha: sha
},
remotes,
clipboard: args.clipboard
Expand Down
8 changes: 4 additions & 4 deletions src/quickpicks/branchHistoryQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CancellationTokenSource, QuickPickOptions, window } from 'vscode';
import { Commands, ShowQuickBranchHistoryCommandArgs } from '../commands';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitLog, GitUri, RemoteResource } from '../git/gitService';
import { GitLog, GitUri, RemoteResourceType } from '../git/gitService';
import { KeyNoopCommand } from '../keyboard';
import { Iterables, Strings } from '../system';
import {
Expand Down Expand Up @@ -65,9 +65,9 @@ export class BranchHistoryQuickPick {
new OpenRemotesCommandQuickPickItem(
remotes,
{
type: 'branch',
branch
} as RemoteResource,
type: RemoteResourceType.Branch,
branch: branch
},
currentCommand
)
);
Expand Down
12 changes: 6 additions & 6 deletions src/quickpicks/commitFileQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../commands';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitLog, GitLogCommit, GitUri, RemoteResource } from '../git/gitService';
import { GitLog, GitLogCommit, GitUri, RemoteResourceType } from '../git/gitService';
import { KeyCommand, KeyNoopCommand } from '../keyboard';
import { Iterables, Strings } from '../system';
import {
Expand Down Expand Up @@ -175,10 +175,10 @@ export class CommitFileQuickPick {
new OpenRemotesCommandQuickPickItem(
remotes,
{
type: 'file',
type: RemoteResourceType.File,
fileName: commit.workingFileName,
branch: branch.name
} as RemoteResource,
},
currentCommand
)
);
Expand All @@ -190,10 +190,10 @@ export class CommitFileQuickPick {
new OpenRemotesCommandQuickPickItem(
remotes,
{
type: 'revision',
type: RemoteResourceType.Revision,
fileName: commit.fileName,
commit
} as RemoteResource,
commit: commit
},
currentCommand
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/quickpicks/commitQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
GitLogCommit,
GitStashCommit,
GitUri,
RemoteResource
RemoteResourceType
} from '../git/gitService';
import { KeyCommand, KeyNoopCommand, Keys } from '../keyboard';
import { Arrays, Iterables, Strings } from '../system';
Expand Down Expand Up @@ -176,9 +176,9 @@ export class CommitQuickPick {
new OpenRemotesCommandQuickPickItem(
remotes,
{
type: 'commit',
type: RemoteResourceType.Commit,
sha: commit.sha
} as RemoteResource,
},
currentCommand
)
);
Expand Down
16 changes: 8 additions & 8 deletions src/quickpicks/fileHistoryQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, ShowQuickCurrentBranchHistoryCommandArgs, ShowQuickFileHistoryCommandArgs } from '../commands';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitLog, GitUri, RemoteResource } from '../git/gitService';
import { GitLog, GitUri, RemoteResource, RemoteResourceType } from '../git/gitService';
import { KeyNoopCommand } from '../keyboard';
import { Iterables, Strings } from '../system';
import {
Expand Down Expand Up @@ -173,19 +173,19 @@ export class FileHistoryQuickPick {

const remotes = await Container.git.getRemotes(uri.repoPath!);
if (remotes.length) {
const resource =
const resource: RemoteResource =
uri.sha !== undefined
? ({
type: 'revision',
? {
type: RemoteResourceType.Revision,
branch: branch.name,
fileName: uri.getRelativePath(),
sha: uri.sha
} as RemoteResource)
: ({
type: 'file',
}
: {
type: RemoteResourceType.File,
branch: branch.name,
fileName: uri.getRelativePath()
} as RemoteResource);
};
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, resource, currentCommand));
}
}
Expand Down

0 comments on commit 4816809

Please sign in to comment.