@@ -37,6 +37,7 @@ export type GitBranchStatus =
3737
3838export interface BranchSortOptions {
3939 current ?: boolean ;
40+ groupByType ?: boolean ;
4041 missingUpstream ?: boolean ;
4142 orderBy ?: BranchSorting ;
4243 openedWorktreesByBranch ?: Set < string > ;
@@ -303,7 +304,7 @@ export function isOfBranchRefType(branch: GitReference | undefined) {
303304}
304305
305306export function sortBranches ( branches : GitBranch [ ] , options ?: BranchSortOptions ) {
306- options = { current : true , orderBy : configuration . get ( 'sortBranchesBy' ) , ...options } ;
307+ options = { current : true , groupByType : true , orderBy : configuration . get ( 'sortBranchesBy' ) , ...options } ;
307308
308309 switch ( options . orderBy ) {
309310 case 'date:asc' :
@@ -316,7 +317,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
316317 ( options . openedWorktreesByBranch . has ( b . id ) ? - 1 : 1 )
317318 : 0 ) ||
318319 ( a . starred ? - 1 : 1 ) - ( b . starred ? - 1 : 1 ) ||
319- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
320+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
320321 ( a . date == null ? - 1 : a . date . getTime ( ) ) - ( b . date == null ? - 1 : b . date . getTime ( ) ) ||
321322 sortCompare ( a . name , b . name ) ,
322323 ) ;
@@ -333,7 +334,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
333334 ( a . name === 'main' ? - 1 : 1 ) - ( b . name === 'main' ? - 1 : 1 ) ||
334335 ( a . name === 'master' ? - 1 : 1 ) - ( b . name === 'master' ? - 1 : 1 ) ||
335336 ( a . name === 'develop' ? - 1 : 1 ) - ( b . name === 'develop' ? - 1 : 1 ) ||
336- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
337+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
337338 sortCompare ( a . name , b . name ) ,
338339 ) ;
339340 case 'name:desc' :
@@ -349,7 +350,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
349350 ( a . name === 'main' ? - 1 : 1 ) - ( b . name === 'main' ? - 1 : 1 ) ||
350351 ( a . name === 'master' ? - 1 : 1 ) - ( b . name === 'master' ? - 1 : 1 ) ||
351352 ( a . name === 'develop' ? - 1 : 1 ) - ( b . name === 'develop' ? - 1 : 1 ) ||
352- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
353+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
353354 sortCompare ( b . name , a . name ) ,
354355 ) ;
355356 case 'date:desc' :
@@ -363,7 +364,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
363364 ( options . openedWorktreesByBranch . has ( b . id ) ? - 1 : 1 )
364365 : 0 ) ||
365366 ( a . starred ? - 1 : 1 ) - ( b . starred ? - 1 : 1 ) ||
366- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
367+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
367368 ( b . date == null ? - 1 : b . date . getTime ( ) ) - ( a . date == null ? - 1 : a . date . getTime ( ) ) ||
368369 sortCompare ( b . name , a . name ) ,
369370 ) ;
@@ -406,3 +407,15 @@ export async function getLocalBranchByUpstream(
406407
407408 return undefined ;
408409}
410+
411+ export async function getLocalBranchUpstreamNames ( branches : PageableResult < GitBranch > ) : Promise < Set < string > > {
412+ const remoteBranches = new Set < string > ( ) ;
413+
414+ for await ( const branch of branches . values ( ) ) {
415+ if ( ! branch . remote && branch . upstream ?. name != null ) {
416+ remoteBranches . add ( branch . upstream . name ) ;
417+ }
418+ }
419+
420+ return remoteBranches ;
421+ }
0 commit comments