@@ -2963,34 +2963,85 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
29632963 aheadOfDefaultCount : 0 ,
29642964 } ) ;
29652965 }
2966+
2967+ yield * git ( cwd , [ "branch" , "-f" , initialBranch , "HEAD" ] ) ;
2968+ yield * git ( cwd , [ "update-ref" , "refs/remotes/origin/trunk" , "HEAD" ] ) ;
2969+ yield * git ( cwd , [ "symbolic-ref" , "refs/remotes/origin/HEAD" , "refs/remotes/origin/trunk" ] ) ;
2970+ for ( const base of [ initialBranch , "missing-base" ] ) {
2971+ yield * git ( cwd , [ "config" , "branch.feature/local-only.gh-merge-base" , base ] ) ;
2972+ commands . length = 0 ;
2973+ const status = yield * driver . statusDetailsLocal ( cwd , {
2974+ includeDivergence : false ,
2975+ includeBranchChanges : true ,
2976+ } ) ;
2977+ assert . deepEqual ( status . branchChanges , {
2978+ baseRef : `origin/${ base === initialBranch ? initialBranch : "trunk" } ` ,
2979+ insertions : base === initialBranch ? 3 : 2 ,
2980+ deletions : 0 ,
2981+ } ) ;
2982+ assert . lengthOf (
2983+ commands . filter ( ( args ) => args . join ( " " ) === "symbolic-ref refs/remotes/origin/HEAD" ) ,
2984+ base === initialBranch ? 0 : 1 ,
2985+ ) ;
2986+ }
29662987 } ) ,
29672988 ) ;
29682989
29692990 it . effect ( "reports remote divergence without reading working-tree details" , ( ) =>
29702991 Effect . gen ( function * ( ) {
29712992 const cwd = yield * makeTmpDir ( ) ;
29722993 const remote = yield * makeTmpDir ( "git-vcs-driver-remote-" ) ;
2973- const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
2994+ yield * initRepoWithCommit ( cwd ) ;
2995+ yield * git ( cwd , [ "branch" , "-M" , "trunk" ] ) ;
29742996 yield * git ( remote , [ "init" , "--bare" ] ) ;
29752997 yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
2976- yield * git ( cwd , [ "push" , "-u" , "origin" , initialBranch ] ) ;
2998+ yield * git ( cwd , [ "push" , "-u" , "origin" , "trunk" ] ) ;
29772999 yield * git ( cwd , [ "checkout" , "-b" , "feature/remote-status" ] ) ;
29783000 yield * writeTextFile ( cwd , "feature.txt" , "feature\n" ) ;
29793001 yield * git ( cwd , [ "add" , "feature.txt" ] ) ;
29803002 yield * git ( cwd , [ "commit" , "-m" , "feature commit" ] ) ;
29813003 yield * git ( cwd , [ "push" , "-u" , "origin" , "feature/remote-status" ] ) ;
29823004 yield * writeTextFile ( cwd , "untracked.txt" , "local-only\n" ) ;
3005+ yield * git ( cwd , [ "symbolic-ref" , "refs/remotes/origin/HEAD" , "refs/remotes/origin/trunk" ] ) ;
29833006
2984- const status = yield * ( yield * GitVcsDriver . GitVcsDriver ) . statusDetailsRemote ( cwd ) ;
3007+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
3008+ let originHeadReads = 0 ;
3009+ let failFirstOriginHead = false ;
3010+ const spawner = ChildProcessSpawner . make ( ( command ) =>
3011+ Effect . gen ( function * ( ) {
3012+ if (
3013+ ChildProcess . isStandardCommand ( command ) &&
3014+ command . args . join ( " " ) === "symbolic-ref refs/remotes/origin/HEAD"
3015+ ) {
3016+ originHeadReads ++ ;
3017+ if ( failFirstOriginHead && originHeadReads === 1 ) return makeNonRepositoryHandle ( ) ;
3018+ }
3019+ return yield * delegate . spawn ( command ) ;
3020+ } ) ,
3021+ ) ;
3022+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
3023+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
3024+ Effect . provide ( layerServerConfig ) ,
3025+ ) ;
3026+ const status = yield * driver . statusDetailsRemote ( cwd , { refreshUpstream : false } ) ;
29853027
29863028 assert . equal ( status . isRepo , true ) ;
29873029 assert . equal ( status . branch , "feature/remote-status" ) ;
3030+ assert . equal ( status . defaultBranch , "trunk" ) ;
29883031 assert . equal ( status . hasUpstream , true ) ;
29893032 assert . equal ( status . aheadCount , 0 ) ;
29903033 assert . equal ( status . behindCount , 0 ) ;
29913034 assert . equal ( status . aheadOfDefaultCount , 1 ) ;
29923035 assert . notProperty ( status , "workingTree" ) ;
29933036 assert . notProperty ( status , "hasWorkingTreeChanges" ) ;
3037+ assert . equal ( originHeadReads , 1 ) ;
3038+
3039+ // With no main/master fallback, the retry must resolve trunk to preserve the ahead count.
3040+ originHeadReads = 0 ;
3041+ failFirstOriginHead = true ;
3042+ const retried = yield * driver . statusDetailsRemote ( cwd , { refreshUpstream : false } ) ;
3043+ assert . deepEqual ( retried , { ...status , defaultBranch : null } ) ;
3044+ assert . equal ( originHeadReads , 2 ) ;
29943045 } ) ,
29953046 ) ;
29963047
0 commit comments