@@ -1580,17 +1580,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
15801580 const path = yield * Path . Path ;
15811581 const fetchCwd =
15821582 path . basename ( gitCommonDir ) === ".git" ? path . dirname ( gitCommonDir ) : gitCommonDir ;
1583- return yield * executeGit (
1584- "GitVcsDriver.statusDetails.defaultBranch" ,
1585- fetchCwd ,
1586- [ "--git-dir" , gitCommonDir , "symbolic-ref" , "refs/remotes/origin/HEAD" ] ,
1587- { allowNonZeroExit : true } ,
1588- ) . pipe (
1589- Effect . map ( ( result ) => {
1590- if ( result . exitCode !== 0 ) return null ;
1591- return parseDefaultBranchFromRemoteHeadRef ( result . stdout , "origin" ) ;
1592- } ) ,
1593- ) ;
1583+ return yield * resolvePrimaryDefaultBranchName ( fetchCwd , [ "--git-dir" , gitCommonDir ] ) ;
15941584 } ) ,
15951585 {
15961586 capacity : 2_048 ,
@@ -1726,11 +1716,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17261716 const resolveDefaultBranchName = (
17271717 cwd : string ,
17281718 remoteName : string ,
1719+ gitDirArgs : ReadonlyArray < string > = [ ] ,
17291720 ) : Effect . Effect < string | null , GitCommandError > =>
17301721 executeGit (
17311722 "GitVcsDriver.resolveDefaultBranchName" ,
17321723 cwd ,
1733- [ "symbolic-ref" , `refs/remotes/${ remoteName } /HEAD` ] ,
1724+ [ ... gitDirArgs , "symbolic-ref" , `refs/remotes/${ remoteName } /HEAD` ] ,
17341725 { allowNonZeroExit : true } ,
17351726 ) . pipe (
17361727 Effect . map ( ( result ) => {
@@ -1764,8 +1755,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17641755 const originRemoteExists = ( cwd : string ) : Effect . Effect < boolean , GitCommandError > =>
17651756 remoteExists ( { cwd, remoteName : "origin" } ) ;
17661757
1767- const listRemoteNames = ( cwd : string ) : Effect . Effect < ReadonlyArray < string > , GitCommandError > =>
1768- runGitStdout ( "GitVcsDriver.listRemoteNames" , cwd , [ "remote" ] ) . pipe (
1758+ const listRemoteNames = (
1759+ cwd : string ,
1760+ gitDirArgs : ReadonlyArray < string > = [ ] ,
1761+ ) : Effect . Effect < ReadonlyArray < string > , GitCommandError > =>
1762+ runGitStdout ( "GitVcsDriver.listRemoteNames" , cwd , [ ...gitDirArgs , "remote" ] ) . pipe (
17691763 Effect . map ( parseRemoteNamesInGitOrder ) ,
17701764 ) ;
17711765
@@ -1788,6 +1782,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17881782 return firstRemote ?? null ;
17891783 } ) ;
17901784
1785+ const resolvePrimaryDefaultBranchName = Effect . fn ( "GitVcsDriver.resolvePrimaryDefaultBranchName" ) (
1786+ function * ( cwd : string , gitDirArgs : ReadonlyArray < string > = [ ] ) {
1787+ const originDefault = yield * resolveDefaultBranchName ( cwd , "origin" , gitDirArgs ) ;
1788+ if ( originDefault !== null ) return originDefault ;
1789+ const remoteNames = yield * listRemoteNames ( cwd , gitDirArgs ) ;
1790+ const [ firstRemote ] = remoteNames ;
1791+ return firstRemote === undefined || remoteNames . includes ( "origin" )
1792+ ? null
1793+ : yield * resolveDefaultBranchName ( cwd , firstRemote , gitDirArgs ) ;
1794+ } ,
1795+ ) ;
1796+
17911797 const resolvePrimaryRemoteName = ( cwd : string ) =>
17921798 findPrimaryRemoteName ( cwd ) . pipe (
17931799 Effect . filterOrFail (
@@ -2123,7 +2129,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21232129 ) ;
21242130 }
21252131
2126- const defaultBranch = yield * resolveDefaultBranchName ( cwd , "origin" ) ;
2132+ const defaultBranch = yield * resolvePrimaryDefaultBranchName ( cwd ) ;
21272133 const isDefaultBranch =
21282134 branch !== null &&
21292135 ( branch === defaultBranch ||
@@ -2269,7 +2275,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22692275 ) ,
22702276 statusCacheKey
22712277 ? Cache . get ( defaultBranchCache , statusCacheKey ) . pipe ( Effect . orElseSucceed ( ( ) => null ) )
2272- : resolveDefaultBranchName ( cwd , "origin" ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ,
2278+ : resolvePrimaryDefaultBranchName ( cwd ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ,
22732279 statusCacheKey
22742280 ? Cache . get ( primaryRemoteExistsCache , statusCacheKey ) . pipe (
22752281 Effect . orElseSucceed ( ( ) => false ) ,
0 commit comments