@@ -1557,6 +1557,65 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
15571557 } ) ;
15581558
15591559 describe ( "worktree operations" , ( ) => {
1560+ for ( const state of [ "new" , "new-missing" , "existing" , "existing-missing" ] as const ) {
1561+ it . effect ( `cleans up only newly registered worktrees on interruption: ${ state } ` , ( ) =>
1562+ Effect . gen ( function * ( ) {
1563+ const cwd = yield * makeTmpDir ( ) ;
1564+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
1565+ const fs = yield * FileSystem . FileSystem ;
1566+ const path = yield * Path . Path ;
1567+ const worktreePath = path . join ( yield * makeTmpDir ( "git-worktrees-" ) , "interrupted" ) ;
1568+ const existing = state . startsWith ( "existing" ) ;
1569+ if ( existing ) {
1570+ yield * git ( cwd , [ "worktree" , "add" , "-b" , "feature/existing" , worktreePath ] ) ;
1571+ if ( state === "existing-missing" ) {
1572+ yield * fs . remove ( worktreePath , { recursive : true } ) ;
1573+ }
1574+ }
1575+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
1576+ const commandFinished = yield * Deferred . make < void > ( ) ;
1577+ const spawner = ChildProcessSpawner . make ( ( command ) =>
1578+ Effect . gen ( function * ( ) {
1579+ const handle = yield * delegate . spawn ( command ) ;
1580+ return ChildProcess . isStandardCommand ( command ) &&
1581+ command . args . includes ( "worktree" ) &&
1582+ command . args . includes ( "add" )
1583+ ? ChildProcessSpawner . makeHandle ( {
1584+ ...handle ,
1585+ exitCode : handle . exitCode . pipe (
1586+ Effect . andThen ( Deferred . succeed ( commandFinished , undefined ) ) ,
1587+ Effect . andThen ( Effect . never ) ,
1588+ ) ,
1589+ } )
1590+ : handle ;
1591+ } ) ,
1592+ ) ;
1593+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
1594+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
1595+ Effect . provide ( ServerConfigLayer ) ,
1596+ ) ;
1597+ const creating = yield * driver
1598+ . createWorktree ( {
1599+ cwd,
1600+ path : worktreePath ,
1601+ refName : initialBranch ,
1602+ newRefName : "feature/interrupted" ,
1603+ } )
1604+ . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
1605+ yield * Deferred . await ( commandFinished ) ;
1606+ if ( state === "new-missing" ) {
1607+ yield * fs . remove ( worktreePath , { recursive : true } ) ;
1608+ }
1609+ yield * Fiber . interrupt ( creating ) ;
1610+
1611+ assert . equal ( yield * fs . exists ( worktreePath ) , state === "existing" ) ;
1612+ const registered = yield * git ( cwd , [ "worktree" , "list" , "--porcelain" , "-z" ] ) ;
1613+ assert . equal ( registered . includes ( "feature/existing" ) , existing ) ;
1614+ assert . notInclude ( registered , "feature/interrupted" ) ;
1615+ } ) ,
1616+ ) ;
1617+ }
1618+
15601619 it . effect ( "uses parallel checkout without skipping filters or hooks" , ( ) =>
15611620 Effect . gen ( function * ( ) {
15621621 const cwd = yield * makeTmpDir ( ) ;
0 commit comments