Skip to content

Commit 4816809

Browse files
committed
Fixes #613 - Changes copy remote url to be the permalink
1 parent c4c0624 commit 4816809

File tree

9 files changed

+61
-35
lines changed

9 files changed

+61
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1515

1616
- Fixes [#606](https://github.com/eamodio/vscode-gitlens/issues/606) - ID for xxx is already registered?!
1717
- Fixes [#607](https://github.com/eamodio/vscode-gitlens/issues/607) - Open file in Remote Doesn't URL encode
18+
- 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)
1819

1920
## [9.3.0] - 2019-01-02
2021

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@
20342034
},
20352035
{
20362036
"command": "gitlens.copyRemoteFileUrlToClipboard",
2037-
"title": "Copy Remote File Url to Clipboard",
2037+
"title": "Copy Remote Url to Clipboard",
20382038
"category": "GitLens",
20392039
"icon": {
20402040
"dark": "images/dark/icon-copy-remote.svg",

src/commands/copyRemoteFileUrlToClipboard.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
'use strict';
22
import { commands, TextEditor, Uri } from 'vscode';
3+
import { Container } from '../container';
4+
import { GitUri } from '../git/gitService';
35
import {
46
ActiveEditorCommand,
57
command,
68
CommandContext,
79
Commands,
8-
isCommandViewContextWithBranch,
10+
getCommandUri,
911
isCommandViewContextWithCommit
1012
} from './common';
1113

1214
export interface CopyRemoteFileUrlToClipboardCommandArgs {
13-
branch?: string;
1415
range?: boolean;
16+
sha?: string;
1517
}
1618

1719
@command()
@@ -27,16 +29,37 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand {
2729
if (isCommandViewContextWithCommit(context)) {
2830
args = { ...args };
2931
args.range = false;
30-
if (isCommandViewContextWithBranch(context)) {
31-
args.branch = context.node.branch !== undefined ? context.node.branch.name : undefined;
32-
}
32+
args.sha = context.node.commit.sha;
33+
3334
return this.execute(context.editor, context.node.commit.uri, args);
3435
}
3536

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

3940
async execute(editor?: TextEditor, uri?: Uri, args: CopyRemoteFileUrlToClipboardCommandArgs = { range: true }) {
41+
if (args.sha === undefined) {
42+
uri = getCommandUri(uri, editor);
43+
if (uri == null) return undefined;
44+
45+
const gitUri = await GitUri.fromUri(uri);
46+
if (!gitUri.repoPath) return undefined;
47+
48+
args = { ...args };
49+
if (gitUri.sha === undefined) {
50+
const commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, {
51+
firstIfNotFound: true
52+
});
53+
54+
if (commit !== undefined) {
55+
args.sha = commit.sha;
56+
}
57+
}
58+
else {
59+
args.sha = gitUri.sha;
60+
}
61+
}
62+
4063
return commands.executeCommand(Commands.OpenFileInRemote, uri, { ...args, clipboard: true });
4164
}
4265
}

src/commands/openCommitInRemote.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
import { commands, TextEditor, Uri, window } from 'vscode';
33
import { Container } from '../container';
4-
import { GitUri } from '../git/gitService';
4+
import { GitUri, RemoteResourceType } from '../git/gitService';
55
import { Logger } from '../logger';
66
import { Messages } from '../messages';
77
import {
@@ -23,7 +23,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
2323
static getMarkdownCommandArgs(sha: string): string;
2424
static getMarkdownCommandArgs(args: OpenCommitInRemoteCommandArgs): string;
2525
static getMarkdownCommandArgs(argsOrSha: OpenCommitInRemoteCommandArgs | string): string {
26-
const args = typeof argsOrSha === 'string' ? { sha: argsOrSha } : argsOrSha;
26+
const args: OpenCommitInRemoteCommandArgs = typeof argsOrSha === 'string' ? { sha: argsOrSha } : argsOrSha;
2727
return super.getMarkdownCommandArgsCore<OpenCommitInRemoteCommandArgs>(Commands.OpenCommitInRemote, args);
2828
}
2929

@@ -80,7 +80,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
8080

8181
return commands.executeCommand(Commands.OpenInRemote, uri, {
8282
resource: {
83-
type: 'commit',
83+
type: RemoteResourceType.Commit,
8484
sha: args.sha
8585
},
8686
remotes

src/commands/openFileInRemote.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { commands, Range, TextEditor, Uri, window } from 'vscode';
33
import { GlyphChars } from '../constants';
44
import { Container } from '../container';
5-
import { GitUri } from '../git/gitService';
5+
import { GitUri, RemoteResourceType } from '../git/gitService';
66
import { Logger } from '../logger';
77
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickpicks';
88
import {
@@ -18,8 +18,9 @@ import { OpenInRemoteCommandArgs } from './openInRemote';
1818

1919
export interface OpenFileInRemoteCommandArgs {
2020
branch?: string;
21-
range?: boolean;
2221
clipboard?: boolean;
22+
range?: boolean;
23+
sha?: string;
2324
}
2425

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

54-
if (args.branch === undefined) {
55+
if (args.branch === undefined && args.sha === undefined) {
5556
const branch = await Container.git.getBranch(gitUri.repoPath);
5657
if (branch === undefined || branch.tracking === undefined) {
5758
const pick = await new BranchesAndTagsQuickPick(gitUri.repoPath).show(
@@ -84,14 +85,15 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
8485
editor.selection.end.with({ line: editor.selection.end.line + 1 })
8586
)
8687
: undefined;
88+
const sha = args.sha || gitUri.sha;
8789

8890
return commands.executeCommand(Commands.OpenInRemote, uri, {
8991
resource: {
90-
type: gitUri.sha === undefined ? 'file' : 'revision',
92+
type: sha === undefined ? RemoteResourceType.File : RemoteResourceType.Revision,
9193
branch: args.branch || 'HEAD',
9294
fileName: gitUri.getRelativePath(),
9395
range: range,
94-
sha: gitUri.sha
96+
sha: sha
9597
},
9698
remotes,
9799
clipboard: args.clipboard

src/quickpicks/branchHistoryQuickPick.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CancellationTokenSource, QuickPickOptions, window } from 'vscode';
33
import { Commands, ShowQuickBranchHistoryCommandArgs } from '../commands';
44
import { GlyphChars } from '../constants';
55
import { Container } from '../container';
6-
import { GitLog, GitUri, RemoteResource } from '../git/gitService';
6+
import { GitLog, GitUri, RemoteResourceType } from '../git/gitService';
77
import { KeyNoopCommand } from '../keyboard';
88
import { Iterables, Strings } from '../system';
99
import {
@@ -65,9 +65,9 @@ export class BranchHistoryQuickPick {
6565
new OpenRemotesCommandQuickPickItem(
6666
remotes,
6767
{
68-
type: 'branch',
69-
branch
70-
} as RemoteResource,
68+
type: RemoteResourceType.Branch,
69+
branch: branch
70+
},
7171
currentCommand
7272
)
7373
);

src/quickpicks/commitFileQuickPick.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../commands';
1515
import { GlyphChars } from '../constants';
1616
import { Container } from '../container';
17-
import { GitLog, GitLogCommit, GitUri, RemoteResource } from '../git/gitService';
17+
import { GitLog, GitLogCommit, GitUri, RemoteResourceType } from '../git/gitService';
1818
import { KeyCommand, KeyNoopCommand } from '../keyboard';
1919
import { Iterables, Strings } from '../system';
2020
import {
@@ -175,10 +175,10 @@ export class CommitFileQuickPick {
175175
new OpenRemotesCommandQuickPickItem(
176176
remotes,
177177
{
178-
type: 'file',
178+
type: RemoteResourceType.File,
179179
fileName: commit.workingFileName,
180180
branch: branch.name
181-
} as RemoteResource,
181+
},
182182
currentCommand
183183
)
184184
);
@@ -190,10 +190,10 @@ export class CommitFileQuickPick {
190190
new OpenRemotesCommandQuickPickItem(
191191
remotes,
192192
{
193-
type: 'revision',
193+
type: RemoteResourceType.Revision,
194194
fileName: commit.fileName,
195-
commit
196-
} as RemoteResource,
195+
commit: commit
196+
},
197197
currentCommand
198198
)
199199
);

src/quickpicks/commitQuickPick.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
GitLogCommit,
2121
GitStashCommit,
2222
GitUri,
23-
RemoteResource
23+
RemoteResourceType
2424
} from '../git/gitService';
2525
import { KeyCommand, KeyNoopCommand, Keys } from '../keyboard';
2626
import { Arrays, Iterables, Strings } from '../system';
@@ -176,9 +176,9 @@ export class CommitQuickPick {
176176
new OpenRemotesCommandQuickPickItem(
177177
remotes,
178178
{
179-
type: 'commit',
179+
type: RemoteResourceType.Commit,
180180
sha: commit.sha
181-
} as RemoteResource,
181+
},
182182
currentCommand
183183
)
184184
);

src/quickpicks/fileHistoryQuickPick.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
44
import { Commands, ShowQuickCurrentBranchHistoryCommandArgs, ShowQuickFileHistoryCommandArgs } from '../commands';
55
import { GlyphChars } from '../constants';
66
import { Container } from '../container';
7-
import { GitLog, GitUri, RemoteResource } from '../git/gitService';
7+
import { GitLog, GitUri, RemoteResource, RemoteResourceType } from '../git/gitService';
88
import { KeyNoopCommand } from '../keyboard';
99
import { Iterables, Strings } from '../system';
1010
import {
@@ -173,19 +173,19 @@ export class FileHistoryQuickPick {
173173

174174
const remotes = await Container.git.getRemotes(uri.repoPath!);
175175
if (remotes.length) {
176-
const resource =
176+
const resource: RemoteResource =
177177
uri.sha !== undefined
178-
? ({
179-
type: 'revision',
178+
? {
179+
type: RemoteResourceType.Revision,
180180
branch: branch.name,
181181
fileName: uri.getRelativePath(),
182182
sha: uri.sha
183-
} as RemoteResource)
184-
: ({
185-
type: 'file',
183+
}
184+
: {
185+
type: RemoteResourceType.File,
186186
branch: branch.name,
187187
fileName: uri.getRelativePath()
188-
} as RemoteResource);
188+
};
189189
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, resource, currentCommand));
190190
}
191191
}

0 commit comments

Comments
 (0)