@@ -1381,6 +1381,61 @@ it.effect("lets a worktree checkout that is still working run past five minutes"
13811381 } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
13821382) ;
13831383
1384+ it . effect ( "cancels a slow submodule checkout without reporting best-effort success" , ( ) =>
1385+ Effect . gen ( function * ( ) {
1386+ const updateStarted = yield * Deferred . make < void > ( ) ;
1387+ const updateStopped = yield * Deferred . make < void > ( ) ;
1388+ const finished = yield * Ref . make < ReadonlyArray < { ok : boolean ; detail : string | null } > > ( [ ] ) ;
1389+ const claimed = yield * Ref . make < string | null > ( null ) ;
1390+ const spawner = ChildProcessSpawner . make ( ( command ) => {
1391+ if (
1392+ ChildProcess . isStandardCommand ( command ) &&
1393+ command . args [ 0 ] === "submodule" &&
1394+ command . args [ 1 ] === "update"
1395+ ) {
1396+ return Effect . acquireRelease (
1397+ Effect . succeed (
1398+ ChildProcessSpawner . makeHandle ( {
1399+ ...makeSuccessfulHandle ( "" ) ,
1400+ exitCode : Deferred . succeed ( updateStarted , undefined ) . pipe (
1401+ Effect . andThen ( Effect . never ) ,
1402+ ) ,
1403+ } ) ,
1404+ ) ,
1405+ ( ) => Deferred . succeed ( updateStopped , undefined ) ,
1406+ ) ;
1407+ }
1408+ return Effect . succeed ( makeSuccessfulHandle ( "" ) ) ;
1409+ } ) ;
1410+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
1411+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
1412+ ) ;
1413+ const cwd = yield * makeTmpDir ( ) ;
1414+ const path = yield * Path . Path ;
1415+ const worktreePath = path . join ( cwd , "worktree" ) ;
1416+ yield * writeTextFile ( worktreePath , ".gitmodules" , "" ) ;
1417+ const creation = yield * driver
1418+ . createWorktree (
1419+ { cwd, refName : "main" , newRefName : "bugfix/cancel-submodules" , path : worktreePath } ,
1420+ {
1421+ progress : {
1422+ onWorktreeClaimed : ( value ) => Ref . set ( claimed , value ) ,
1423+ onSubmodulesFinished : ( result ) => Ref . update ( finished , ( items ) => [ ...items , result ] ) ,
1424+ } ,
1425+ } ,
1426+ )
1427+ . pipe ( Effect . forkChild ) ;
1428+ yield * Deferred . await ( updateStarted ) ;
1429+ yield * TestClock . adjust ( "6 minutes" ) ;
1430+ yield * Fiber . interrupt ( creation ) ;
1431+ const exit = yield * Fiber . await ( creation ) ;
1432+ assert . isTrue ( Exit . isFailure ( exit ) && Cause . hasInterruptsOnly ( exit . cause ) ) ;
1433+ assert . isTrue ( yield * Deferred . isDone ( updateStopped ) ) ;
1434+ assert . equal ( yield * Ref . get ( claimed ) , worktreePath ) ;
1435+ assert . isEmpty ( yield * Ref . get ( finished ) ) ;
1436+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
1437+ ) ;
1438+
13841439describe ( "rejected git refs" , ( ) => {
13851440 const remoteUrl = "https://user:[email protected] /org/secret-repo.git" ; 13861441 const failedPush = `error: failed to push some refs to '${ remoteUrl } '` ;
@@ -4037,7 +4092,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40374092 } ) ,
40384093 ) ;
40394094
4040- it . effect ( "checks out submodules in a new worktree" , ( ) =>
4095+ it . effect . each ( [
4096+ [ "recursive" , false ] ,
4097+ [ "recursive" , true ] ,
4098+ [ "top-level" , false ] ,
4099+ [ "top-level" , true ] ,
4100+ ] as const ) ( "finishes a slow submodule checkout (%s, progress: %s)" , ( [ submodules , progress ] ) =>
40414101 Effect . gen ( function * ( ) {
40424102 const fileSystem = yield * FileSystem . FileSystem ;
40434103 const pathService = yield * Path . Path ;
@@ -4057,6 +4117,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40574117
40584118 const submoduleRepo = yield * makeTmpDir ( "git-submodule-" ) ;
40594119 yield * initRepoWithCommit ( submoduleRepo ) ;
4120+ yield * writeTextFile ( submoduleRepo , ".gitattributes" , "* text eol=lf\n" ) ;
40604121 yield * writeTextFile ( submoduleRepo , "SHARED.md" , "# shared\n" ) ;
40614122 yield * git ( submoduleRepo , [ "add" , "." ] ) ;
40624123 yield * git ( submoduleRepo , [ "commit" , "-m" , "shared" ] ) ;
@@ -4065,23 +4126,80 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40654126 const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
40664127 yield * git ( cwd , [ "submodule" , "add" , submoduleRepo , "shared" ] ) ;
40674128 yield * git ( cwd , [ "commit" , "-m" , "add submodule" ] ) ;
4129+ const recordedHead = yield * git ( submoduleRepo , [ "rev-parse" , "HEAD" ] ) ;
4130+ yield * writeTextFile ( submoduleRepo , "SHARED.md" , "# newer remote default\n" ) ;
4131+ yield * git ( submoduleRepo , [ "commit" , "-am" , "advance remote default" ] ) ;
4132+
4133+ const updateStarted = yield * Deferred . make < void > ( ) ;
4134+ const releaseUpdate = yield * Deferred . make < void > ( ) ;
4135+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
4136+ const spawner = ChildProcessSpawner . make ( ( command ) =>
4137+ Effect . gen ( function * ( ) {
4138+ if (
4139+ ChildProcess . isStandardCommand ( command ) &&
4140+ command . args [ 0 ] === "submodule" &&
4141+ command . args [ 1 ] === "update"
4142+ ) {
4143+ yield * Deferred . succeed ( updateStarted , undefined ) ;
4144+ yield * Deferred . await ( releaseUpdate ) ;
4145+ }
4146+ return yield * delegate . spawn ( command ) ;
4147+ } ) ,
4148+ ) ;
4149+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
4150+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
4151+ Effect . provide ( layerServerConfig ) ,
4152+ ) ;
4153+ const finished = yield * Ref . make < ReadonlyArray < { ok : boolean ; detail : string | null } > > ( [ ] ) ;
4154+ const lines = yield * Ref . make < ReadonlyArray < string > > ( [ ] ) ;
40684155
40694156 const worktreePath = pathService . join (
40704157 yield * makeTmpDir ( "git-worktrees-" ) ,
40714158 "submodule-worktree" ,
40724159 ) ;
4073- const driver = yield * GitVcsDriver . GitVcsDriver ;
4074- yield * driver . createWorktree ( {
4075- cwd,
4076- path : worktreePath ,
4077- refName : initialBranch ,
4078- newRefName : "feature/submodules" ,
4079- } ) ;
4160+ const creation = yield * driver
4161+ . createWorktree (
4162+ {
4163+ cwd,
4164+ path : worktreePath ,
4165+ refName : initialBranch ,
4166+ newRefName : "feature/submodules" ,
4167+ } ,
4168+ {
4169+ submodules,
4170+ progress : {
4171+ onSubmodulesFinished : ( result ) =>
4172+ Ref . update ( finished , ( items ) => [ ...items , result ] ) ,
4173+ ...( progress
4174+ ? {
4175+ onSubmoduleLine : ( line : string ) =>
4176+ Ref . update ( lines , ( items ) => [ ...items , line ] ) ,
4177+ }
4178+ : { } ) ,
4179+ } ,
4180+ } ,
4181+ )
4182+ . pipe ( Effect . forkChild ) ;
4183+ yield * Deferred . await ( updateStarted ) ;
4184+ yield * TestClock . adjust ( "6 minutes" ) ;
4185+ yield * Deferred . succeed ( releaseUpdate , undefined ) ;
4186+ yield * Fiber . join ( creation ) ;
40804187
4188+ assert . deepEqual ( yield * Ref . get ( finished ) , [ { ok : true , detail : null } ] ) ;
40814189 assert . equal (
40824190 yield * fileSystem . exists ( pathService . join ( worktreePath , "shared" , "SHARED.md" ) ) ,
40834191 true ,
40844192 ) ;
4193+ assert . equal (
4194+ yield * git ( pathService . join ( worktreePath , "shared" ) , [ "rev-parse" , "HEAD" ] ) ,
4195+ recordedHead ,
4196+ ) ;
4197+ assert . equal ( yield * git ( worktreePath , [ "status" , "--porcelain" ] ) , "" ) ;
4198+ assert . equal (
4199+ yield * git ( pathService . join ( worktreePath , "shared" ) , [ "status" , "--porcelain" ] ) ,
4200+ "" ,
4201+ ) ;
4202+ if ( progress ) assert . isNotEmpty ( yield * Ref . get ( lines ) ) ;
40854203 } ) ,
40864204 ) ;
40874205
@@ -4098,22 +4216,36 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40984216 '[submodule "missing"]\n\tpath = missing\n\turl = /nonexistent/repo.git\n' ,
40994217 ) ;
41004218 yield * git ( cwd , [ "add" , "." ] ) ;
4219+ const gitlink = yield * git ( cwd , [ "rev-parse" , "HEAD" ] ) ;
4220+ yield * git ( cwd , [ "update-index" , "--add" , "--cacheinfo" , `160000,${ gitlink } ,missing` ] ) ;
41014221 yield * git ( cwd , [ "commit" , "-m" , "add unreachable submodule" ] ) ;
41024222
41034223 const worktreePath = pathService . join (
41044224 yield * makeTmpDir ( "git-worktrees-" ) ,
41054225 "broken-submodule-worktree" ,
41064226 ) ;
41074227 const driver = yield * GitVcsDriver . GitVcsDriver ;
4108- const created = yield * driver . createWorktree ( {
4109- cwd,
4110- path : worktreePath ,
4111- refName : initialBranch ,
4112- newRefName : "feature/broken-submodules" ,
4113- } ) ;
4228+ const finished = yield * Ref . make < ReadonlyArray < { ok : boolean ; detail : string | null } > > ( [ ] ) ;
4229+ const created = yield * driver . createWorktree (
4230+ {
4231+ cwd,
4232+ path : worktreePath ,
4233+ refName : initialBranch ,
4234+ newRefName : "feature/broken-submodules" ,
4235+ } ,
4236+ {
4237+ progress : {
4238+ onSubmodulesFinished : ( result ) => Ref . update ( finished , ( items ) => [ ...items , result ] ) ,
4239+ } ,
4240+ } ,
4241+ ) ;
41144242
41154243 assert . equal ( created . worktree . path , worktreePath ) ;
41164244 assert . equal ( yield * fileSystem . exists ( worktreePath ) , true ) ;
4245+ const results = yield * Ref . get ( finished ) ;
4246+ assert . lengthOf ( results , 1 ) ;
4247+ assert . isFalse ( results [ 0 ] ! . ok ) ;
4248+ assert . include ( results [ 0 ] ! . detail , "GitVcsDriver.createWorktree.updateSubmodules" ) ;
41174249 } ) ,
41184250 ) ;
41194251
0 commit comments