Просмотр исходного кода

Fixes #613 - Changes copy remote url to be the permalink

main
Eric Amodio 5 лет назад
Родитель
Сommit
4816809d52
9 измененных файлов: 61 добавлений и 35 удалений
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -1
      package.json
  3. +28
    -5
      src/commands/copyRemoteFileUrlToClipboard.ts
  4. +3
    -3
      src/commands/openCommitInRemote.ts
  5. +7
    -5
      src/commands/openFileInRemote.ts
  6. +4
    -4
      src/quickpicks/branchHistoryQuickPick.ts
  7. +6
    -6
      src/quickpicks/commitFileQuickPick.ts
  8. +3
    -3
      src/quickpicks/commitQuickPick.ts
  9. +8
    -8
      src/quickpicks/fileHistoryQuickPick.ts

+ 1
- 0
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

+ 1
- 1
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",

+ 28
- 5
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 });
}
}

+ 3
- 3
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<OpenCommitInRemoteCommandArgs>(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

+ 7
- 5
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

+ 4
- 4
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
)
);

+ 6
- 6
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
)
);

+ 3
- 3
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
)
);

+ 8
- 8
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));
}
}

Загрузка…
Отмена
Сохранить