@@ -24,6 +24,19 @@ type StateRepoEnv = FileSystem.FileSystem | Path.Path | CommandExecutor.CommandE
2424
2525const resolveStateRoot = ( path : Path . Path , cwd : string ) : string => path . resolve ( defaultProjectsRoot ( cwd ) )
2626
27+ const managedRepositoryCachePaths = [ ".cache/git-mirrors" , ".cache/packages" ] as const
28+
29+ const ensureStateIgnoreAndUntrackCaches = (
30+ fs : FileSystem . FileSystem ,
31+ path : Path . Path ,
32+ root : string
33+ ) : Effect . Effect < void , CommandFailedError | PlatformError , StateRepoEnv > =>
34+ Effect . gen ( function * ( _ ) {
35+ yield * _ ( ensureStateGitignore ( fs , path , root ) )
36+ // Best-effort idempotent cleanup: keep cache artifacts out of git history.
37+ yield * _ ( git ( root , [ "rm" , "-r" , "--cached" , "--ignore-unmatch" , ...managedRepositoryCachePaths ] , gitBaseEnv ) )
38+ } ) . pipe ( Effect . asVoid )
39+
2740export const statePath : Effect . Effect < void , PlatformError , Path . Path > = Effect . gen ( function * ( _ ) {
2841 const path = yield * _ ( Path . Path )
2942 const cwd = process . cwd ( )
@@ -48,6 +61,8 @@ export const stateSync = (
4861 )
4962 }
5063
64+ yield * _ ( ensureStateIgnoreAndUntrackCaches ( fs , path , root ) )
65+
5166 const originUrlExit = yield * _ ( gitExitCode ( root , [ "remote" , "get-url" , "origin" ] , gitBaseEnv ) )
5267 if ( originUrlExit !== successExitCode ) {
5368 yield * _ ( Effect . logWarning ( `State dir has no origin remote: ${ root } ` ) )
@@ -269,11 +284,17 @@ export const statePush = Effect.gen(function*(_) {
269284
270285export const stateCommit = (
271286 message : string
272- ) : Effect . Effect < void , CommandFailedError | PlatformError , Path . Path | CommandExecutor . CommandExecutor > =>
287+ ) : Effect . Effect <
288+ void ,
289+ CommandFailedError | PlatformError ,
290+ FileSystem . FileSystem | Path . Path | CommandExecutor . CommandExecutor
291+ > =>
273292 Effect . gen ( function * ( _ ) {
293+ const fs = yield * _ ( FileSystem . FileSystem )
274294 const path = yield * _ ( Path . Path )
275295 const root = resolveStateRoot ( path , process . cwd ( ) )
276296
297+ yield * _ ( ensureStateIgnoreAndUntrackCaches ( fs , path , root ) )
277298 yield * _ ( git ( root , [ "add" , "-A" ] , gitBaseEnv ) )
278299 const diffExit = yield * _ ( gitExitCode ( root , [ "diff" , "--cached" , "--quiet" ] , gitBaseEnv ) )
279300
0 commit comments