Skip to content
Myr

git.ts

This file

Path

packages/testkit/src/git.ts

68 lines · 2.0 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–68why, one step back
1import { Effect, Stream } from "effect";
2import type { Scope } from "effect";3import { ChildProcess, ChildProcessSpawner } from "effect/process";45export interface Ran {6 readonly exitCode: number;7 readonly stdout: string;8 readonly stderr: string;9}1011// Fixed identity and dates, English messages, and no config from this machine.12const env = {13 GIT_AUTHOR_DATE: "2026-10-06T12:00:00Z",14 GIT_AUTHOR_EMAIL: "answerer@example.com",15 GIT_AUTHOR_NAME: "Answerer",16 GIT_COMMITTER_DATE: "2026-10-06T12:00:00Z",17 GIT_COMMITTER_EMAIL: "answerer@example.com",18 GIT_COMMITTER_NAME: "Answerer",19 GIT_CONFIG_GLOBAL: "/dev/null",20 GIT_CONFIG_NOSYSTEM: "1",21 GIT_TERMINAL_PROMPT: "0",22 LC_ALL: "C",23};2425const text = <E>(bytes: Stream.Stream<Uint8Array, E>) =>26 bytes.pipe(Stream.decodeText(), Stream.mkString);2728export const spawn = (29 command: string,30 args: readonly string[],31 options: ChildProcess.CommandOptions32): Effect.Effect<33 ChildProcessSpawner.ChildProcessHandle,34 never,35 ChildProcessSpawner.ChildProcessSpawner | Scope.Scope36> =>37 Effect.flatMap(ChildProcessSpawner.ChildProcessSpawner, (spawner) =>38 spawner.spawn(39 ChildProcess.make(command, args, {40 ...options,41 env: { ...env, ...options.env },42 extendEnv: true,43 })44 )45 ).pipe(Effect.orDie);4647export const git = (cwd: string, ...args: string[]) =>48 Effect.scoped(49 Effect.gen(function* () {50 const child = yield* spawn("git", args, { cwd });5152 const [stdout, stderr, exitCode] = yield* Effect.all(53 [text(child.stdout), text(child.stderr), child.exitCode],54 { concurrency: "unbounded" }55 ).pipe(Effect.orDie);5657 return { exitCode, stderr, stdout } satisfies Ran;58 })59 );6061export const gitOk = (cwd: string, ...args: string[]) =>62 Effect.flatMap(git(cwd, ...args), (ran) =>63 ran.exitCode === 064 ? Effect.succeed(ran.stdout.trim())65 : Effect.die(66 `git ${args.join(" ")} exited ${ran.exitCode}: ${ran.stderr}`67 )68 );