Przeglądaj źródła

Adds more context menus actions

main
Eric Amodio 2 lat temu
rodzic
commit
1c1b8ef4cc
8 zmienionych plików z 188 dodań i 16 usunięć
  1. +90
    -3
      package.json
  2. +6
    -0
      src/commands/copyMessageToClipboard.ts
  3. +16
    -4
      src/commands/openCommitOnRemote.ts
  4. +7
    -2
      src/env/node/git/localGitProvider.ts
  5. +1
    -1
      src/git/gitProvider.ts
  6. +2
    -2
      src/git/gitProviderService.ts
  7. +6
    -1
      src/plus/github/githubGitProvider.ts
  8. +60
    -3
      src/plus/webviews/graph/graphWebview.ts

+ 90
- 3
package.json Wyświetl plik

@ -6251,6 +6251,12 @@
"category": "GitLens"
},
{
"command": "gitlens.graph.copyRemoteBranchUrl",
"title": "Copy Remote Branch Url",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.createBranch",
"title": "Create Branch...",
"category": "GitLens",
@ -6306,6 +6312,30 @@
"category": "GitLens"
},
{
"command": "gitlens.graph.copyMessage",
"title": "Copy Message",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.copySha",
"title": "Copy SHA",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.copyRemoteCommitUrl",
"title": "Copy Remote Commit Url",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.openCommitOnRemote",
"title": "Open Commit on Remote",
"category": "GitLens",
"icon": "$(globe)"
},
{
"command": "gitlens.graph.rebaseOntoCommit",
"title": "Rebase Current Branch onto Commit...",
"category": "GitLens"
@ -8196,6 +8226,10 @@
"when": "false"
},
{
"command": "gitlens.graph.copyRemoteBranchUrl",
"when": "false"
},
{
"command": "gitlens.graph.createBranch",
"when": "false"
},
@ -8236,6 +8270,22 @@
"when": "false"
},
{
"command": "gitlens.graph.copyMessage",
"when": "false"
},
{
"command": "gitlens.graph.copySha",
"when": "false"
},
{
"command": "gitlens.graph.copyRemoteCommitUrl",
"when": "false"
},
{
"command": "gitlens.graph.openCommitOnRemote",
"when": "false"
},
{
"command": "gitlens.graph.rebaseOntoCommit",
"when": "false"
},
@ -9815,7 +9865,7 @@
},
{
"command": "gitlens.openCommitOnRemote",
"when": "viewItem =~ /gitlens:commit\\b/ && gitlens:hasRemotes",
"when": "gitlens:hasRemotes && viewItem =~ /gitlens:commit\\b/",
"group": "3_gitlens_explore@2",
"alt": "gitlens.copyRemoteCommitUrl"
},
@ -10850,6 +10900,17 @@
"group": "1_gitlens_actions_1@2"
},
{
"command": "gitlens.graph.openCommitOnRemote",
"when": "gitlens:hasRemotes && webviewItem =~ /gitlens:commit\\b/",
"group": "3_gitlens_explore@2",
"alt": "gitlens.copyRemoteCommitUrl"
},
{
"submenu": "gitlens/commit/copy",
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/",
"group": "7_gitlens_cutcopypaste@2"
},
{
"command": "gitlens.graph.applyStash",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem == gitlens:stash",
"group": "1_gitlens_actions@1"
@ -10931,17 +10992,43 @@
},
{
"command": "gitlens.copyMessageToClipboard",
"when": "viewItem",
"group": "1_gitlens@2"
},
{
"command": "gitlens.copyRemoteCommitUrl",
"when": "viewItem =~ /gitlens:(commit|file\\b(?=.*?\\b\\+committed\\b))/ && gitlens:hasRemotes",
"when": "gitlens:hasRemotes && viewItem =~ /gitlens:(commit|file\\b(?=.*?\\b\\+committed\\b))/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.copyRemoteBranchUrl",
"when": "gitlens:hasRemotes && viewItem =~ /gitlens:branch/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "viewItem =~ /gitlens:(file\\b(?=.*?\\b\\+committed\\b)|history:(file|line)|status:file)\\b/ && gitlens:hasRemotes",
"when": "gitlens:hasRemotes && viewItem =~ /gitlens:(file\\b(?=.*?\\b\\+committed\\b)|history:(file|line)|status:file)\\b/",
"group": "2_gitlens@2"
},
{
"command": "gitlens.graph.copySha",
"when": "webviewItem =~ /gitlens:(?!stash\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.graph.copyMessage",
"when": "webviewItem",
"group": "1_gitlens@2"
},
{
"command": "gitlens.graph.copyRemoteCommitUrl",
"when": "gitlens:hasRemotes && webviewItem =~ /gitlens:commit/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.graph.copyRemoteBranchUrl",
"when": "gitlens:hasRemotes && webviewItem =~ /gitlens:branch/",
"group": "2_gitlens@1"
}
],
"gitlens/commit/changes": [

+ 6
- 0
src/commands/copyMessageToClipboard.ts Wyświetl plik

@ -20,6 +20,7 @@ import { GitActions } from './gitCommands.actions';
export interface CopyMessageToClipboardCommandArgs {
message?: string;
sha?: string;
repoPath?: string;
}
@command()
@ -60,6 +61,11 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
try {
if (!args.message) {
if (args.repoPath != null && args.sha != null) {
await GitActions.Commit.copyMessageToClipboard({ ref: args.sha, repoPath: args.repoPath });
return;
}
let repoPath;
// If we don't have an editor then get the message of the last commit to the branch

+ 16
- 4
src/commands/openCommitOnRemote.ts Wyświetl plik

@ -7,6 +7,7 @@ import { GitRevision } from '../git/models/reference';
import { RemoteResourceType } from '../git/models/remoteResource';
import { Logger } from '../logger';
import { showFileNotUnderSourceControlWarningMessage } from '../messages';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { command, executeCommand } from '../system/command';
import type { CommandContext } from './base';
import {
@ -59,10 +60,21 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args?: OpenCommitOnRemoteCommandArgs) {
uri = getCommandUri(uri, editor);
if (uri == null) return;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return;
let gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = (
await RepositoryPicker.getBestRepositoryOrShow(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Commit Url' : 'Open Commit On Remote',
)
)?.path;
if (!repoPath) return;
if (gitUri == null) {
gitUri = GitUri.fromRepoPath(repoPath);
}
args = { ...args };
@ -89,7 +101,7 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
type: RemoteResourceType.Commit,
sha: args.sha,
},
repoPath: gitUri.repoPath,
repoPath: repoPath,
clipboard: args.clipboard,
}));
} catch (ex) {

+ 7
- 2
src/env/node/git/localGitProvider.ts Wyświetl plik

@ -4085,7 +4085,12 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log()
async resolveReference(repoPath: string, ref: string, pathOrUri?: string | Uri, options?: { timeout?: number }) {
async resolveReference(
repoPath: string,
ref: string,
pathOrUri?: string | Uri,
options?: { force?: boolean; timeout?: number },
) {
if (
!ref ||
ref === GitRevision.deletedOrMissing ||
@ -4097,7 +4102,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (pathOrUri == null) {
// If it doesn't look like a sha at all (e.g. branch name) or is a stash ref (^3) don't try to resolve it
if (!GitRevision.isShaLike(ref) || ref.endsWith('^3')) return ref;
if ((!options?.force && !GitRevision.isShaLike(ref)) || ref.endsWith('^3')) return ref;
return (await this.git.rev_parse__verify(repoPath, ref)) ?? ref;
}

+ 1
- 1
src/git/gitProvider.ts Wyświetl plik

@ -401,7 +401,7 @@ export interface GitProvider extends Disposable {
repoPath: string,
ref: string,
pathOrUri?: string | Uri,
options?: { timeout?: number | undefined },
options?: { force?: boolean; timeout?: number | undefined },
): Promise<string>;
richSearchCommits(
repoPath: string,

+ 2
- 2
src/git/gitProviderService.ts Wyświetl plik

@ -2201,9 +2201,9 @@ export class GitProviderService implements Disposable {
repoPath: string,
ref: string,
path?: string,
options?: { timeout?: number },
options?: { force?: boolean; timeout?: number },
): Promise<string>;
async resolveReference(repoPath: string, ref: string, uri?: Uri, options?: { timeout?: number }): Promise<string>;
async resolveReference(repoPath: string, ref: string, uri?: Uri, options?: { force?: boolean; timeout?: number }): Promise<string>;
@gate()
@log()
async resolveReference(

+ 6
- 1
src/plus/github/githubGitProvider.ts Wyświetl plik

@ -2425,7 +2425,12 @@ export class GitHubGitProvider implements GitProvider, Disposable {
async openDirectoryCompare(_repoPath: string, _ref1: string, _ref2?: string, _tool?: string): Promise<void> {}
@log()
async resolveReference(repoPath: string, ref: string, pathOrUri?: string | Uri, _options?: { timeout?: number }) {
async resolveReference(
repoPath: string,
ref: string,
pathOrUri?: string | Uri,
_options?: { force?: boolean; timeout?: number },
) {
if (
!ref ||
ref === GitRevision.deletedOrMissing ||

+ 60
- 3
src/plus/webviews/graph/graphWebview.ts Wyświetl plik

@ -2,7 +2,12 @@ import type { ColorTheme, ConfigurationChangeEvent, Disposable, Event, StatusBar
import { CancellationTokenSource, EventEmitter, MarkdownString, StatusBarAlignment, ViewColumn, window } from 'vscode';
import type { CreatePullRequestActionContext } from '../../../api/gitlens';
import { getAvatarUri } from '../../../avatars';
import type { OpenBranchOnRemoteCommandArgs } from '../../../commands';
import type {
CopyMessageToClipboardCommandArgs,
CopyShaToClipboardCommandArgs,
OpenBranchOnRemoteCommandArgs,
OpenCommitOnRemoteCommandArgs,
} from '../../../commands';
import { parseCommandContext } from '../../../commands/base';
import { GitActions } from '../../../commands/gitCommands.actions';
import { configuration } from '../../../configuration';
@ -19,7 +24,7 @@ import type {
GitStashReference,
GitTagReference,
} from '../../../git/models/reference';
import { GitReference } from '../../../git/models/reference';
import { GitReference, GitRevision } from '../../../git/models/reference';
import type { Repository, RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import type { GitSearch } from '../../../git/search';
@ -209,6 +214,7 @@ export class GraphWebview extends WebviewBase {
registerCommand(Commands.RefreshGraphPage, () => this.refresh(true)),
registerCommand('gitlens.graph.createBranch', this.createBranch, this),
registerCommand('gitlens.graph.deleteBranch', this.deleteBranch, this),
registerCommand('gitlens.graph.copyRemoteBranchUrl', item => this.openBranchOnRemote(item, true), this),
registerCommand('gitlens.graph.openBranchOnRemote', this.openBranchOnRemote, this),
registerCommand('gitlens.graph.mergeBranchInto', this.mergeBranchInto, this),
registerCommand('gitlens.graph.rebaseOntoBranch', this.rebase, this),
@ -219,6 +225,8 @@ export class GraphWebview extends WebviewBase {
registerCommand('gitlens.graph.switchToBranch', this.switchTo, this),
registerCommand('gitlens.graph.cherryPick', this.cherryPick, this),
registerCommand('gitlens.graph.copyRemoteCommitUrl', item => this.openCommitOnRemote(item, true), this),
registerCommand('gitlens.graph.openCommitOnRemote', this.openCommitOnRemote, this),
registerCommand('gitlens.graph.rebaseOntoCommit', this.rebase, this),
registerCommand('gitlens.graph.resetCommit', this.resetCommit, this),
registerCommand('gitlens.graph.resetToCommit', this.resetToCommit, this),
@ -237,6 +245,9 @@ export class GraphWebview extends WebviewBase {
registerCommand('gitlens.graph.createPullRequest', this.createPullRequest, this),
registerCommand('gitlens.graph.copyMessage', this.copyMessage, this),
registerCommand('gitlens.graph.copySha', this.copySha, this),
registerCommand('gitlens.graph.columnAuthorOn', () => this.toggleColumn('author', true)),
registerCommand('gitlens.graph.columnAuthorOff', () => this.toggleColumn('author', false)),
registerCommand('gitlens.graph.columnDateTimeOn', () => this.toggleColumn('datetime', true)),
@ -915,12 +926,13 @@ export class GraphWebview extends WebviewBase {
}
@debug()
private openBranchOnRemote(item: GraphItemContext) {
private openBranchOnRemote(item: GraphItemContext, clipboard?: boolean) {
if (isGraphItemRefContext(item, 'branch')) {
const { ref } = item.webviewItemValue;
return executeCommand<OpenBranchOnRemoteCommandArgs>(Commands.OpenBranchOnRemote, {
branch: ref.name,
remote: ref.upstream?.name,
clipboard: clipboard,
});
}
@ -977,6 +989,51 @@ export class GraphWebview extends WebviewBase {
}
@debug()
private copyMessage(item: GraphItemContext) {
if (isGraphItemRefContext(item)) {
const { ref } = item.webviewItemValue;
return executeCommand<CopyMessageToClipboardCommandArgs>(Commands.CopyMessageToClipboard, {
repoPath: ref.repoPath,
sha: ref.ref,
message: 'message' in ref ? ref.message : undefined,
});
}
return Promise.resolve();
}
@debug()
private async copySha(item: GraphItemContext) {
if (isGraphItemRefContext(item)) {
const { ref } = item.webviewItemValue;
let sha = ref.ref;
if (!GitRevision.isSha(sha)) {
sha = await this.container.git.resolveReference(ref.repoPath, sha, undefined, { force: true });
}
return executeCommand<CopyShaToClipboardCommandArgs>(Commands.CopyShaToClipboard, {
sha: sha,
});
}
return Promise.resolve();
}
@debug()
private openCommitOnRemote(item: GraphItemContext, clipboard?: boolean) {
if (isGraphItemRefContext(item, 'revision')) {
const { ref } = item.webviewItemValue;
return executeCommand<OpenCommitOnRemoteCommandArgs>(Commands.OpenCommitOnRemote, {
sha: ref.ref,
clipboard: clipboard,
});
}
return Promise.resolve();
}
@debug()
private resetCommit(item: GraphItemContext) {
if (isGraphItemRefContext(item, 'revision')) {
const { ref } = item.webviewItemValue;

Ładowanie…
Anuluj
Zapisz