@@ -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' ;
@@ -146,7 +147,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
146147 this . notifyDidChangeOnboardingIntegration ( ) ;
147148 }
148149
149- private async shouldNotifyRespositoryChange ( ) : Promise < boolean > {
150+ private async shouldNotifyRepositoryChange ( ) : Promise < boolean > {
150151 if ( this . _etag === this . container . git . etag ) {
151152 return false ;
152153 }
@@ -181,7 +182,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
181182 }
182183
183184 private async onRepositoriesChanged ( ) {
184- if ( ! ( await this . shouldNotifyRespositoryChange ( ) ) ) {
185+ if ( ! ( await this . shouldNotifyRepositoryChange ( ) ) ) {
185186 return ;
186187 }
187188 this . notifyDidChangeRepositories ( ) ;
@@ -197,8 +198,39 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
197198 }
198199 }
199200
201+ private async push ( force = false ) {
202+ const repo = this . getSelectedRepository ( ) ;
203+ if ( repo ) {
204+ return executeGitCommand ( {
205+ command : 'push' ,
206+ state : { repos : [ repo ] , flags : force ? [ '--force' ] : undefined } ,
207+ } ) ;
208+ }
209+ return Promise . resolve ( ) ;
210+ }
211+
212+ private async pull ( ) {
213+ const repo = this . getSelectedRepository ( ) ;
214+ if ( repo ) {
215+ return executeGitCommand ( {
216+ command : 'pull' ,
217+ state : { repos : [ repo ] } ,
218+ } ) ;
219+ }
220+ return Promise . resolve ( ) ;
221+ }
222+
200223 registerCommands ( ) : Disposable [ ] {
201224 return [
225+ registerCommand ( `${ this . host . id } .pull` , this . pull , this ) ,
226+ registerCommand (
227+ `${ this . host . id } .push` ,
228+ args => {
229+ void this . push ( args . force ) ;
230+ } ,
231+ this ,
232+ ) ,
233+ registerCommand ( `${ this . host . id } .publishBranch` , this . push , this ) ,
202234 registerCommand ( `${ this . host . id } .refresh` , ( ) => this . host . refresh ( true ) , this ) ,
203235 registerCommand (
204236 `${ this . host . id } .account.resync` ,
@@ -426,6 +458,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
426458 }
427459
428460 private onWipChanged ( _repo : Repository ) {
461+ this . _invalidateRepositoryBranches = true ;
429462 void this . host . notify ( DidChangeRepositoryWip , undefined ) ;
430463 }
431464
@@ -437,16 +470,21 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
437470 return this . _repositorySubscription ?. repo ;
438471 }
439472
440- private _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
441- private async getBranchesAndWorktrees ( repo : Repository , force = false ) {
473+ private _invalidateRepositoryBranches = true ;
474+ private readonly _repositoryBranches : Map < string , { branches : GitBranch [ ] ; worktrees : GitWorktree [ ] } > = new Map ( ) ;
475+ private async getBranchesAndWorktrees ( repo : Repository , force = this . _invalidateRepositoryBranches ) {
442476 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 ( ) ,
477+ const worktrees = ( await repo . git . getWorktrees ( ) ) ?? [ ] ;
478+ const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
479+ const [ branchesResult ] = await Promise . allSettled ( [
480+ repo . git . getBranches ( {
481+ filter : b => ! b . remote ,
482+ sort : { current : true , openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) } ,
483+ } ) ,
446484 ] ) ;
447485
448486 const branches = getSettledValue ( branchesResult ) ?. values ?? [ ] ;
449- const worktrees = getSettledValue ( worktreesResult ) ?? [ ] ;
487+ this . _invalidateRepositoryBranches = false ;
450488 this . _repositoryBranches . set ( repo . path , { branches : branches , worktrees : worktrees } ) ;
451489 }
452490
@@ -542,16 +580,11 @@ async function getOverviewBranches(
542580 container : Container ,
543581 options : OverviewFilters ,
544582) : Promise < GetOverviewBranches | undefined > {
583+ console . log ( 'try to getOverviewBranches' ) ;
545584 if ( branches . length === 0 ) return undefined ;
546585
547586 const worktreesByBranch = groupWorktreesByBranch ( worktrees ) ;
548587
549- sortBranches ( branches , {
550- current : true ,
551- orderBy : 'date:desc' ,
552- openedWorktreesByBranch : getOpenedWorktreesByBranch ( worktreesByBranch ) ,
553- } ) ;
554-
555588 const overviewBranches : GetOverviewBranches = {
556589 active : [ ] ,
557590 recent : [ ] ,
@@ -571,7 +604,7 @@ async function getOverviewBranches(
571604
572605 const timestamp = branch . date ?. getTime ( ) ;
573606 if ( branch . current || wt ?. opened ) {
574- prPromises . set ( branch . id , branch . getAssociatedPullRequest ( ) ) ;
607+ prPromises . set ( branch . id , branch . getAssociatedPullRequest ( { avatarSize : 16 } ) ) ;
575608 if ( wt != null ) {
576609 statusPromises . set ( branch . id , wt . getStatus ( ) ) ;
577610 }
@@ -678,15 +711,15 @@ async function getOverviewBranches(
678711 const prs = new Map (
679712 getSettledValue ( prResults )
680713 ?. 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- }
714+ . map ( ( { value : [ prId , pr ] } ) => [
715+ prId ,
716+ pr
717+ ? ( {
718+ id : pr . id ,
719+ title : pr . title ,
720+ state : pr . state ,
721+ url : pr . url ,
722+ } satisfies GetOverviewBranch [ 'pr' ] )
690723 : undefined ,
691724 ] ) ,
692725 ) ;
0 commit comments