@@ -205,34 +205,55 @@ function runGit(
205205 } ) ;
206206}
207207
208+ /** A committed repository and an empty bare remote, built once and copied into each test. */
209+ class GitFixtureTemplates extends Context . Service <
210+ GitFixtureTemplates ,
211+ { readonly repo : string ; readonly bareRemote : string }
212+ > ( ) ( "t3/git/GitManager.test/GitFixtureTemplates" ) { }
213+
214+ const layerGitFixtureTemplates = Layer . effect (
215+ GitFixtureTemplates ,
216+ Effect . gen ( function * ( ) {
217+ const fs = yield * FileSystem . FileSystem ;
218+ const repo = yield * makeTempDir ( "t3code-git-template-" ) ;
219+ // An empty template skips copying git's sample hooks into every test repository.
220+ yield * runGit ( repo , [ "init" , "--initial-branch=main" , "--template=" ] ) ;
221+ yield * runGit ( repo , [ "config" , "user.email" , "[email protected] " ] ) ; 222+ yield * runGit ( repo , [ "config" , "user.name" , "Test User" ] ) ;
223+ // Override global autocrlf on Windows for LF assertions, including linked worktrees.
224+ yield * runGit ( repo , [ "config" , "core.autocrlf" , "false" ] ) ;
225+ yield * fs . writeFileString ( NodePath . join ( repo , "README.md" ) , "hello\n" ) ;
226+ yield * runGit ( repo , [ "add" , "README.md" ] ) ;
227+ yield * runGit ( repo , [ "commit" , "-m" , "Initial commit" ] ) ;
228+ const bareRemote = yield * makeTempDir ( "t3code-git-remote-template-" ) ;
229+ yield * runGit ( bareRemote , [ "init" , "--bare" , "--template=" ] ) ;
230+ yield * fs . makeDirectory ( NodePath . join ( bareRemote , "hooks" ) , { recursive : true } ) ;
231+ return { repo, bareRemote } ;
232+ } ) ,
233+ ) ;
234+
208235function initRepo (
209236 cwd : string ,
210- ) : Effect . Effect <
211- void ,
212- PlatformError . PlatformError | GitCommandError ,
213- FileSystem . FileSystem | Scope . Scope | GitVcsDriver . GitVcsDriver
214- > {
237+ ) : Effect . Effect < void , PlatformError . PlatformError , FileSystem . FileSystem | GitFixtureTemplates > {
215238 return Effect . gen ( function * ( ) {
216239 const fs = yield * FileSystem . FileSystem ;
217- yield * runGit ( cwd , [ "init" , "--initial-branch=main" ] ) ;
218- yield * runGit ( cwd , [ "config" , "user.email" , "[email protected] " ] ) ; 219- yield * runGit ( cwd , [ "config" , "user.name" , "Test User" ] ) ;
220- // Override global autocrlf on Windows for LF assertions, including linked worktrees.
221- yield * runGit ( cwd , [ "config" , "core.autocrlf" , "false" ] ) ;
222- yield * fs . writeFileString ( NodePath . join ( cwd , "README.md" ) , "hello\n" ) ;
223- yield * runGit ( cwd , [ "add" , "README.md" ] ) ;
224- yield * runGit ( cwd , [ "commit" , "-m" , "Initial commit" ] ) ;
240+ const templates = yield * GitFixtureTemplates ;
241+ for ( const entry of [ ".git" , "README.md" ] ) {
242+ yield * fs . copy ( NodePath . join ( templates . repo , entry ) , NodePath . join ( cwd , entry ) ) ;
243+ }
225244 } ) ;
226245}
227246
228247function createBareRemote ( ) : Effect . Effect <
229248 string ,
230- PlatformError . PlatformError | GitCommandError ,
231- FileSystem . FileSystem | Scope . Scope | GitVcsDriver . GitVcsDriver
249+ PlatformError . PlatformError ,
250+ FileSystem . FileSystem | Scope . Scope | GitFixtureTemplates
232251> {
233252 return Effect . gen ( function * ( ) {
253+ const fs = yield * FileSystem . FileSystem ;
254+ const templates = yield * GitFixtureTemplates ;
234255 const remoteDir = yield * makeTempDir ( "t3code-git-remote-" ) ;
235- yield * runGit ( remoteDir , [ "init" , "--bare" ] ) ;
256+ yield * fs . copy ( templates . bareRemote , remoteDir , { overwrite : true } ) ;
236257 return remoteDir ;
237258 } ) ;
238259}
@@ -740,7 +761,8 @@ function makeManager(input?: {
740761
741762const asThreadId = ( threadId : string ) => threadId as ThreadId ;
742763
743- const layerGitManagerTest = GitVcsDriver . layer . pipe (
764+ const layerGitManagerTest = layerGitFixtureTemplates . pipe (
765+ Layer . provideMerge ( GitVcsDriver . layer ) ,
744766 Layer . provide ( ServerConfig . layerTest ( process . cwd ( ) , { prefix : "t3-git-manager-test-" } ) ) ,
745767 Layer . provideMerge ( VcsProcess . layer ) ,
746768 Layer . provideMerge ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ,
0 commit comments