@@ -1050,13 +1050,13 @@ export const make = Effect.gen(function* () {
10501050 ...( remoteName . length > 0 ? { remoteName } : { } ) ,
10511051 } ;
10521052 return Effect . gen ( function * ( ) {
1053- const { headContext, lookup } = yield * resolveLookupHeadContext ( cwd , details ) ;
1054- if ( ! lookup ) {
1055- return {
1056- outcome : { _tag : "Complete" , latest : null } satisfies PrLookupOutcome ,
1057- headContext,
1058- } ;
1059- }
1053+ const { headContext, lookup } = yield * resolveLookupHeadContext ( cwd , details ) ;
1054+ if ( ! lookup ) {
1055+ return {
1056+ outcome : { _tag : "Complete" , latest : null } satisfies PrLookupOutcome ,
1057+ headContext,
1058+ } ;
1059+ }
10601060 // Only skip when the branch is untracked as well: anything carrying an
10611061 // upstream keeps the old behaviour.
10621062 if (
@@ -1146,119 +1146,119 @@ export const make = Effect.gen(function* () {
11461146 return lastKnown . pr ;
11471147 } ;
11481148 const lookupStatusPr = Effect . fn ( "lookupStatusPr" ) ( function * (
1149- cwd : string ,
1150- details : {
1151- branch : string ;
1152- upstreamRef : string | null ;
1153- defaultBranch : string | null ;
1154- isDefaultBranch : boolean ;
1155- } ,
1156- refreshMissingPullRequest = false ,
1157- ) {
1158- // Keyed by (cwd, branch) only: the upstream ref changing (e.g. a first
1159- // `push -u`) must not orphan the fallback value for the same branch.
1160- const branchKey = `${ cwd } \u0000${ details . branch } ` ;
1161- const cacheKey = prLookupCacheKey ( cwd , details ) ;
1162- if ( refreshMissingPullRequest ) {
1163- const cached = yield * Cache . getOption ( prLookupCache , cacheKey ) . pipe (
1164- Effect . orElseSucceed ( ( ) => Option . none ( ) ) ,
1165- ) ;
1166- if (
1167- Option . isSome ( cached ) &&
1168- cached . value . outcome . _tag === "Complete" &&
1169- cached . value . outcome . latest === null
1170- ) {
1171- yield * Cache . invalidate ( prLookupCache , cacheKey ) ;
1172- }
1173- }
1174- return yield * Cache . get ( prLookupCache , cacheKey ) . pipe (
1175- Effect . flatMap ( ( { outcome, headContext } ) => {
1176- const lastKnownContext = {
1177- upstreamRef : details . upstreamRef ,
1178- headBranch : headContext . headBranch ,
1179- remoteName : headContext . remoteName ,
1180- headRemoteUrlKey : headContext . headRemoteUrlKey ,
1181- } ;
1182- if ( outcome . _tag === "ProviderUnknown" ) {
1183- return Effect . succeed ( resolveLastKnownPr ( branchKey , lastKnownContext ) ) ;
1149+ cwd : string ,
1150+ details : {
1151+ branch : string ;
1152+ upstreamRef : string | null ;
1153+ defaultBranch : string | null ;
1154+ isDefaultBranch : boolean ;
1155+ } ,
1156+ refreshMissingPullRequest = false ,
1157+ ) {
1158+ // Keyed by (cwd, branch) only: the upstream ref changing (e.g. a first
1159+ // `push -u`) must not orphan the fallback value for the same branch.
1160+ const branchKey = `${ cwd } \u0000${ details . branch } ` ;
1161+ const cacheKey = prLookupCacheKey ( cwd , details ) ;
1162+ if ( refreshMissingPullRequest ) {
1163+ const cached = yield * Cache . getOption ( prLookupCache , cacheKey ) . pipe (
1164+ Effect . orElseSucceed ( ( ) => Option . none ( ) ) ,
1165+ ) ;
1166+ if (
1167+ Option . isSome ( cached ) &&
1168+ cached . value . outcome . _tag === "Complete" &&
1169+ cached . value . outcome . latest === null
1170+ ) {
1171+ yield * Cache . invalidate ( prLookupCache , cacheKey ) ;
11841172 }
1173+ }
1174+ return yield * Cache . get ( prLookupCache , cacheKey ) . pipe (
1175+ Effect . flatMap ( ( { outcome, headContext } ) => {
1176+ const lastKnownContext = {
1177+ upstreamRef : details . upstreamRef ,
1178+ headBranch : headContext . headBranch ,
1179+ remoteName : headContext . remoteName ,
1180+ headRemoteUrlKey : headContext . headRemoteUrlKey ,
1181+ } ;
1182+ if ( outcome . _tag === "ProviderUnknown" ) {
1183+ return Effect . succeed ( resolveLastKnownPr ( branchKey , lastKnownContext ) ) ;
1184+ }
11851185
1186- const pr =
1187- outcome . latest === null ||
1188- // On the default branch, only surface open PRs. Merged/closed
1189- // matches are usually reverse-merge history, not the thread's PR.
1190- ( details . isDefaultBranch && outcome . latest . state !== "open" )
1191- ? null
1192- : toStatusPr ( outcome . latest ) ;
1193- return Effect . sync ( ( ) => {
1194- rememberLastKnownPr ( branchKey , { pr, ...lastKnownContext } ) ;
1195- return pr ;
1196- } ) ;
1197- } ) ,
1198- Effect . catch ( ( error ) =>
1199- Effect . logWarning ( "PR lookup failed; keeping last known PR state." ) . pipe (
1200- Effect . annotateLogs ( {
1201- operation : "lookupStatusPr" ,
1202- branch : details . branch ,
1203- errorTag :
1204- typeof error === "object" && error !== null && "_tag" in error
1205- ? String ( error . _tag )
1206- : typeof error ,
1207- ...( isSourceControlProviderError ( error )
1208- ? {
1209- provider : error . provider ,
1210- providerOperation : error . operation ,
1211- providerCommand : error . command ?? "unknown" ,
1212- errorDetail : error . detail ,
1213- }
1214- : { } ) ,
1215- } ) ,
1216- Effect . andThen ( resolveLookupHeadContext ( cwd , details ) ) ,
1217- Effect . map ( ( { headContext } ) =>
1218- resolveLastKnownPr ( branchKey , {
1219- upstreamRef : details . upstreamRef ,
1220- headBranch : headContext . headBranch ,
1221- remoteName : headContext . remoteName ,
1222- headRemoteUrlKey : headContext . headRemoteUrlKey ,
1186+ const pr =
1187+ outcome . latest === null ||
1188+ // On the default branch, only surface open PRs. Merged/closed
1189+ // matches are usually reverse-merge history, not the thread's PR.
1190+ ( details . isDefaultBranch && outcome . latest . state !== "open" )
1191+ ? null
1192+ : toStatusPr ( outcome . latest ) ;
1193+ return Effect . sync ( ( ) => {
1194+ rememberLastKnownPr ( branchKey , { pr, ...lastKnownContext } ) ;
1195+ return pr ;
1196+ } ) ;
1197+ } ) ,
1198+ Effect . catch ( ( error ) =>
1199+ Effect . logWarning ( "PR lookup failed; keeping last known PR state." ) . pipe (
1200+ Effect . annotateLogs ( {
1201+ operation : "lookupStatusPr" ,
1202+ branch : details . branch ,
1203+ errorTag :
1204+ typeof error === "object" && error !== null && "_tag" in error
1205+ ? String ( error . _tag )
1206+ : typeof error ,
1207+ ...( isSourceControlProviderError ( error )
1208+ ? {
1209+ provider : error . provider ,
1210+ providerOperation : error . operation ,
1211+ providerCommand : error . command ?? "unknown" ,
1212+ errorDetail : error . detail ,
1213+ }
1214+ : { } ) ,
12231215 } ) ,
1216+ Effect . andThen ( resolveLookupHeadContext ( cwd , details ) ) ,
1217+ Effect . map ( ( { headContext } ) =>
1218+ resolveLastKnownPr ( branchKey , {
1219+ upstreamRef : details . upstreamRef ,
1220+ headBranch : headContext . headBranch ,
1221+ remoteName : headContext . remoteName ,
1222+ headRemoteUrlKey : headContext . headRemoteUrlKey ,
1223+ } ) ,
1224+ ) ,
12241225 ) ,
12251226 ) ,
1226- ) ,
1227- ) ;
1228- } ) ;
1229- const readRemoteStatus = Effect . fn ( "readRemoteStatus" ) ( function * (
1230- cwd : string ,
1231- options ?: GitRemoteStatusOptions ,
1232- ) {
1233- const details = yield * gitCore
1234- . statusDetailsRemote ( cwd , options )
1235- . pipe ( Effect . catchIf ( isNotGitRepositoryError , ( ) => Effect . succeed ( null ) ) ) ;
1236- if ( details === null || ! details . isRepo ) {
1237- return null ;
1238- }
1227+ ) ;
1228+ } ) ;
1229+ const readRemoteStatus = Effect . fn ( "readRemoteStatus" ) ( function * (
1230+ cwd : string ,
1231+ options ?: GitRemoteStatusOptions ,
1232+ ) {
1233+ const details = yield * gitCore
1234+ . statusDetailsRemote ( cwd , options )
1235+ . pipe ( Effect . catchIf ( isNotGitRepositoryError , ( ) => Effect . succeed ( null ) ) ) ;
1236+ if ( details === null || ! details . isRepo ) {
1237+ return null ;
1238+ }
12391239
1240- const pr =
1241- details . branch !== null
1242- ? yield * lookupStatusPr (
1243- cwd ,
1244- {
1245- branch : details . branch ,
1246- upstreamRef : details . upstreamRef ,
1247- defaultBranch : details . defaultBranch ,
1248- isDefaultBranch : details . isDefaultBranch ,
1249- } ,
1250- options ?. refreshMissingPullRequest ,
1251- )
1252- : null ;
1240+ const pr =
1241+ details . branch !== null
1242+ ? yield * lookupStatusPr (
1243+ cwd ,
1244+ {
1245+ branch : details . branch ,
1246+ upstreamRef : details . upstreamRef ,
1247+ defaultBranch : details . defaultBranch ,
1248+ isDefaultBranch : details . isDefaultBranch ,
1249+ } ,
1250+ options ?. refreshMissingPullRequest ,
1251+ )
1252+ : null ;
12531253
1254- return {
1255- hasUpstream : details . hasUpstream ,
1256- aheadCount : details . aheadCount ,
1257- behindCount : details . behindCount ,
1258- aheadOfDefaultCount : details . aheadOfDefaultCount ,
1259- pr,
1260- } satisfies VcsStatusRemoteResult ;
1261- } ) ;
1254+ return {
1255+ hasUpstream : details . hasUpstream ,
1256+ aheadCount : details . aheadCount ,
1257+ behindCount : details . behindCount ,
1258+ aheadOfDefaultCount : details . aheadOfDefaultCount ,
1259+ pr,
1260+ } satisfies VcsStatusRemoteResult ;
1261+ } ) ;
12621262 const remoteStatusResultCache = yield * Cache . makeWith ( ( cwd : string ) => readRemoteStatus ( cwd ) , {
12631263 capacity : STATUS_RESULT_CACHE_CAPACITY ,
12641264 timeToLive : ( exit ) => ( Exit . isSuccess ( exit ) ? STATUS_RESULT_CACHE_TTL : Duration . zero ) ,
0 commit comments