@@ -1527,6 +1527,50 @@ describe("VcsStatusBroadcaster", () => {
15271527 } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
15281528 ) ;
15291529
1530+ it . effect ( "a HEAD watch ends when its git directory is removed" , ( ) =>
1531+ Effect . gen ( function * ( ) {
1532+ const gitDir = "/repo/.git/worktrees/feature" ;
1533+ const events = yield * Queue . unbounded < FileSystem . WatchEvent > ( ) ;
1534+ const closed = yield * Deferred . make < void > ( ) ;
1535+ let gitDirExists = true ;
1536+ const state : Parameters < typeof layerTestFor > [ 0 ] = {
1537+ currentLocalStatus : { ...baseLocalStatus , refName : "main" } ,
1538+ currentRemoteStatus : null ,
1539+ localStatusCalls : 0 ,
1540+ remoteStatusCalls : 0 ,
1541+ localInvalidationCalls : 0 ,
1542+ remoteInvalidationCalls : 0 ,
1543+ headPath : `${ gitDir } /HEAD` ,
1544+ fileSystem : FileSystem . makeNoop ( {
1545+ realPath : ( target ) => Effect . succeed ( target ) ,
1546+ exists : ( target ) => Effect . succeed ( target !== gitDir || gitDirExists ) ,
1547+ watch : ( _target , options ) =>
1548+ Stream . fromQueue ( events ) . pipe (
1549+ Stream . onStart ( Effect . sync ( ( ) => options ?. onReady ?.( ) ) ) ,
1550+ Stream . ensuring ( Deferred . succeed ( closed , undefined ) ) ,
1551+ ) ,
1552+ } ) ,
1553+ } ;
1554+
1555+ yield * Effect . gen ( function * ( ) {
1556+ const broadcaster = yield * VcsStatusBroadcaster . VcsStatusBroadcaster ;
1557+ const branches = yield * Stream . toPull ( broadcaster . streamBranchStatus ( { cwd : "/repo" } ) ) ;
1558+ assert . deepEqual ( yield * branches , [ { refName : "main" } ] ) ;
1559+
1560+ // Every checkout removes HEAD.lock, which leaves the watch running.
1561+ state . currentLocalStatus = { ...baseLocalStatus , refName : "other" } ;
1562+ yield * Queue . offer ( events , { _tag : "Remove" , path : "HEAD.lock" } ) ;
1563+ yield * Queue . offer ( events , { _tag : "Update" , path : "HEAD" } ) ;
1564+ assert . deepEqual ( yield * branches , [ { refName : "other" } ] ) ;
1565+
1566+ // `git worktree remove` deletes the watched directory; Windows keeps reporting it.
1567+ gitDirExists = false ;
1568+ yield * Queue . offer ( events , { _tag : "Remove" , path : gitDir } ) ;
1569+ yield * Deferred . await ( closed ) ;
1570+ } ) . pipe ( Effect . provide ( layerTestFor ( state ) ) , Effect . scoped ) ;
1571+ } ) ,
1572+ ) ;
1573+
15301574 it . effect ( "releases remote demand while passive observers remain" , ( ) => {
15311575 const state = {
15321576 currentLocalStatus : baseLocalStatus ,
0 commit comments