@@ -151,6 +151,49 @@ for (const timestamp of [1_700_000_000, 1_700_000_000.9999]) {
151151 ) ;
152152}
153153
154+ it . effect ( "checkpoint capture preserves racy edits made after resetting the index" , ( ) =>
155+ Effect . gen ( function * ( ) {
156+ const fileSystem = yield * FileSystem . FileSystem ;
157+ const path = yield * Path . Path ;
158+ const liveProcess = yield * VcsProcess . VcsProcess ;
159+ const driver = yield * GitVcsDriver . makeVcsDriverShape ( ) ;
160+ const cwd = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-checkpoint-racy-reset-" } ) ;
161+ const { git, checkpointRef } = yield * makeCheckpointFixture ( driver , cwd ) ;
162+ const racyPath = path . join ( cwd , "racy.txt" ) ;
163+ const indexPath = path . join ( cwd , ".git" , "index" ) ;
164+ const timestamp = 1_700_000_000 ;
165+ yield * git ( [ "config" , "core.trustctime" , "false" ] ) ;
166+ yield * fileSystem . writeFileString ( racyPath , "before\n" ) ;
167+ yield * fileSystem . utimes ( racyPath , timestamp , timestamp ) ;
168+ yield * git ( [ "add" , "." ] ) ;
169+ yield * git ( [ "commit" , "-m" , "record racy file" ] ) ;
170+ yield * fileSystem . writeFileString ( path . join ( cwd , "file.txt" ) , "staged\n" ) ;
171+ yield * git ( [ "add" , "file.txt" ] ) ;
172+ yield * fileSystem . utimes ( indexPath , timestamp , timestamp ) ;
173+ const originalIndex = yield * fileSystem . readFile ( indexPath ) ;
174+ const originalIndexMtime = ( yield * fileSystem . stat ( indexPath ) ) . mtime ;
175+ const captureDriver = yield * GitVcsDriver . makeVcsDriverShape ( ) . pipe (
176+ Effect . provideService ( VcsProcess . VcsProcess , {
177+ run : Effect . fn ( function * ( input : VcsProcess . VcsProcessInput ) {
178+ const result = yield * liveProcess . run ( input ) ;
179+ if ( input . args . includes ( "read-tree" ) && input . args . includes ( "--reset" ) ) {
180+ yield * fileSystem . writeFileString ( racyPath , "after!\n" ) . pipe ( Effect . orDie ) ;
181+ yield * fileSystem . utimes ( racyPath , timestamp , timestamp ) . pipe ( Effect . orDie ) ;
182+ }
183+ return result ;
184+ } ) ,
185+ } ) ,
186+ ) ;
187+
188+ yield * captureDriver . checkpoints . captureCheckpoint ( { cwd, checkpointRef } ) ;
189+
190+ assert . strictEqual ( ( yield * git ( [ "show" , `${ checkpointRef } :racy.txt` ] ) ) . stdout , "after!\n" ) ;
191+ assert . strictEqual ( ( yield * git ( [ "show" , `${ checkpointRef } :file.txt` ] ) ) . stdout , "staged\n" ) ;
192+ assert . deepEqual ( yield * fileSystem . readFile ( indexPath ) , originalIndex ) ;
193+ assert . deepEqual ( ( yield * fileSystem . stat ( indexPath ) ) . mtime , originalIndexMtime ) ;
194+ } ) . pipe ( Effect . scoped , Effect . provide ( GitContractLayer ) ) ,
195+ ) ;
196+
154197for ( const nested of [ false , true ] ) {
155198 for ( const indexMode of [ "normal" , "flags" , "split" ] as const ) {
156199 it . effect (
0 commit comments