Browse Source

Adds Show in Commit Graph to view items

e.g. branches, commits, stashes, tags
main
Eric Amodio 2 years ago
parent
commit
eb03a428c7
7 changed files with 82 additions and 35 deletions
  1. +16
    -1
      package.json
  2. +4
    -6
      src/commands/gitCommands.actions.ts
  3. +1
    -1
      src/constants.ts
  4. +5
    -5
      src/git/formatters/commitFormatter.ts
  5. +17
    -0
      src/git/models/reference.ts
  6. +35
    -18
      src/plus/webviews/graph/graphWebview.ts
  7. +4
    -4
      src/webviews/commitDetails/commitDetailsWebviewView.ts

+ 16
- 1
package.json View File

@ -4039,6 +4039,12 @@
"icon": "$(gitlens-graph)"
},
{
"command": "gitlens.showInCommitGraph",
"title": "Show in Commit Graph",
"category": "GitLens+",
"icon": "$(gitlens-graph)"
},
{
"command": "gitlens.refreshGraphPage",
"title": "Refresh",
"category": "GitLens",
@ -6701,6 +6707,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.showInCommitGraph",
"when": "false"
},
{
"command": "gitlens.refreshGraphPage",
"when": "false"
},
@ -9866,9 +9876,14 @@
"group": "3_gitlens_explore@0"
},
{
"command": "gitlens.showInCommitGraph",
"when": "viewItem =~ /gitlens:(branch|commit|stash|tag|file\\b(?=.*?\\b\\+committed\\b))\\b/",
"group": "3_gitlens_explore@1"
},
{
"command": "gitlens.revealCommitInView",
"when": "view =~ /gitlens\\.views\\.(?!commits|branches\\b)/ && viewItem =~ /gitlens:commit\\b/",
"group": "3_gitlens_explore@1"
"group": "3_gitlens_explore@2"
},
{
"command": "gitlens.openCommitOnRemote",

+ 4
- 6
src/commands/gitCommands.actions.ts View File

@ -21,16 +21,15 @@ import type { GitContributor } from '../git/models/contributor';
import type { GitFile } from '../git/models/file';
import type {
GitBranchReference,
GitReference,
GitRevisionReference,
GitStashReference,
GitTagReference,
} from '../git/models/reference';
import { GitRevision } from '../git/models/reference';
import { GitReference, GitRevision } from '../git/models/reference';
import type { GitRemote } from '../git/models/remote';
import type { Repository } from '../git/models/repository';
import type { GitWorktree } from '../git/models/worktree';
import type { ShowCommitInGraphCommandArgs } from '../plus/webviews/graph/graphWebview';
import type { ShowInCommitGraphCommandArgs } from '../plus/webviews/graph/graphWebview';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { ensure } from '../system/array';
import { executeCommand, executeCoreCommand, executeEditorCommand } from '../system/command';
@ -778,9 +777,8 @@ export namespace GitActions {
commit: GitRevisionReference | GitCommit,
options?: { preserveFocus?: boolean },
): Promise<void> {
void (await executeCommand<ShowCommitInGraphCommandArgs>(Commands.ShowCommitInGraph, {
sha: commit.ref,
repoPath: commit.repoPath,
void (await executeCommand<ShowInCommitGraphCommandArgs>(Commands.ShowInCommitGraph, {
ref: GitReference.fromRevision(commit),
preserveFocus: options?.preserveFocus,
}));
}

+ 1
- 1
src/constants.ts View File

@ -163,13 +163,13 @@ export const enum Commands {
SearchCommitsInView = 'gitlens.views.searchAndCompare.searchCommits',
SetViewsLayout = 'gitlens.setViewsLayout',
ShowBranchesView = 'gitlens.showBranchesView',
ShowCommitInGraph = 'gitlens.showCommitInGraph',
ShowCommitInView = 'gitlens.showCommitInView',
ShowCommitsInView = 'gitlens.showCommitsInView',
ShowCommitsView = 'gitlens.showCommitsView',
ShowContributorsView = 'gitlens.showContributorsView',
ShowHomeView = 'gitlens.showHomeView',
ShowFileHistoryView = 'gitlens.showFileHistoryView',
ShowInCommitGraph = 'gitlens.showInCommitGraph',
ShowLastQuickPick = 'gitlens.showLastQuickPick',
ShowLineHistoryView = 'gitlens.showLineHistoryView',
ShowQuickBranchHistory = 'gitlens.showQuickBranchHistory',

+ 5
- 5
src/git/formatters/commitFormatter.ts View File

@ -19,7 +19,7 @@ import { configuration, DateStyle, FileAnnotationType } from '../../configuratio
import { Commands, GlyphChars } from '../../constants';
import { Container } from '../../container';
import { emojify } from '../../emojis';
import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import { join, map } from '../../system/iterable';
import { PromiseCancelledError } from '../../system/promise';
import type { TokenOptions } from '../../system/string';
@ -30,7 +30,7 @@ import type { GitCommit } from '../models/commit';
import { isCommit } from '../models/commit';
import type { IssueOrPullRequest } from '../models/issue';
import { PullRequest } from '../models/pullRequest';
import { GitRevision } from '../models/reference';
import { GitReference, GitRevision } from '../models/reference';
import { GitRemote } from '../models/remote';
import type { RemoteProvider } from '../remotes/remoteProvider';
import type { FormatOptions } from './formatter';
@ -354,9 +354,9 @@ export class CommitFormatter extends Formatter {
)} "Open Blame Prior to this Change")`;
}
commands += ` &nbsp;[$(gitlens-graph)](${Command.getMarkdownCommandArgsCore<ShowCommitInGraphCommandArgs>(
Commands.ShowCommitInGraph,
{ sha: this._item.sha, repoPath: this._item.repoPath },
commands += ` &nbsp;[$(gitlens-graph)](${Command.getMarkdownCommandArgsCore<ShowInCommitGraphCommandArgs>(
Commands.ShowInCommitGraph,
{ ref: GitReference.fromRevision(this._item) },
)} "Show in Commit Graph")`;
if (this._options.remotes != null && this._options.remotes.length !== 0) {

+ 17
- 0
src/git/models/reference.ts View File

@ -209,6 +209,23 @@ export namespace GitReference {
});
}
export function fromRevision(revision: GitRevisionReference) {
if (revision.refType === 'stash') {
return create(revision.ref, revision.repoPath, {
refType: revision.refType,
name: revision.name,
number: revision.number,
message: revision.message,
});
}
return create(revision.ref, revision.repoPath, {
refType: revision.refType,
name: revision.name,
message: revision.message,
});
}
export function fromTag(tag: GitTagReference) {
return create(tag.ref, tag.repoPath, {
refType: tag.refType,

+ 35
- 18
src/plus/webviews/graph/graphWebview.ts View File

@ -47,6 +47,11 @@ import { updateRecordValue } from '../../../system/object';
import { isDarkTheme, isLightTheme } from '../../../system/utils';
import type { WebviewItemContext } from '../../../system/webview';
import { isWebviewItemContext, serializeWebviewItemContext } from '../../../system/webview';
import type { BranchNode } from '../../../views/nodes/branchNode';
import type { CommitFileNode } from '../../../views/nodes/commitFileNode';
import type { CommitNode } from '../../../views/nodes/commitNode';
import type { StashNode } from '../../../views/nodes/stashNode';
import type { TagNode } from '../../../views/nodes/tagNode';
import { RepositoryFolderNode } from '../../../views/nodes/viewNode';
import { onIpc } from '../../../webviews/protocol';
import type { IpcMessage, IpcMessageParams, IpcNotificationType } from '../../../webviews/protocol';
@ -88,9 +93,8 @@ import {
UpdateSelectionCommandType,
} from './protocol';
export interface ShowCommitInGraphCommandArgs {
repoPath: string;
sha: string;
export interface ShowInCommitGraphCommandArgs {
ref: GitReference;
preserveFocus?: boolean;
}
@ -157,22 +161,35 @@ export class GraphWebview extends WebviewBase {
this.disposables.push(
configuration.onDidChange(this.onConfigurationChanged, this),
{ dispose: () => this._statusBarItem?.dispose() },
registerCommand(Commands.ShowCommitInGraph, (args: ShowCommitInGraphCommandArgs) => {
this.repository = this.container.git.getRepository(args.repoPath);
this.setSelectedRows(args.sha);
if (this._panel == null) {
void this.show({ preserveFocus: args.preserveFocus });
} else {
if (this._graph?.ids.has(args.sha)) {
void this.notifyDidChangeSelection();
return;
registerCommand(
Commands.ShowInCommitGraph,
async (
args: ShowInCommitGraphCommandArgs | BranchNode | CommitNode | CommitFileNode | StashNode | TagNode,
) => {
this.repository = this.container.git.getRepository(args.ref.repoPath);
let sha = args.ref.ref;
if (!GitRevision.isSha(sha)) {
sha = await this.container.git.resolveReference(args.ref.repoPath, sha, undefined, {
force: true,
});
}
this.setSelectedRows(args.sha);
void this.onGetMoreCommits({ sha: args.sha });
}
}),
this.setSelectedRows(sha);
const preserveFocus = 'preserveFocus' in args ? args.preserveFocus ?? false : false;
if (this._panel == null) {
void this.show({ preserveFocus: preserveFocus });
} else {
this._panel.reveal(this._panel.viewColumn ?? ViewColumn.Active, preserveFocus ?? false);
if (this._graph?.ids.has(sha)) {
void this.notifyDidChangeSelection();
return;
}
this.setSelectedRows(sha);
void this.onGetMoreCommits({ sha: sha });
}
},
),
);
this.onConfigurationChanged();

+ 4
- 4
src/webviews/commitDetails/commitDetailsWebviewView.ts View File

@ -18,8 +18,9 @@ import { serializeIssueOrPullRequest } from '../../git/models/issue';
import type { PullRequest } from '../../git/models/pullRequest';
import { serializePullRequest } from '../../git/models/pullRequest';
import type { GitRevisionReference } from '../../git/models/reference';
import { GitReference } from '../../git/models/reference';
import { Logger } from '../../logger';
import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import { executeCommand } from '../../system/command';
import type { DateTimeFormat } from '../../system/date';
import { debug, getLogScope } from '../../system/decorators/log';
@ -237,9 +238,8 @@ export class CommitDetailsWebviewView extends WebviewViewBase
case 'graph':
if (this._context.commit == null) return;
void executeCommand<ShowCommitInGraphCommandArgs>(Commands.ShowCommitInGraph, {
repoPath: this._context.commit.repoPath,
sha: this._context.commit.sha,
void executeCommand<ShowInCommitGraphCommandArgs>(Commands.ShowInCommitGraph, {
ref: GitReference.fromRevision(this._context.commit),
});
break;
case 'more':

Loading…
Cancel
Save