@@ -17,6 +17,7 @@ import { assert, it } from "@effect/vitest";
1717
1818import { CheckpointRef , GitCommandError , VcsProcessExitError } from "@t3tools/contracts" ;
1919import * as HostProcess from "@t3tools/shared/HostProcess" ;
20+ import { symlinksSupported } from "@t3tools/shared/testing/symlinks" ;
2021import * as ServerConfig from "../config.ts" ;
2122import * as CheckpointStore from "../checkpointing/CheckpointStore.ts" ;
2223import * as ProcessRunner from "../processRunner.ts" ;
@@ -196,6 +197,54 @@ it.effect("checkpoint capture skips untracked nested repositories without a comm
196197 } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
197198) ;
198199
200+ it . effect . skipIf ( ! symlinksSupported ) (
201+ "checkpoint capture writes its index into the real git dir when cwd is a symlinked subdirectory" ,
202+ ( ) =>
203+ Effect . gen ( function * ( ) {
204+ const fileSystem = yield * FileSystem . FileSystem ;
205+ const path = yield * Path . Path ;
206+ const liveRunner = yield * ProcessRunner . ProcessRunner ;
207+ const indexFiles : string [ ] = [ ] ;
208+ const captureProcess = yield * VcsProcess . make . pipe (
209+ Effect . provideService ( ProcessRunner . ProcessRunner , {
210+ run : ( input ) => {
211+ const indexFile = input . env ?. GIT_INDEX_FILE ;
212+ if ( indexFile !== undefined ) indexFiles . push ( indexFile ) ;
213+ return liveRunner . run ( input ) ;
214+ } ,
215+ } ) ,
216+ ) ;
217+ const driver = yield * GitVcsDriver . makeVcsDriverShape ( ) . pipe (
218+ Effect . provideService ( VcsProcess . VcsProcess , captureProcess ) ,
219+ ) ;
220+ const sandbox = yield * fileSystem . makeTempDirectoryScoped ( {
221+ prefix : "t3-checkpoint-symlink-" ,
222+ } ) ;
223+ const repo = path . join ( sandbox , "repo" ) ;
224+ const subdir = path . join ( repo , "sub" , "dir" ) ;
225+ const link = path . join ( sandbox , "nest" , "link" ) ;
226+ yield * fileSystem . makeDirectory ( subdir , { recursive : true } ) ;
227+ yield * fileSystem . makeDirectory ( path . dirname ( link ) , { recursive : true } ) ;
228+ yield * fileSystem . symlink ( subdir , link ) ;
229+ const { git, checkpointRef } = yield * makeCheckpointFixture ( driver , repo ) ;
230+ // Git returns ../../.git from the target; resolving it against the link reaches the decoy.
231+ yield * git ( [ "-C" , sandbox , "init" ] ) ;
232+ yield * fileSystem . writeFileString ( path . join ( subdir , "nested.txt" ) , "from-link\n" ) ;
233+ const realCommonDir = yield * fileSystem . realPath ( path . join ( repo , ".git" ) ) ;
234+
235+ yield * driver . checkpoints . captureCheckpoint ( { cwd : link , checkpointRef } ) ;
236+
237+ assert . isTrue ( indexFiles . length > 0 ) ;
238+ for ( const indexFile of indexFiles ) {
239+ assert . strictEqual ( yield * fileSystem . realPath ( path . dirname ( indexFile ) ) , realCommonDir ) ;
240+ }
241+ assert . strictEqual (
242+ ( yield * git ( [ "show" , `${ checkpointRef } :sub/dir/nested.txt` ] ) ) . stdout ,
243+ "from-link\n" ,
244+ ) ;
245+ } ) . pipe ( Effect . scoped , Effect . provide ( layerGitCaptureContract ) ) ,
246+ ) ;
247+
199248it . effect ( "checkpoint capture keeps the shared index a split index still uses" , ( ) =>
200249 Effect . gen ( function * ( ) {
201250 const fileSystem = yield * FileSystem . FileSystem ;
0 commit comments