Skip to content

Commit 54f5619

Browse files
committed
Adds correct stash lookup for Commit Details view
Adds visibility check for stashes view following
1 parent dfa0631 commit 54f5619

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

src/commands/gitCommands.actions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { FileAnnotationType } from '../configuration';
1414
import { Commands, CoreCommands } from '../constants';
1515
import { Container } from '../container';
1616
import { GitUri } from '../git/gitUri';
17-
import type { GitCommit } from '../git/models/commit';
17+
import type { GitCommit, GitStashCommit } from '../git/models/commit';
1818
import { isCommit } from '../git/models/commit';
1919
import type { GitContributor } from '../git/models/contributor';
2020
import type { GitFile } from '../git/models/file';
@@ -758,7 +758,7 @@ export namespace GitActions {
758758
}
759759

760760
export function showDetailsView(
761-
commit: GitCommit,
761+
commit: GitRevisionReference | GitCommit,
762762
options?: { pin?: boolean; preserveFocus?: boolean },
763763
): Promise<void> {
764764
return Container.instance.commitDetailsView.show({ ...options, commit: commit });
@@ -921,6 +921,13 @@ export namespace GitActions {
921921
: await Container.instance.repositoriesView.revealStash(stash, options);
922922
return node;
923923
}
924+
925+
export function showDetailsView(
926+
stash: GitStashReference | GitStashCommit,
927+
options?: { pin?: boolean; preserveFocus?: boolean },
928+
): Promise<void> {
929+
return Container.instance.commitDetailsView.show({ ...options, commit: stash });
930+
}
924931
}
925932

926933
export namespace Tag {

src/webviews/commitDetails/commitDetailsWebviewView.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { configuration } from '../../configuration';
55
import { Commands } from '../../constants';
66
import type { Container } from '../../container';
77
import type { GitCommit } from '../../git/models/commit';
8+
import { isCommit } from '../../git/models/commit';
89
import type { GitFileChange } from '../../git/models/file';
910
import { GitFile } from '../../git/models/file';
1011
import type { IssueOrPullRequest } from '../../git/models/issue';
1112
import type { PullRequest } from '../../git/models/pullRequest';
13+
import type { GitRevisionReference } from '../../git/models/reference';
1214
import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
1315
import { executeCommand } from '../../system/command';
1416
import { debug } from '../../system/decorators/log';
@@ -81,7 +83,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
8183
}
8284

8385
override async show(options?: {
84-
commit?: GitCommit;
86+
commit?: GitRevisionReference | GitCommit;
8587
pin?: boolean;
8688
preserveFocus?: boolean | undefined;
8789
}): Promise<void> {
@@ -90,9 +92,17 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
9092
let pin;
9193
({ commit, pin, ...options } = options);
9294
if (commit == null) {
93-
commit = this.getBestCommit();
95+
commit = this.getBestCommitOrStash();
9496
}
9597
if (commit != null) {
98+
if (!isCommit(commit)) {
99+
if (commit.refType === 'stash') {
100+
const stash = await this.container.git.getStash(commit.repoPath);
101+
commit = stash?.commits.get(commit.ref);
102+
} else {
103+
commit = await this.container.git.getCommit(commit.repoPath, commit.ref);
104+
}
105+
}
96106
this.updateCommit(commit, { pinned: pin ?? true });
97107
}
98108
}
@@ -111,7 +121,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
111121

112122
protected override onInitializing(): Disposable[] | undefined {
113123
if (this._context.commit == null) {
114-
const commit = this.getBestCommit();
124+
const commit = this.getBestCommitOrStash();
115125
if (commit != null) {
116126
this.updateCommit(commit, { immediate: false });
117127
}
@@ -144,12 +154,13 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
144154
const { lineTracker, commitsView, stashesView } = this.container;
145155
this._visibilityDisposable = Disposable.from(
146156
lineTracker.subscribe(this, lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this)),
147-
commitsView.onDidChangeVisibility(this.onCommitsViewVisibilityChanged, this),
148157
commitsView.onDidChangeSelection(this.onCommitsViewSelectionChanged, this),
158+
commitsView.onDidChangeVisibility(this.onCommitsViewVisibilityChanged, this),
149159
stashesView.onDidChangeSelection(this.onStashesViewSelectionChanged, this),
160+
stashesView.onDidChangeVisibility(this.onStashesViewVisibilityChanged, this),
150161
);
151162

152-
const commit = this.getBestCommit();
163+
const commit = this.getBestCommitOrStash();
153164
this.updateCommit(commit, { immediate: false });
154165
}
155166

@@ -238,21 +249,30 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
238249
}
239250
}
240251

252+
private onCommitsViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
253+
if (!e.visible) return;
254+
255+
const node = this.container.commitsView.activeSelection;
256+
if (
257+
node != null &&
258+
(node instanceof CommitNode || node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode)
259+
) {
260+
this.updateCommit(node.commit);
261+
}
262+
}
263+
241264
private onStashesViewSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
242265
const node = e.selection?.[0];
243266
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
244267
this.updateCommit(node.commit);
245268
}
246269
}
247270

248-
private onCommitsViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
271+
private onStashesViewVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
249272
if (!e.visible) return;
250273

251-
const node = this.container.commitsView.activeSelection;
252-
if (
253-
node != null &&
254-
(node instanceof CommitNode || node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode)
255-
) {
274+
const node = this.container.stashesView.activeSelection;
275+
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
256276
this.updateCommit(node.commit);
257277
}
258278
}
@@ -497,7 +517,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
497517
// }
498518
// }
499519

500-
private getBestCommit(): GitCommit | undefined {
520+
private getBestCommitOrStash(): GitCommit | undefined {
501521
if (this._pinned) return undefined;
502522

503523
let commit;
@@ -521,6 +541,14 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
521541
}
522542
}
523543

544+
if (commit == null) {
545+
const { stashesView } = this.container;
546+
const node = stashesView.activeSelection;
547+
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
548+
commit = node.commit;
549+
}
550+
}
551+
524552
return commit;
525553
}
526554

0 commit comments

Comments
 (0)