@@ -5,10 +5,12 @@ import { configuration } from '../../configuration';
55import { Commands } from '../../constants' ;
66import type { Container } from '../../container' ;
77import type { GitCommit } from '../../git/models/commit' ;
8+ import { isCommit } from '../../git/models/commit' ;
89import type { GitFileChange } from '../../git/models/file' ;
910import { GitFile } from '../../git/models/file' ;
1011import type { IssueOrPullRequest } from '../../git/models/issue' ;
1112import type { PullRequest } from '../../git/models/pullRequest' ;
13+ import type { GitRevisionReference } from '../../git/models/reference' ;
1214import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview' ;
1315import { executeCommand } from '../../system/command' ;
1416import { 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