@@ -5,10 +5,12 @@ import { configuration } from '../../configuration';
5
5
import { Commands } from '../../constants' ;
6
6
import type { Container } from '../../container' ;
7
7
import type { GitCommit } from '../../git/models/commit' ;
8
+ import { isCommit } from '../../git/models/commit' ;
8
9
import type { GitFileChange } from '../../git/models/file' ;
9
10
import { GitFile } from '../../git/models/file' ;
10
11
import type { IssueOrPullRequest } from '../../git/models/issue' ;
11
12
import type { PullRequest } from '../../git/models/pullRequest' ;
13
+ import type { GitRevisionReference } from '../../git/models/reference' ;
12
14
import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview' ;
13
15
import { executeCommand } from '../../system/command' ;
14
16
import { debug } from '../../system/decorators/log' ;
@@ -81,7 +83,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
81
83
}
82
84
83
85
override async show ( options ?: {
84
- commit ?: GitCommit ;
86
+ commit ?: GitRevisionReference | GitCommit ;
85
87
pin ?: boolean ;
86
88
preserveFocus ?: boolean | undefined ;
87
89
} ) : Promise < void > {
@@ -90,9 +92,17 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
90
92
let pin ;
91
93
( { commit, pin, ...options } = options ) ;
92
94
if ( commit == null ) {
93
- commit = this . getBestCommit ( ) ;
95
+ commit = this . getBestCommitOrStash ( ) ;
94
96
}
95
97
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
+ }
96
106
this . updateCommit ( commit , { pinned : pin ?? true } ) ;
97
107
}
98
108
}
@@ -111,7 +121,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
111
121
112
122
protected override onInitializing ( ) : Disposable [ ] | undefined {
113
123
if ( this . _context . commit == null ) {
114
- const commit = this . getBestCommit ( ) ;
124
+ const commit = this . getBestCommitOrStash ( ) ;
115
125
if ( commit != null ) {
116
126
this . updateCommit ( commit , { immediate : false } ) ;
117
127
}
@@ -144,12 +154,13 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
144
154
const { lineTracker, commitsView, stashesView } = this . container ;
145
155
this . _visibilityDisposable = Disposable . from (
146
156
lineTracker . subscribe ( this , lineTracker . onDidChangeActiveLines ( this . onActiveLinesChanged , this ) ) ,
147
- commitsView . onDidChangeVisibility ( this . onCommitsViewVisibilityChanged , this ) ,
148
157
commitsView . onDidChangeSelection ( this . onCommitsViewSelectionChanged , this ) ,
158
+ commitsView . onDidChangeVisibility ( this . onCommitsViewVisibilityChanged , this ) ,
149
159
stashesView . onDidChangeSelection ( this . onStashesViewSelectionChanged , this ) ,
160
+ stashesView . onDidChangeVisibility ( this . onStashesViewVisibilityChanged , this ) ,
150
161
) ;
151
162
152
- const commit = this . getBestCommit ( ) ;
163
+ const commit = this . getBestCommitOrStash ( ) ;
153
164
this . updateCommit ( commit , { immediate : false } ) ;
154
165
}
155
166
@@ -238,21 +249,30 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
238
249
}
239
250
}
240
251
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
+
241
264
private onStashesViewSelectionChanged ( e : TreeViewSelectionChangeEvent < ViewNode > ) {
242
265
const node = e . selection ?. [ 0 ] ;
243
266
if ( node != null && ( node instanceof StashNode || node instanceof StashFileNode ) ) {
244
267
this . updateCommit ( node . commit ) ;
245
268
}
246
269
}
247
270
248
- private onCommitsViewVisibilityChanged ( e : TreeViewVisibilityChangeEvent ) {
271
+ private onStashesViewVisibilityChanged ( e : TreeViewVisibilityChangeEvent ) {
249
272
if ( ! e . visible ) return ;
250
273
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 ) ) {
256
276
this . updateCommit ( node . commit ) ;
257
277
}
258
278
}
@@ -497,7 +517,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
497
517
// }
498
518
// }
499
519
500
- private getBestCommit ( ) : GitCommit | undefined {
520
+ private getBestCommitOrStash ( ) : GitCommit | undefined {
501
521
if ( this . _pinned ) return undefined ;
502
522
503
523
let commit ;
@@ -521,6 +541,14 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
521
541
}
522
542
}
523
543
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
+
524
552
return commit ;
525
553
}
526
554
0 commit comments