@@ -1273,6 +1273,87 @@ it.effect("restores a checkpoint before the first commit without staging its fil
12731273 } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
12741274) ;
12751275
1276+ it . effect ( "restores edits to skip-worktree files whose checkpoint content matches HEAD" , ( ) =>
1277+ Effect . gen ( function * ( ) {
1278+ const fileSystem = yield * FileSystem . FileSystem ;
1279+ const path = yield * Path . Path ;
1280+ const driver = yield * GitVcsDriver . makeVcsDriverShape ( ) ;
1281+ const cwd = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-skip-worktree-restore-" } ) ;
1282+ const { git, checkpointRef } = yield * makeCheckpointFixture ( driver , cwd ) ;
1283+ const skippedPath = path . join ( cwd , "skipped.txt" ) ;
1284+ yield * fileSystem . writeFileString ( skippedPath , "original\n" ) ;
1285+ yield * git ( [ "add" , "skipped.txt" ] ) ;
1286+ yield * git ( [ "commit" , "-m" , "add skipped file" ] ) ;
1287+ yield * git ( [ "update-index" , "--skip-worktree" , "skipped.txt" ] ) ;
1288+ yield * driver . checkpoints . captureCheckpoint ( { cwd, checkpointRef } ) ;
1289+ yield * fileSystem . writeFileString ( skippedPath , "later\n" ) ;
1290+
1291+ assert . isTrue (
1292+ yield * driver . checkpoints . restoreCheckpoint ( { cwd, checkpointRef, fallbackToHead : false } ) ,
1293+ ) ;
1294+
1295+ assert . strictEqual ( yield * fileSystem . readFileString ( skippedPath ) , "original\n" ) ;
1296+ } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
1297+ ) ;
1298+
1299+ it . effect ( "sparse restore rewrites manual skip-worktree files and keeps exclusions absent" , ( ) =>
1300+ Effect . gen ( function * ( ) {
1301+ const fs = yield * FileSystem . FileSystem ;
1302+ const path = yield * Path . Path ;
1303+ const liveProcess = yield * VcsProcess . VcsProcess ;
1304+ // One byte per chunk, so the index listing splits inside every record.
1305+ const driver = yield * GitVcsDriver . makeVcsDriverShape ( ) . pipe (
1306+ Effect . provideService ( VcsProcess . VcsProcess , {
1307+ run : ( input ) => {
1308+ const onStdoutChunk = input . onStdoutChunk ;
1309+ return liveProcess . run (
1310+ onStdoutChunk === undefined
1311+ ? input
1312+ : {
1313+ ...input ,
1314+ onStdoutChunk : ( chunk ) => {
1315+ for ( let index = 0 ; index < chunk . length ; index ++ )
1316+ onStdoutChunk ( chunk . subarray ( index , index + 1 ) ) ;
1317+ } ,
1318+ } ,
1319+ ) ;
1320+ } ,
1321+ } ) ,
1322+ ) ;
1323+ const cwd = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-sparse-restore-" } ) ;
1324+ const { git, checkpointRef } = yield * makeCheckpointFixture ( driver , cwd ) ;
1325+ for ( const name of [ "in/normal" , "in/skipped" , "in/s space" , "out/deep/absent" , "out/stray" ] ) {
1326+ yield * fs . makeDirectory ( path . dirname ( path . join ( cwd , name ) ) , { recursive : true } ) ;
1327+ yield * fs . writeFileString ( path . join ( cwd , name ) , "original\n" ) ;
1328+ }
1329+ yield * git ( [ "add" , "." ] ) ;
1330+ yield * git ( [ "commit" , "-m" , "sparse fixture" ] ) ;
1331+ yield * git ( [ "sparse-checkout" , "set" , "--cone" , "--sparse-index" , "in" ] ) ;
1332+ // Keeps Git from clearing the bit on files that are present.
1333+ yield * git ( [ "config" , "sparse.expectFilesOutsideOfPatterns" , "true" ] ) ;
1334+ yield * git ( [ "update-index" , "--skip-worktree" , "in/skipped" , "in/s space" ] ) ;
1335+ const captureCwd = path . join ( cwd , "in" ) ;
1336+ yield * driver . checkpoints . captureCheckpoint ( { cwd : captureCwd , checkpointRef } ) ;
1337+ yield * fs . writeFileString ( path . join ( cwd , "in/skipped" ) , "later\n" ) ;
1338+ yield * fs . writeFileString ( path . join ( cwd , "in/s space" ) , "later\n" ) ;
1339+ yield * fs . writeFileString ( path . join ( cwd , "in/normal" ) , "later\n" ) ;
1340+
1341+ for ( const restoreCwd of [ captureCwd , cwd ] ) {
1342+ assert . isTrue (
1343+ yield * driver . checkpoints . restoreCheckpoint ( {
1344+ cwd : restoreCwd ,
1345+ checkpointRef,
1346+ fallbackToHead : false ,
1347+ } ) ,
1348+ ) ;
1349+ assert . strictEqual ( yield * fs . readFileString ( path . join ( cwd , "in/skipped" ) ) , "original\n" ) ;
1350+ assert . strictEqual ( yield * fs . readFileString ( path . join ( cwd , "in/s space" ) ) , "original\n" ) ;
1351+ assert . strictEqual ( yield * fs . readFileString ( path . join ( cwd , "in/normal" ) ) , "original\n" ) ;
1352+ assert . isFalse ( yield * fs . exists ( path . join ( cwd , "out" ) ) ) ;
1353+ }
1354+ } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
1355+ ) ;
1356+
12761357// The real VCS process, spawning `command` wherever the driver runs git.
12771358const vcsProcessSpawning = ( command : string ) =>
12781359 Layer . effect (
0 commit comments