@@ -5,6 +5,7 @@ import { GlyphChars } from '../../constants';
55import type { ContextKeys } from '../../constants.context' ;
66import type { HomeTelemetryContext } from '../../constants.telemetry' ;
77import type { Container } from '../../container' ;
8+ import { executeGitCommand } from '../../git/actions' ;
89import type { BranchContributorOverview } from '../../git/gitProvider' ;
910import type { GitBranch } from '../../git/models/branch' ;
1011import { sortBranches } from '../../git/models/branch' ;
@@ -199,6 +200,26 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
199200
200201 registerCommands ( ) : Disposable [ ] {
201202 return [
203+ registerCommand (
204+ `${ this . host . id } .pull` ,
205+ ( ) => {
206+ void executeGitCommand ( {
207+ command : 'pull' ,
208+ state : { } ,
209+ } ) ;
210+ } ,
211+ this ,
212+ ) ,
213+ registerCommand (
214+ `${ this . host . id } .push` ,
215+ args => {
216+ void executeGitCommand ( {
217+ command : 'push' ,
218+ state : { flags : args . force ? [ '--force' ] : undefined } ,
219+ } ) ;
220+ } ,
221+ this ,
222+ ) ,
202223 registerCommand ( `${ this . host . id } .refresh` , ( ) => this . host . refresh ( true ) , this ) ,
203224 registerCommand (
204225 `${ this . host . id } .account.resync` ,
@@ -426,6 +447,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
426447 }
427448
428449 private onWipChanged ( _repo : Repository ) {
450+ this . _invalidateRepositoryBranches = true ;
429451 void this . host . notify ( DidChangeRepositoryWip , undefined ) ;
430452 }
431453
@@ -437,16 +459,21 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
437459 return this . _repositorySubscription ?. repo ;
438460 }
439461
440- private _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
441- private async getBranchesAndWorktrees ( repo : Repository , force = false ) {
462+ private _invalidateRepositoryBranches = true ;
463+ private readonly _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
464+ private async getBranchesAndWorktrees ( repo : Repository , force = this . _invalidateRepositoryBranches ) {
442465 if ( force || ! this . _repositoryBranches . has ( repo . path ) ) {
443- const [ branchesResult , worktreesResult ] = await Promise . allSettled ( [
444- repo . git . getBranches ( { filter : b => ! b . remote } ) ,
445- repo . git . getWorktrees ( ) ,
466+ const worktrees = ( await repo . git . getWorktrees ( ) ) ?? [ ] ;
467+ const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
468+ const [ branchesResult ] = await Promise . allSettled ( [
469+ repo . git . getBranches ( {
470+ filter : b => ! b . remote ,
471+ sort : { current : true , openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) } ,
472+ } ) ,
446473 ] ) ;
447474
448475 const branches = getSettledValue ( branchesResult ) ?. values ?? [ ] ;
449- const worktrees = getSettledValue ( worktreesResult ) ?? [ ] ;
476+ this . _invalidateRepositoryBranches = false ;
450477 this . _repositoryBranches . set ( repo . path , { branches : branches , worktrees : worktrees } ) ;
451478 }
452479
@@ -542,16 +569,11 @@ async function getOverviewBranches(
542569 container : Container ,
543570 options : OverviewFilters ,
544571) : Promise < GetOverviewBranches | undefined > {
572+ console . log ( 'try to getOverviewBranches' ) ;
545573 if ( branches . length === 0 ) return undefined ;
546574
547575 const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
548576
549- sortBranches ( branches , {
550- current : true ,
551- orderBy : 'date:desc' ,
552- openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) ,
553- } ) ;
554-
555577 const overviewBranches : GetOverviewBranches = {
556578 active : [ ] ,
557579 recent : [ ] ,
@@ -571,7 +593,7 @@ async function getOverviewBranches(
571593
572594 const timestamp = branch . date ?. getTime ( ) ;
573595 if ( branch . current || wt ?. opened ) {
574- prPromises . set ( branch . id , branch . getAssociatedPullRequest ( ) ) ;
596+ prPromises . set ( branch . id , branch . getAssociatedPullRequest ( { avatarSize : 16 } ) ) ;
575597 if ( wt != null ) {
576598 statusPromises . set ( branch . id , wt . getStatus ( ) ) ;
577599 }
@@ -678,15 +700,15 @@ async function getOverviewBranches(
678700 const prs = new Map (
679701 getSettledValue ( prResults )
680702 ?. filter ( r => r . status === 'fulfilled' )
681- . map ( r => [
682- r . value [ 0 ] ,
683- r . value [ 1 ]
684- ? {
685- id : r . value [ 1 ] . id ,
686- title : r . value [ 1 ] . title ,
687- state : r . value [ 1 ] . state ,
688- url : r . value [ 1 ] . url ,
689- }
703+ . map ( ( { value : [ prId , pr ] } ) => [
704+ prId ,
705+ pr
706+ ? ( {
707+ id : pr . id ,
708+ title : pr . title ,
709+ state : pr . state ,
710+ url : pr . url ,
711+ } satisfies GetOverviewBranch [ 'pr' ] )
690712 : undefined ,
691713 ] ) ,
692714 ) ;
0 commit comments