@@ -38,6 +38,7 @@ export type GitBranchStatus =
3838
3939export interface BranchSortOptions {
4040 current ?: boolean ;
41+ groupByType ?: boolean ;
4142 missingUpstream ?: boolean ;
4243 orderBy ?: BranchSorting ;
4344 openedWorktreesByBranch ?: Set < string > ;
@@ -311,7 +312,7 @@ export function isOfBranchRefType(branch: GitReference | undefined) {
311312}
312313
313314export function sortBranches ( branches : GitBranch [ ] , options ?: BranchSortOptions ) {
314- options = { current : true , orderBy : configuration . get ( 'sortBranchesBy' ) , ...options } ;
315+ options = { current : true , groupByType : true , orderBy : configuration . get ( 'sortBranchesBy' ) , ...options } ;
315316
316317 switch ( options . orderBy ) {
317318 case 'date:asc' :
@@ -324,7 +325,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
324325 ( options . openedWorktreesByBranch . has ( b . id ) ? - 1 : 1 )
325326 : 0 ) ||
326327 ( a . starred ? - 1 : 1 ) - ( b . starred ? - 1 : 1 ) ||
327- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
328+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
328329 ( a . date == null ? - 1 : a . date . getTime ( ) ) - ( b . date == null ? - 1 : b . date . getTime ( ) ) ||
329330 sortCompare ( a . name , b . name ) ,
330331 ) ;
@@ -341,7 +342,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
341342 ( a . name === 'main' ? - 1 : 1 ) - ( b . name === 'main' ? - 1 : 1 ) ||
342343 ( a . name === 'master' ? - 1 : 1 ) - ( b . name === 'master' ? - 1 : 1 ) ||
343344 ( a . name === 'develop' ? - 1 : 1 ) - ( b . name === 'develop' ? - 1 : 1 ) ||
344- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
345+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
345346 sortCompare ( a . name , b . name ) ,
346347 ) ;
347348 case 'name:desc' :
@@ -357,7 +358,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
357358 ( a . name === 'main' ? - 1 : 1 ) - ( b . name === 'main' ? - 1 : 1 ) ||
358359 ( a . name === 'master' ? - 1 : 1 ) - ( b . name === 'master' ? - 1 : 1 ) ||
359360 ( a . name === 'develop' ? - 1 : 1 ) - ( b . name === 'develop' ? - 1 : 1 ) ||
360- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
361+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
361362 sortCompare ( b . name , a . name ) ,
362363 ) ;
363364 case 'date:desc' :
@@ -371,7 +372,7 @@ export function sortBranches(branches: GitBranch[], options?: BranchSortOptions)
371372 ( options . openedWorktreesByBranch . has ( b . id ) ? - 1 : 1 )
372373 : 0 ) ||
373374 ( a . starred ? - 1 : 1 ) - ( b . starred ? - 1 : 1 ) ||
374- ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) ||
375+ ( options . groupByType ? ( b . remote ? - 1 : 1 ) - ( a . remote ? - 1 : 1 ) : 0 ) ||
375376 ( b . date == null ? - 1 : b . date . getTime ( ) ) - ( a . date == null ? - 1 : a . date . getTime ( ) ) ||
376377 sortCompare ( b . name , a . name ) ,
377378 ) ;
@@ -414,3 +415,15 @@ export async function getLocalBranchByUpstream(
414415
415416 return undefined ;
416417}
418+
419+ export async function getLocalBranchUpstreamNames ( branches : PageableResult < GitBranch > ) : Promise < Set < string > > {
420+ const remoteBranches = new Set < string > ( ) ;
421+
422+ for await ( const branch of branches . values ( ) ) {
423+ if ( ! branch . remote && branch . upstream ?. name != null ) {
424+ remoteBranches . add ( branch . upstream . name ) ;
425+ }
426+ }
427+
428+ return remoteBranches ;
429+ }
0 commit comments