@@ -2091,7 +2091,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
20912091 return yield * lockError ;
20922092 }
20932093 }
2094- const statusResult = yield * executeGitWithStableDiagnostics (
2094+ const repositoryPaths = yield * resolveRepositoryPaths ( cwd ) . pipe (
2095+ Effect . catchTags ( { GitCommandError : ( ) => Effect . succeed ( null ) } ) ,
2096+ ) ;
2097+ const statusCacheKey = repositoryPaths ?. gitCommonDir ;
2098+ const readStatus = executeGitWithStableDiagnostics (
20952099 "GitVcsDriver.statusDetails.status" ,
20962100 cwd ,
20972101 statusArgs ,
@@ -2105,34 +2109,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21052109 isMissingGitCwdError ( error ) ? Effect . succeed ( null ) : Effect . fail ( error ) ,
21062110 } ) ,
21072111 ) ;
2108-
2109- if ( statusResult === null ) {
2110- return NON_REPOSITORY_STATUS_DETAILS ;
2111- }
2112-
2113- if ( statusResult . exitCode !== 0 ) {
2114- if ( isNonRepositoryGitStderr ( statusResult . stderr ) ) {
2115- return NON_REPOSITORY_STATUS_DETAILS ;
2116- }
2117- return yield * new GitCommandError ( {
2118- ...gitCommandContext ( {
2119- operation : "GitVcsDriver.statusDetails.status" ,
2120- cwd,
2121- args : statusArgs ,
2122- } ) ,
2123- detail : "Git status failed." ,
2124- exitCode : statusResult . exitCode ,
2125- stdoutLength : statusResult . stdout . length ,
2126- stderrLength : statusResult . stderr . length ,
2127- } ) ;
2128- }
2129-
2130- const repositoryPaths = yield * resolveRepositoryPaths ( cwd ) . pipe (
2131- Effect . catchTags ( { GitCommandError : ( ) => Effect . succeed ( null ) } ) ,
2132- ) ;
2133- const statusCacheKey = repositoryPaths ?. gitCommonDir ;
2134- const [ numstatEntries , defaultBranch , hasPrimaryRemote ] = yield * Effect . all (
2112+ // diff-index does not read status output, so both spawn together; a non-repository discards it.
2113+ const [ statusResult , numstatResult , defaultBranch , hasPrimaryRemote ] = yield * Effect . all (
21352114 [
2115+ readStatus ,
21362116 // Porcelain diff rewrites indexes despite GIT_OPTIONAL_LOCKS=0; plumbing with -M preserves rename detection.
21372117 executeGitWithStableDiagnostics (
21382118 "GitVcsDriver.statusDetails.numstat" ,
@@ -2178,6 +2158,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21782158 } ) ,
21792159 ) ;
21802160 } ) ,
2161+ Effect . result ,
21812162 ) ,
21822163 statusCacheKey
21832164 ? Cache . get ( defaultBranchCache , statusCacheKey ) . pipe ( Effect . orElseSucceed ( ( ) => null ) )
@@ -2188,6 +2169,28 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21882169 ] ,
21892170 { concurrency : "unbounded" } ,
21902171 ) ;
2172+ if ( statusResult === null ) {
2173+ return NON_REPOSITORY_STATUS_DETAILS ;
2174+ }
2175+
2176+ if ( statusResult . exitCode !== 0 ) {
2177+ if ( isNonRepositoryGitStderr ( statusResult . stderr ) ) {
2178+ return NON_REPOSITORY_STATUS_DETAILS ;
2179+ }
2180+ return yield * new GitCommandError ( {
2181+ ...gitCommandContext ( {
2182+ operation : "GitVcsDriver.statusDetails.status" ,
2183+ cwd,
2184+ args : statusArgs ,
2185+ } ) ,
2186+ detail : "Git status failed." ,
2187+ exitCode : statusResult . exitCode ,
2188+ stdoutLength : statusResult . stdout . length ,
2189+ stderrLength : statusResult . stderr . length ,
2190+ } ) ;
2191+ }
2192+
2193+ const numstatEntries = yield * Effect . fromResult ( numstatResult ) ;
21912194 const statusStdout = statusResult . stdout ;
21922195
21932196 let refName : string | null = null ;
@@ -2231,25 +2234,34 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22312234 }
22322235 }
22332236
2234- const fallbackAheadCount =
2235- includeDivergence && ! upstreamRef && refName
2236- ? yield * computeAheadCountAgainstBase ( cwd , refName ) . pipe ( Effect . orElseSucceed ( ( ) => 0 ) )
2237- : null ;
2238-
2239- if ( fallbackAheadCount !== null ) {
2240- aheadCount = fallbackAheadCount ;
2241- behindCount = 0 ;
2242- }
2243-
22442237 const isDefaultBranch =
22452238 refName !== null &&
22462239 ( refName === defaultBranch ||
22472240 ( defaultBranch === null && ( refName === "main" || refName === "master" ) ) ) ;
2248- if ( includeDivergence && refName && ! isDefaultBranch ) {
2249- aheadOfDefaultCount =
2250- fallbackAheadCount !== null
2251- ? fallbackAheadCount
2252- : yield * computeAheadCountAgainstBase ( cwd , refName ) . pipe ( Effect . orElseSucceed ( ( ) => 0 ) ) ;
2241+ const needsFallbackAhead = includeDivergence && ! upstreamRef && refName !== null ;
2242+ const needsAheadOfDefault = includeDivergence && refName !== null && ! isDefaultBranch ;
2243+ const [ baseAheadCount , branchChanges ] = yield * Effect . all (
2244+ [
2245+ refName !== null && ( needsFallbackAhead || needsAheadOfDefault )
2246+ ? computeAheadCountAgainstBase ( cwd , refName , {
2247+ knownOriginDefaultBranch : defaultBranch ,
2248+ } ) . pipe ( Effect . orElseSucceed ( ( ) => 0 ) )
2249+ : Effect . succeed ( 0 ) ,
2250+ options ?. includeBranchChanges
2251+ ? readBranchChangeTotals ( repositoryPaths ?. worktreeRoot ?? cwd , refName , {
2252+ knownOriginDefaultBranch : defaultBranch ,
2253+ } ) . pipe ( Effect . orElseSucceed ( ( ) => undefined ) )
2254+ : Effect . undefined ,
2255+ ] ,
2256+ { concurrency : "unbounded" } ,
2257+ ) ;
2258+
2259+ if ( needsFallbackAhead ) {
2260+ aheadCount = baseAheadCount ;
2261+ behindCount = 0 ;
2262+ }
2263+ if ( needsAheadOfDefault ) {
2264+ aheadOfDefaultCount = baseAheadCount ;
22532265 }
22542266
22552267 const fileStatMap = new Map < string , { insertions : number ; deletions : number } > ( ) ;
@@ -2276,12 +2288,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22762288 }
22772289 files . sort ( ( a , b ) => a . path . localeCompare ( b . path ) ) ;
22782290
2279- const branchChanges = options ?. includeBranchChanges
2280- ? yield * readBranchChangeTotals ( repositoryPaths ?. worktreeRoot ?? cwd , refName ) . pipe (
2281- Effect . orElseSucceed ( ( ) => undefined ) ,
2282- )
2283- : undefined ;
2284-
22852291 return {
22862292 isRepo : true ,
22872293 hasOriginRemote : hasPrimaryRemote ,
@@ -3014,6 +3020,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30143020 cwd : string ,
30153021 branch : string | null ,
30163022 explicitBaseRef ?: string ,
3023+ knownOriginDefaultBranch : string | null = null ,
30173024 ) {
30183025 const base =
30193026 explicitBaseRef !== undefined
@@ -3025,9 +3032,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30253032 : explicitBaseRef ,
30263033 } )
30273034 : branch
3028- ? yield * resolveBaseBranchForNoUpstream ( cwd , branch , { allowRemoteOfCurrent : true } ) . pipe (
3029- Effect . orElseSucceed ( ( ) => null ) ,
3030- )
3035+ ? yield * resolveBaseBranchForNoUpstream ( cwd , branch , {
3036+ allowRemoteOfCurrent : true ,
3037+ knownOriginDefaultBranch,
3038+ } ) . pipe ( Effect . orElseSucceed ( ( ) => null ) )
30313039 : null ;
30323040 if ( base === null ) return { baseRef : null , mergeBase : "HEAD" } ;
30333041 const { baseRef, comparisonRef } = base ;
@@ -3058,8 +3066,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30583066 const readBranchChangeTotals = Effect . fn ( "readBranchChangeTotals" ) ( function * (
30593067 cwd : string ,
30603068 branch : string | null ,
3069+ options ?: { readonly knownOriginDefaultBranch : string | null } ,
30613070 ) {
3062- const { baseRef, mergeBase } = yield * resolveReviewMergeBase ( cwd , branch ) ;
3071+ const { baseRef, mergeBase } = yield * resolveReviewMergeBase (
3072+ cwd ,
3073+ branch ,
3074+ undefined ,
3075+ options ?. knownOriginDefaultBranch ?? null ,
3076+ ) ;
30633077 const untracked = yield * prepareUntrackedReviewIndex ( cwd , [ ] ) ;
30643078 if ( untracked === null ) {
30653079 return yield * new GitCommandError ( {
0 commit comments