@@ -4,6 +4,7 @@ import { getAvatarUriFromGravatarEmail } from '../../avatars';
44import type { ContextKeys } from '../../constants.context' ;
55import type { WebviewTelemetryContext } from '../../constants.telemetry' ;
66import type { Container } from '../../container' ;
7+ import { executeGitCommand } from '../../git/actions' ;
78import type { BranchContributorOverview } from '../../git/gitProvider' ;
89import type { GitBranch } from '../../git/models/branch' ;
910import { sortBranches } from '../../git/models/branch' ;
@@ -179,6 +180,26 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
179180
180181 registerCommands ( ) : Disposable [ ] {
181182 return [
183+ registerCommand (
184+ `${ this . host . id } .pull` ,
185+ ( ) => {
186+ void executeGitCommand ( {
187+ command : 'pull' ,
188+ state : { } ,
189+ } ) ;
190+ } ,
191+ this ,
192+ ) ,
193+ registerCommand (
194+ `${ this . host . id } .push` ,
195+ args => {
196+ void executeGitCommand ( {
197+ command : 'push' ,
198+ state : { flags : args . force ? [ '--force' ] : undefined } ,
199+ } ) ;
200+ } ,
201+ this ,
202+ ) ,
182203 registerCommand ( `${ this . host . id } .refresh` , ( ) => this . host . refresh ( true ) , this ) ,
183204 registerCommand (
184205 `${ this . host . id } .account.resync` ,
@@ -420,6 +441,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
420441 }
421442
422443 private onWipChanged ( _repo : Repository ) {
444+ this . _invalidateRepositoryBranches = true ;
423445 void this . host . notify ( DidChangeRepositoryWip , undefined ) ;
424446 }
425447
@@ -431,16 +453,21 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
431453 return this . _repositorySubscription ?. repo ;
432454 }
433455
434- private _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
435- private async getBranchesAndWorktrees ( repo : Repository , force = false ) {
456+ private _invalidateRepositoryBranches = true ;
457+ private readonly _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
458+ private async getBranchesAndWorktrees ( repo : Repository , force = this . _invalidateRepositoryBranches ) {
436459 if ( force || ! this . _repositoryBranches . has ( repo . path ) ) {
437- const [ branchesResult , worktreesResult ] = await Promise . allSettled ( [
438- repo . git . getBranches ( { filter : b => ! b . remote } ) ,
439- repo . git . getWorktrees ( ) ,
460+ const worktrees = ( await repo . git . getWorktrees ( ) ) ?? [ ] ;
461+ const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
462+ const [ branchesResult ] = await Promise . allSettled ( [
463+ repo . git . getBranches ( {
464+ filter : b => ! b . remote ,
465+ sort : { current : true , openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) } ,
466+ } ) ,
440467 ] ) ;
441468
442469 const branches = getSettledValue ( branchesResult ) ?. values ?? [ ] ;
443- const worktrees = getSettledValue ( worktreesResult ) ?? [ ] ;
470+ this . _invalidateRepositoryBranches = false ;
444471 this . _repositoryBranches . set ( repo . path , { branches : branches , worktrees : worktrees } ) ;
445472 }
446473
@@ -537,16 +564,11 @@ async function getOverviewBranches(
537564 container : Container ,
538565 options : OverviewFilters ,
539566) : Promise < GetOverviewBranches | undefined > {
567+ console . log ( 'try to getOverviewBranches' ) ;
540568 if ( branches . length === 0 ) return undefined ;
541569
542570 const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
543571
544- sortBranches ( branches , {
545- current : true ,
546- orderBy : 'date:desc' ,
547- openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) ,
548- } ) ;
549-
550572 const overviewBranches : GetOverviewBranches = {
551573 active : [ ] ,
552574 recent : [ ] ,
@@ -566,7 +588,7 @@ async function getOverviewBranches(
566588
567589 const timestamp = branch . date ?. getTime ( ) ;
568590 if ( branch . current || wt ?. opened ) {
569- prPromises . set ( branch . id , branch . getAssociatedPullRequest ( ) ) ;
591+ prPromises . set ( branch . id , branch . getAssociatedPullRequest ( { avatarSize : 16 } ) ) ;
570592 if ( wt != null ) {
571593 statusPromises . set ( branch . id , wt . getStatus ( ) ) ;
572594 }
@@ -673,15 +695,15 @@ async function getOverviewBranches(
673695 const prs = new Map (
674696 getSettledValue ( prResults )
675697 ?. filter ( r => r . status === 'fulfilled' )
676- . map ( r => [
677- r . value [ 0 ] ,
678- r . value [ 1 ]
679- ? {
680- id : r . value [ 1 ] . id ,
681- title : r . value [ 1 ] . title ,
682- state : r . value [ 1 ] . state ,
683- url : r . value [ 1 ] . url ,
684- }
698+ . map ( ( { value : [ prId , pr ] } ) => [
699+ prId ,
700+ pr
701+ ? ( {
702+ id : pr . id ,
703+ title : pr . title ,
704+ state : pr . state ,
705+ url : pr . url ,
706+ } satisfies GetOverviewBranch [ 'pr' ] )
685707 : undefined ,
686708 ] ) ,
687709 ) ;
0 commit comments