@@ -17,8 +17,9 @@ import { getBestPath } from '../../system/-webview/path';
1717import { gate } from '../../system/decorators/-webview/gate' ;
1818import { debug } from '../../system/decorators/log' ;
1919import { map } from '../../system/iterable' ;
20+ import { Logger } from '../../system/logger' ;
2021import type { Deferred } from '../../system/promise' ;
21- import { defer , getSettledValue } from '../../system/promise' ;
22+ import { defer , getSettledValue , pauseOnCancelOrTimeout } from '../../system/promise' ;
2223import { pad } from '../../system/string' ;
2324import type { ViewsWithWorktrees } from '../viewBase' ;
2425import { createViewDecorationUri } from '../viewDecorationProvider' ;
@@ -48,7 +49,6 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
4849 view : ViewsWithWorktrees ,
4950 public override parent : ViewNode ,
5051 public readonly worktree : GitWorktree ,
51- private readonly worktreeStatus : { status : GitStatus | undefined ; missing : boolean } | undefined ,
5252 ) {
5353 super ( 'worktree' , uri , view , parent ) ;
5454
@@ -194,8 +194,9 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
194194 children . push ( new LoadMoreNode ( this . view , this , children [ children . length - 1 ] ) ) ;
195195 }
196196
197- if ( this . worktreeStatus ?. status ?. hasChanges ) {
198- children . unshift ( new UncommittedFilesNode ( this . view , this , this . worktreeStatus . status , undefined ) ) ;
197+ const { status } = await this . getStatus ( ) ;
198+ if ( status ?. hasChanges ) {
199+ children . unshift ( new UncommittedFilesNode ( this . view , this , status , undefined ) ) ;
199200 }
200201
201202 this . children = children ;
@@ -224,7 +225,19 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
224225 } )`
225226 : '' ;
226227
227- const status = this . worktreeStatus ?. status ;
228+ let status : GitStatus | undefined ;
229+ let missing = false ;
230+
231+ const result = await pauseOnCancelOrTimeout ( this . getStatus ( ) , undefined , 1 ) ;
232+ if ( ! result . paused ) {
233+ ( { status, missing } = result . value ) ;
234+ } else {
235+ queueMicrotask ( ( ) => {
236+ void result . value . then ( ( ) => {
237+ this . view . triggerNodeChange ( this ) ;
238+ } ) ;
239+ } ) ;
240+ }
228241
229242 const folder = `\\\n$(folder) [\`${
230243 this . worktree . friendlyPath
@@ -368,7 +381,6 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
368381 tooltip . appendMarkdown ( `\n\n$(loading~spin) Loading associated pull request${ GlyphChars . Ellipsis } ` ) ;
369382 }
370383
371- const missing = this . worktreeStatus ?. missing ?? false ;
372384 if ( missing ) {
373385 tooltip . appendMarkdown ( `\n\n${ GlyphChars . Warning } Unable to locate worktree path` ) ;
374386 }
@@ -456,6 +468,21 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
456468 return this . _log ;
457469 }
458470
471+ private _status : { status : GitStatus | undefined ; missing : boolean } | undefined ;
472+ private async getStatus ( ) {
473+ if ( this . _status == null ) {
474+ try {
475+ const status = await this . worktree . getStatus ( ) ;
476+ this . _status = { status : status , missing : false } ;
477+ } catch ( ex ) {
478+ Logger . error ( ex , `Worktree status failed: ${ this . worktree . uri . toString ( true ) } ` ) ;
479+ this . _status = { status : undefined , missing : true } ;
480+ }
481+ }
482+
483+ return this . _status ;
484+ }
485+
459486 get hasMore ( ) : boolean {
460487 return this . _log ?. hasMore ?? true ;
461488 }
0 commit comments