Skip to content

Commit d5afca2

Browse files
committed
fix(state): keep shared caches out of state git sync
1 parent 05a2b2e commit d5afca2

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

packages/lib/src/usecases/projects-delete.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CommandExecutor } from "@effect/platform/CommandExecutor"
1+
import type * as CommandExecutor from "@effect/platform/CommandExecutor"
22
import type { PlatformError } from "@effect/platform/Error"
33
import * as FileSystem from "@effect/platform/FileSystem"
44
import * as Path from "@effect/platform/Path"
@@ -67,7 +67,11 @@ const removeContainersFallback = (
6767
// COMPLEXITY: O(docker + fs)
6868
export const deleteDockerGitProject = (
6969
item: ProjectItem
70-
): Effect.Effect<void, PlatformError | DockerCommandError, FileSystem.FileSystem | Path.Path | CommandExecutor> =>
70+
): Effect.Effect<
71+
void,
72+
PlatformError | DockerCommandError,
73+
FileSystem.FileSystem | Path.Path | CommandExecutor.CommandExecutor
74+
> =>
7175
Effect.gen(function*(_) {
7276
const fs = yield* _(FileSystem.FileSystem)
7377
const path = yield* _(Path.Path)

packages/lib/src/usecases/state-repo.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ type StateRepoEnv = FileSystem.FileSystem | Path.Path | CommandExecutor.CommandE
2424

2525
const 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+
2740
export 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

270285
export 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

Comments
 (0)