@@ -612,6 +612,52 @@ const runCleanupTest = <A, E>(
612612 > ,
613613) => effect . pipe ( Effect . provide ( cleanupTestLayer ) , Effect . scoped ) ;
614614
615+ it . live . each ( [ "repository" , "uppercase" , "bare" ] as const ) (
616+ "keeps a worktree holding an ignored nested %s" ,
617+ ( kind ) =>
618+ runCleanupTest (
619+ Effect . gen ( function * ( ) {
620+ const { service, fs, repo, worktree, command, setPolicy } = yield * cleanupFixture ( ) ;
621+ setPolicy ( "tracked-changes" ) ;
622+ const nested = `${ worktree } /dist/nested` ;
623+ if ( kind === "uppercase" ) {
624+ yield * command ( repo , [ "worktree" , "add" , "-b" , "nested" , nested ] ) ;
625+ } else {
626+ yield * command ( repo , [
627+ "clone" ,
628+ "--no-hardlinks" ,
629+ ...( kind === "bare" ? [ "--bare" ] : [ ] ) ,
630+ repo ,
631+ nested ,
632+ ] ) ;
633+ }
634+ if ( kind === "uppercase" ) yield * fs . rename ( `${ nested } /.git` , `${ nested } /.GIT` ) ;
635+ yield * fs . writeFileString ( `${ nested } /uncommitted.txt` , "irreplaceable work\n" ) ;
636+ expect ( ( yield * command ( worktree , [ "status" , "--porcelain" ] ) ) . stdout ) . toBe ( "" ) ;
637+ const report = yield * service . runNow ;
638+ expect ( report . entries . find ( ( entry ) => entry . path === worktree ) ) . toMatchObject ( {
639+ outcome : "kept" ,
640+ reason : "Contains a nested Git repository" ,
641+ } ) ;
642+ expect ( yield * fs . readFileString ( `${ nested } /uncommitted.txt` ) ) . toBe ( "irreplaceable work\n" ) ;
643+ expect (
644+ ( yield * command ( nested , [
645+ ...( kind === "uppercase"
646+ ? [
647+ `--git-dir=${ ( yield * fs . readFileString ( `${ nested } /.GIT` ) ) . trim ( ) . slice ( 8 ) } ` ,
648+ "--work-tree=." ,
649+ ]
650+ : [ ] ) ,
651+ "-c" ,
652+ "safe.bareRepository=all" ,
653+ "rev-parse" ,
654+ "--is-bare-repository" ,
655+ ] ) ) . stdout . trim ( ) ,
656+ ) . toBe ( String ( kind === "bare" ) ) ;
657+ } ) ,
658+ ) ,
659+ ) ;
660+
615661const submoduleCleanupFixture = ( ) =>
616662 Effect . gen ( function * ( ) {
617663 const fixture = yield * cleanupFixture ( ) ;
@@ -636,6 +682,48 @@ const submoduleCleanupFixture = () =>
636682 return { ...fixture , submodule, child, recordSubmodules } ;
637683 } ) ;
638684
685+ it . live ( "inspects a pnpm store excluded from reclaimed bytes for nested repositories" , ( ) =>
686+ runCleanupTest (
687+ Effect . gen ( function * ( ) {
688+ const { service, fs, repo, worktree, command, setPolicy } = yield * cleanupFixture ( ) ;
689+ setPolicy ( "tracked-changes" ) ;
690+ const storeDir = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-store-" } ) ;
691+ const nested = `${ worktree } /node_modules/.pnpm/nested` ;
692+ yield * command ( repo , [ "clone" , "--no-hardlinks" , repo , nested ] ) ;
693+ yield * fs . writeFileString ( `${ nested } /uncommitted.txt` , "keep me" ) ;
694+ yield * fs . writeFileString (
695+ `${ worktree } /node_modules/.modules.yaml` ,
696+ JSON . stringify ( { storeDir, virtualStoreDir : ".pnpm" } ) ,
697+ ) ;
698+ const report = yield * service . runNow ;
699+ expect ( report . entries . find ( ( entry ) => entry . path === worktree ) ) . toMatchObject ( {
700+ outcome : "kept" ,
701+ reason : "Contains a nested Git repository" ,
702+ } ) ;
703+ expect ( yield * fs . readFileString ( `${ nested } /uncommitted.txt` ) ) . toBe ( "keep me" ) ;
704+ } ) ,
705+ ) ,
706+ ) ;
707+
708+ it . live ( "keeps an ignored repository inside a registered submodule" , ( ) =>
709+ runCleanupTest (
710+ Effect . gen ( function * ( ) {
711+ const { service, fs, repo, worktree, submodule, command, setPolicy } =
712+ yield * submoduleCleanupFixture ( ) ;
713+ setPolicy ( "tracked-changes" ) ;
714+ const nested = `${ submodule } /dist/nested` ;
715+ yield * command ( repo , [ "clone" , "--no-hardlinks" , repo , nested ] ) ;
716+ yield * fs . writeFileString ( `${ nested } /uncommitted.txt` , "keep me" ) ;
717+ const report = yield * service . runNow ;
718+ expect ( report . entries . find ( ( entry ) => entry . path === worktree ) ) . toMatchObject ( {
719+ outcome : "kept" ,
720+ reason : "Contains a nested Git repository" ,
721+ } ) ;
722+ expect ( yield * fs . readFileString ( `${ nested } /uncommitted.txt` ) ) . toBe ( "keep me" ) ;
723+ } ) ,
724+ ) ,
725+ ) ;
726+
639727it . live ( "removes clean submodules recursively, including deinitialized repositories" , ( ) =>
640728 runCleanupTest (
641729 Effect . gen ( function * ( ) {
@@ -649,6 +737,37 @@ it.live("removes clean submodules recursively, including deinitialized repositor
649737 repo ,
650738 "stored" ,
651739 ] ) ;
740+ const legacy = `${ worktree } /legacy` ;
741+ yield * command ( repo , [ "clone" , "--no-hardlinks" , repo , legacy ] ) ;
742+ yield * command ( worktree , [ "submodule" , "add" , repo , "legacy" ] ) ;
743+ expect ( ( yield * fs . stat ( `${ legacy } /.git` ) ) . type ) . toBe ( "Directory" ) ;
744+ yield * command ( legacy , [
745+ "-c" ,
746+ "protocol.file.allow=always" ,
747+ "submodule" ,
748+ "add" ,
749+ repo ,
750+ "child" ,
751+ ] ) ;
752+ yield * command ( legacy , [
753+ "-c" ,
754+ "protocol.file.allow=always" ,
755+ "submodule" ,
756+ "add" ,
757+ repo ,
758+ "stored" ,
759+ ] ) ;
760+ yield * command ( legacy , [
761+ "-c" ,
762+ "user.name=Cleanup test" ,
763+ "-c" ,
764+ 765+ "commit" ,
766+ "-am" ,
767+ "record legacy children" ,
768+ ] ) ;
769+ yield * command ( legacy , [ "push" , "origin" , "HEAD:legacy" ] ) ;
770+ yield * command ( legacy , [ "submodule" , "deinit" , "stored" ] ) ;
652771 yield * recordSubmodules ( ) ;
653772 yield * command ( submodule , [ "submodule" , "deinit" , "stored" ] ) ;
654773 const admin = ( yield * command ( worktree , [ "rev-parse" , "--absolute-git-dir" ] ) ) . stdout . trim ( ) ;
@@ -2241,9 +2360,14 @@ describe("storage cleanup reports and local file policies", () => {
22412360 Effect . gen ( function * ( ) {
22422361 const fs = yield * FileSystem . FileSystem ;
22432362 const storeDir = yield * fs . makeTempDirectoryScoped ( { prefix : "pnpm-store-" } ) ;
2363+ const statted : string [ ] = [ ] ;
22442364 const { service, worktree, setPolicy } = yield * cleanupFixture ( ) . pipe (
22452365 Effect . provideService ( FileSystem . FileSystem , {
22462366 ...fs ,
2367+ lstat : ( target ) => {
2368+ statted . push ( target ) ;
2369+ return fs . lstat ( target ) ;
2370+ } ,
22472371 stat : ( target ) =>
22482372 fs
22492373 . stat ( target )
@@ -2284,6 +2408,9 @@ describe("storage cleanup reports and local file policies", () => {
22842408 ) ;
22852409 const report = yield * service . runNow ;
22862410 expect ( report . entries [ 0 ] ) . toMatchObject ( { outcome : "removed" , bytes } ) ;
2411+ expect ( statted . includes ( `${ nodeModules } /.pnpm/[email protected] /index.js` ) ) . toBe ( 2412+ store !== "same-device" ,
2413+ ) ;
22872414 } ) ,
22882415 ) ,
22892416 ) ;
@@ -2378,7 +2505,7 @@ describe("storage cleanup reports and local file policies", () => {
23782505 } ) ,
23792506 ) ,
23802507 ) ;
2381- it . live ( "still removes a worktree when measuring its size fails " , ( ) =>
2508+ it . live ( "keeps a worktree when the inspection cannot read its directories " , ( ) =>
23822509 runCleanupTest (
23832510 Effect . gen ( function * ( ) {
23842511 const fs = yield * FileSystem . FileSystem ;
@@ -2389,9 +2516,14 @@ describe("storage cleanup reports and local file policies", () => {
23892516 } ) ,
23902517 ) ;
23912518 const report = yield * service . runNow ;
2392- expect ( report . entries [ 0 ] ) . toMatchObject ( { outcome : "removed" , bytes : null , files : null } ) ;
2519+ expect ( report . entries [ 0 ] ) . toMatchObject ( {
2520+ outcome : "kept" ,
2521+ reason : "Worktree could not be fully inspected" ,
2522+ bytes : null ,
2523+ files : null ,
2524+ } ) ;
23932525 expect ( report . bytesFreed ) . toBe ( 0 ) ;
2394- expect ( yield * fs . exists ( worktree ) ) . toBe ( false ) ;
2526+ expect ( yield * fs . exists ( worktree ) ) . toBe ( true ) ;
23952527 } ) ,
23962528 ) ,
23972529 ) ;
0 commit comments