@@ -74,33 +74,26 @@ const make = Effect.gen(function* () {
7474 // seconds, and the user is writing their description meanwhile.
7575 const serviceScope = yield * Effect . scope ;
7676
77- const cloneSource = Effect . fn ( "TriageService.cloneSource" ) ( function * ( ref : string ) {
77+ // Fetches the exact commit `ls-remote` resolved, so the folder the session
78+ // names is the one that appears even when main moves meanwhile.
79+ const cloneSource = Effect . fn ( "TriageService.cloneSource" ) ( function * ( commit : string ) {
7880 const staging = yield * fs . makeTempDirectory ( { directory : sourceDir , prefix : ".clone-" } ) ;
81+ const directory = path . join ( sourceDir , commit ) ;
7982 yield * Effect . gen ( function * ( ) {
83+ yield * runGit ( "initSource" , staging , [ "init" , "--quiet" ] , 10_000 ) ;
8084 yield * runGit (
81- "cloneSource" ,
82- sourceDir ,
83- [
84- "clone" ,
85- "--depth" ,
86- "1" ,
87- "--filter=blob:none" ,
88- "--branch" ,
89- ref ,
90- "--" ,
91- T3CODE_REPOSITORY_URL ,
92- staging ,
93- ] ,
94- 600_000 ,
95- ) ;
96- // main can move between ls-remote and clone, so name the folder by what landed.
97- const commit = ( yield * runGit (
98- "readSourceCommit" ,
85+ "addSourceRemote" ,
9986 staging ,
100- [ "rev-parse " , "HEAD" ] ,
87+ [ "remote " , "add" , "origin" , T3CODE_REPOSITORY_URL ] ,
10188 10_000 ,
102- ) ) . stdout . trim ( ) ;
103- const directory = path . join ( sourceDir , commit ) ;
89+ ) ;
90+ yield * runGit (
91+ "fetchSource" ,
92+ staging ,
93+ [ "fetch" , "--depth" , "1" , "--filter=blob:none" , "origin" , commit ] ,
94+ 600_000 ,
95+ ) ;
96+ yield * runGit ( "checkoutSource" , staging , [ "checkout" , "--quiet" , "FETCH_HEAD" ] , 600_000 ) ;
10497 yield * fs . rename ( staging , directory ) . pipe (
10598 // A concurrent session cloned the same commit first; keep theirs.
10699 Effect . catch ( ( error ) =>
@@ -139,7 +132,7 @@ const make = Effect.gen(function* () {
139132 if ( yield * fs . exists ( directory ) ) {
140133 return { _tag : "cloned" , directory, serverVersion, ...source } as const ;
141134 }
142- yield * cloneSource ( source . ref ) . pipe (
135+ yield * cloneSource ( source . commit ) . pipe (
143136 Effect . ignoreCause ( { log : true } ) ,
144137 Effect . forkIn ( serviceScope ) ,
145138 ) ;
0 commit comments