@@ -1797,6 +1797,71 @@ describe("orphan worktree reports", () => {
17971797 ) ,
17981798 ) ;
17991799
1800+ it . live ( "reports linked worktrees nested deeper inside a plain folder" , ( ) =>
1801+ runCleanupTest (
1802+ Effect . gen ( function * ( ) {
1803+ const fixture = yield * cleanupFixture ( ) ;
1804+ fixture . setThreads ( [ ] ) ;
1805+ const replay = `${ fixture . config . worktreesDir } /repository/replay` ;
1806+ const deep = `${ fixture . config . worktreesDir } /repository/deep` ;
1807+ const worktrees = [ `${ deep } /a/b` , `${ replay } /1376` ] ;
1808+ for ( const [ index , worktree ] of worktrees . entries ( ) ) {
1809+ yield * fixture . command ( fixture . repo , [
1810+ "worktree" ,
1811+ "add" ,
1812+ "-b" ,
1813+ `nested-${ index } ` ,
1814+ worktree ,
1815+ ] ) ;
1816+ }
1817+ for ( const folder of [ ...worktrees , `${ deep } /a` , deep , replay ] ) {
1818+ yield * fixture . fs . utimes ( folder , 1 , 1 ) ;
1819+ }
1820+ const report = yield * fixture . service . runNow ;
1821+ expect (
1822+ report . entries
1823+ . map ( ( entry ) => ( { path : entry . path , reason : entry . reason } ) )
1824+ . sort ( ( left , right ) => String ( left . path ) . localeCompare ( String ( right . path ) ) ) ,
1825+ ) . toEqual ( worktrees . map ( ( path ) => ( { path, reason : "No thread uses this worktree" } ) ) ) ;
1826+ } ) ,
1827+ ) ,
1828+ ) ;
1829+
1830+ it . live ( "still reports a plain folder whose nested worktree registration is stale" , ( ) =>
1831+ runCleanupTest (
1832+ Effect . gen ( function * ( ) {
1833+ const fixture = yield * cleanupFixture ( ) ;
1834+ fixture . setThreads ( [ ] ) ;
1835+ const replay = `${ fixture . config . worktreesDir } /repository/replay` ;
1836+ const worktree = `${ replay } /1376` ;
1837+ yield * fixture . command ( fixture . repo , [ "worktree" , "add" , "-b" , "locked" , worktree ] ) ;
1838+ yield * fixture . command ( fixture . repo , [ "worktree" , "lock" , worktree ] ) ;
1839+ yield * fixture . fs . rename ( worktree , `${ replay } /moved` ) ;
1840+ yield * fixture . fs . makeDirectory ( worktree ) ;
1841+ yield * fixture . fs . utimes ( replay , 1 , 1 ) ;
1842+ expect ( ( yield * fixture . service . runNow ) . entries . map ( ( entry ) => entry . path ) ) . toEqual ( [
1843+ replay ,
1844+ ] ) ;
1845+ } ) ,
1846+ ) ,
1847+ ) ;
1848+
1849+ it . live ( "does not report nested worktrees inside a project checkout" , ( ) =>
1850+ runCleanupTest (
1851+ Effect . gen ( function * ( ) {
1852+ const fixture = yield * cleanupFixture ( ) ;
1853+ fixture . setThreads ( [ ] ) ;
1854+ const project = `${ fixture . config . worktreesDir } /repository/replay/project` ;
1855+ const worktree = `${ project } /nested` ;
1856+ yield * fixture . fs . makeDirectory ( project , { recursive : true } ) ;
1857+ fixture . setProjectRoots ( [ fixture . repo , project ] ) ;
1858+ yield * fixture . command ( fixture . repo , [ "worktree" , "add" , "-b" , "nested" , worktree ] ) ;
1859+ for ( const folder of [ worktree , project ] ) yield * fixture . fs . utimes ( folder , 1 , 1 ) ;
1860+ expect ( ( yield * fixture . service . runNow ) . entries ) . toEqual ( [ ] ) ;
1861+ } ) ,
1862+ ) ,
1863+ ) ;
1864+
18001865 it . live ( "continues after an inaccessible directory's git probe" , ( context ) =>
18011866 runCleanupTest (
18021867 Effect . gen ( function * ( ) {
0 commit comments