@@ -2959,6 +2959,70 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
29592959 } ) ,
29602960 ) ;
29612961
2962+ it . effect ( "does not guess a Changes base for a branch renamed during the status read" , ( ) =>
2963+ Effect . gen ( function * ( ) {
2964+ const cwd = yield * makeTmpDir ( ) ;
2965+ const fork = yield * makeTmpDir ( ) ;
2966+ const upstream = yield * makeTmpDir ( ) ;
2967+ yield * initRepoWithCommit ( cwd ) ;
2968+ yield * git ( cwd , [ "branch" , "-M" , "main" ] ) ;
2969+ yield * git ( fork , [ "init" , "--bare" ] ) ;
2970+ yield * git ( upstream , [ "init" , "--bare" ] ) ;
2971+ yield * git ( cwd , [ "remote" , "add" , "origin" , fork ] ) ;
2972+ yield * git ( cwd , [ "remote" , "add" , "upstream" , upstream ] ) ;
2973+ yield * git ( cwd , [ "push" , "origin" , "main" ] ) ;
2974+ yield * writeTextFile ( cwd , "upstream.txt" , "work missing from the fork\n" ) ;
2975+ yield * git ( cwd , [ "add" , "upstream.txt" ] ) ;
2976+ yield * git ( cwd , [ "commit" , "-m" , "upstream work" ] ) ;
2977+ yield * git ( cwd , [ "push" , "upstream" , "main" ] ) ;
2978+ yield * git ( cwd , [ "fetch" , "origin" ] ) ;
2979+ yield * git ( cwd , [ "fetch" , "upstream" ] ) ;
2980+ yield * git ( cwd , [ "checkout" , "-b" , "t3/temporary" ] ) ;
2981+ yield * git ( cwd , [ "config" , "branch.t3/temporary.t3-merge-base" , "main" ] ) ;
2982+ yield * git ( cwd , [
2983+ "config" ,
2984+ "branch.t3/temporary.t3-merge-base-ref" ,
2985+ "refs/remotes/upstream/main" ,
2986+ ] ) ;
2987+ yield * writeTextFile ( cwd , "feature.txt" , "thread work\n" ) ;
2988+
2989+ const outer = yield * GitVcsDriver . GitVcsDriver ;
2990+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
2991+ const renameClaimed = yield * Ref . make ( false ) ;
2992+ const renamed = yield * Deferred . make < void > ( ) ;
2993+ // Rename after `git status` has read HEAD, as the thread launcher does after the first turn.
2994+ // Base config reads start only after status completes; hold every one until the rename lands.
2995+ const spawner = ChildProcessSpawner . make ( ( command ) =>
2996+ Effect . gen ( function * ( ) {
2997+ if ( ChildProcess . isStandardCommand ( command ) && command . args [ 0 ] === "config" ) {
2998+ if ( ! ( yield * Ref . getAndSet ( renameClaimed , true ) ) ) {
2999+ yield * git ( cwd , [ "branch" , "-m" , "t3/temporary" , "feature/named" ] ) . pipe (
3000+ Effect . provideService ( GitVcsDriver . GitVcsDriver , outer ) ,
3001+ Effect . orDie ,
3002+ ) ;
3003+ yield * Deferred . succeed ( renamed , undefined ) ;
3004+ }
3005+ yield * Deferred . await ( renamed ) ;
3006+ }
3007+ return yield * delegate . spawn ( command ) ;
3008+ } ) ,
3009+ ) ;
3010+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
3011+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
3012+ Effect . provide ( layerServerConfig ) ,
3013+ ) ;
3014+
3015+ const status = yield * driver . statusDetailsLocal ( cwd , { includeBranchChanges : true } ) ;
3016+
3017+ assert . strictEqual ( status . branch , "t3/temporary" ) ;
3018+ assert . deepStrictEqual ( status . branchChanges , {
3019+ baseRef : null ,
3020+ insertions : 1 ,
3021+ deletions : 0 ,
3022+ } ) ;
3023+ } ) ,
3024+ ) ;
3025+
29623026 it . effect ( "keeps local branch bases consistent when tags share their names" , ( ) =>
29633027 Effect . gen ( function * ( ) {
29643028 const cwd = yield * makeTmpDir ( ) ;
0 commit comments