Browse Source

Adds correct stash lookup for Commit Details view

Adds visibility check for stashes view following
main
Eric Amodio 2 years ago
parent
commit
54f56192b6
2 changed files with 49 additions and 14 deletions
  1. +9
    -2
      src/commands/gitCommands.actions.ts
  2. +40
    -12
      src/webviews/commitDetails/commitDetailsWebviewView.ts

+ 9
- 2
src/commands/gitCommands.actions.ts View File

@ -14,7 +14,7 @@ import type { FileAnnotationType } from '../configuration';
import { Commands, CoreCommands } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import type { GitCommit } from '../git/models/commit';
import type { GitCommit, GitStashCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import type { GitContributor } from '../git/models/contributor';
import type { GitFile } from '../git/models/file';
@ -758,7 +758,7 @@ export namespace GitActions {
}
export function showDetailsView(
commit: GitCommit,
commit: GitRevisionReference | GitCommit,
options?: { pin?: boolean; preserveFocus?: boolean },
): Promise<void> {
return Container.instance.commitDetailsView.show({ ...options, commit: commit });
@ -921,6 +921,13 @@ export namespace GitActions {
: await Container.instance.repositoriesView.revealStash(stash, options);
return node;
}
export function showDetailsView(
stash: GitStashReference | GitStashCommit,
options?: { pin?: boolean; preserveFocus?: boolean },
): Promise<void> {
return Container.instance.commitDetailsView.show({ ...options, commit: stash });
}
}
export namespace Tag {

+ 40
- 12
src/webviews/commitDetails/commitDetailsWebviewView.ts View File

@ -5,10 +5,12 @@ import { configuration } from '../../configuration';
import { Commands } from '../../constants';
import type { Container } from '../../container';
import type { GitCommit } from '../../git/models/commit';
import { isCommit } from '../../git/models/commit';
import type { GitFileChange } from '../../git/models/file';
import { GitFile } from '../../git/models/file';
import type { IssueOrPullRequest } from '../../git/models/issue';
import type { PullRequest } from '../../git/models/pullRequest';
import type { GitRevisionReference } from '../../git/models/reference';
import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import { executeCommand } from '../../system/command';
import { debug } from '../../system/decorators/log';
@ -81,7 +83,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
}
override async show(options?: {
commit?: GitCommit;
commit?: GitRevisionReference | GitCommit;
pin?: boolean;
preserveFocus?: boolean | undefined;
}): Promise<void> {
@ -90,9 +92,17 @@ export class CommitDetailsWebviewView extends WebviewViewBase
let pin;
({ commit, pin, ...options } = options);
if (commit == null) {
commit = this.getBestCommit();
commit = this.getBestCommitOrStash();
}
if (commit != null) {
if (!isCommit(commit)) {
if (commit.refType === 'stash') {
const stash = await this.container.git.getStash(commit.repoPath);
commit = stash?.commits.get(commit.ref);
} else {
commit = await this.container.git.getCommit(commit.repoPath, commit.ref);
}
}
this.updateCommit(commit, { pinned: pin ?? true });
}
}
@ -111,7 +121,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
protected override onInitializing(): Disposable[] | undefined {
if (this._context.commit == null) {
const commit = this.getBestCommit();
const commit = this.getBestCommitOrStash();
if (commit != null) {
this.updateCommit(commit, { immediate: false });
}
@ -144,12 +154,13 @@ export class CommitDetailsWebviewView extends WebviewViewBase
const { lineTracker, commitsView, stashesView } = this.container;
this._visibilityDisposable = Disposable.from(
lineTracker.subscribe(this, lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this)),
commitsView.onDidChangeVisibility(this.onCommitsViewVisibilityChanged, this),
commitsView.onDidChangeSelection(this.onCommitsViewSelectionChanged, this),
commitsView.onDidChangeVisibility(this.onCommitsViewVisibilityChanged, this),
stashesView.onDidChangeSelection(this.onStashesViewSelectionChanged, this),
stashesView.onDidChangeVisibility(this.onStashesViewVisibilityChanged, this),
);
const commit = this.getBestCommit();
const commit = this.getBestCommitOrStash();
this.updateCommit(commit, { immediate: false });
}
@ -238,6 +249,18 @@ export class CommitDetailsWebviewView extends WebviewViewBase
}
}
private onCommitsViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
if (!e.visible) return;
const node = this.container.commitsView.activeSelection;
if (
node != null &&
(node instanceof CommitNode || node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode)
) {
this.updateCommit(node.commit);
}
}
private onStashesViewSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
const node = e.selection?.[0];
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
@ -245,14 +268,11 @@ export class CommitDetailsWebviewView extends WebviewViewBase
}
}
private onCommitsViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
private onStashesViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
if (!e.visible) return;
const node = this.container.commitsView.activeSelection;
if (
node != null &&
(node instanceof CommitNode || node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode)
) {
const node = this.container.stashesView.activeSelection;
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
this.updateCommit(node.commit);
}
}
@ -497,7 +517,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
// }
// }
private getBestCommit(): GitCommit | undefined {
private getBestCommitOrStash(): GitCommit | undefined {
if (this._pinned) return undefined;
let commit;
@ -521,6 +541,14 @@ export class CommitDetailsWebviewView extends WebviewViewBase
}
}
if (commit == null) {
const { stashesView } = this.container;
const node = stashesView.activeSelection;
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
commit = node.commit;
}
}
return commit;
}

Loading…
Cancel
Save