diff --git a/CHANGELOG.md b/CHANGELOG.md index afd42fa..c7be30a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index e44a8b7..591fa50 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/commands/copyRemoteFileUrlToClipboard.ts b/src/commands/copyRemoteFileUrlToClipboard.ts index 1658134..b7bba02 100644 --- a/src/commands/copyRemoteFileUrlToClipboard.ts +++ b/src/commands/copyRemoteFileUrlToClipboard.ts @@ -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() @@ -27,9 +29,8 @@ 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); } @@ -37,6 +38,28 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand { } 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 }); } } diff --git a/src/commands/openCommitInRemote.ts b/src/commands/openCommitInRemote.ts index e281061..92ec7c6 100644 --- a/src/commands/openCommitInRemote.ts +++ b/src/commands/openCommitInRemote.ts @@ -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 { @@ -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(Commands.OpenCommitInRemote, args); } @@ -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 diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 315a11d..25cb8b9 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -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 { @@ -18,8 +18,9 @@ import { OpenInRemoteCommandArgs } from './openInRemote'; export interface OpenFileInRemoteCommandArgs { branch?: string; - range?: boolean; clipboard?: boolean; + range?: boolean; + sha?: string; } @command() @@ -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( @@ -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 diff --git a/src/quickpicks/branchHistoryQuickPick.ts b/src/quickpicks/branchHistoryQuickPick.ts index 232b9b4..14d0838 100644 --- a/src/quickpicks/branchHistoryQuickPick.ts +++ b/src/quickpicks/branchHistoryQuickPick.ts @@ -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 { @@ -65,9 +65,9 @@ export class BranchHistoryQuickPick { new OpenRemotesCommandQuickPickItem( remotes, { - type: 'branch', - branch - } as RemoteResource, + type: RemoteResourceType.Branch, + branch: branch + }, currentCommand ) ); diff --git a/src/quickpicks/commitFileQuickPick.ts b/src/quickpicks/commitFileQuickPick.ts index 38a2676..8a5054f 100644 --- a/src/quickpicks/commitFileQuickPick.ts +++ b/src/quickpicks/commitFileQuickPick.ts @@ -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 { @@ -175,10 +175,10 @@ export class CommitFileQuickPick { new OpenRemotesCommandQuickPickItem( remotes, { - type: 'file', + type: RemoteResourceType.File, fileName: commit.workingFileName, branch: branch.name - } as RemoteResource, + }, currentCommand ) ); @@ -190,10 +190,10 @@ export class CommitFileQuickPick { new OpenRemotesCommandQuickPickItem( remotes, { - type: 'revision', + type: RemoteResourceType.Revision, fileName: commit.fileName, - commit - } as RemoteResource, + commit: commit + }, currentCommand ) ); diff --git a/src/quickpicks/commitQuickPick.ts b/src/quickpicks/commitQuickPick.ts index a2bd6da..e870ae9 100644 --- a/src/quickpicks/commitQuickPick.ts +++ b/src/quickpicks/commitQuickPick.ts @@ -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'; @@ -176,9 +176,9 @@ export class CommitQuickPick { new OpenRemotesCommandQuickPickItem( remotes, { - type: 'commit', + type: RemoteResourceType.Commit, sha: commit.sha - } as RemoteResource, + }, currentCommand ) ); diff --git a/src/quickpicks/fileHistoryQuickPick.ts b/src/quickpicks/fileHistoryQuickPick.ts index 8dbab9f..e5ccb0e 100644 --- a/src/quickpicks/fileHistoryQuickPick.ts +++ b/src/quickpicks/fileHistoryQuickPick.ts @@ -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 { @@ -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)); } }