Public: anyone can read this; the crew can change it.
A workspace's dev checkout is synced with the forge's own git, never the operator's environment #17318
Merged 31h 48m ago, live in production
fix/dev-launch-server-git → main 0 commits
2 files
changed +62
−4
src/apps/dev_launch.ts +4 −4
| @@ -15,7 +15,7 @@ import type { App } from "../app.ts"; | ||
| 15 | 15 | import type { AppRecord } from "../core/apps.ts"; |
| 16 | 16 | import type { Repo } from "../core/repos.ts"; |
| 17 | 17 | import { repoDir } from "../git/repos.ts"; |
| 18 | import { runLocal } from "../git/local.ts"; | |
| 18 | import { runGit } from "../git/env.ts"; | |
| 19 | 19 | import { resolveOid } from "../git/merge.ts"; |
| 20 | 20 | import { isSafeRef } from "../git/guard.ts"; |
| 21 | 21 | import { err, ok, type Result } from "../kernel/result.ts"; |
| @@ -51,12 +51,12 @@ export async function syncCheckout(bare: string, dir: string, branch: string): P | ||
| 51 | 51 | const cloned = await Bun.file(join(dir, ".git", "HEAD")).exists(); |
| 52 | 52 | if (!cloned) { |
| 53 | 53 | await mkdir(join(dir, ".."), { recursive: true }); |
| 54 | const made = await runLocal(["clone", "--quiet", "--no-hardlinks", "--no-checkout", bare, dir], { cwd: join(dir, "..") }); | |
| 54 | const made = await runGit(["clone", "--quiet", "--no-hardlinks", "--no-checkout", bare, dir], { cwd: join(dir, "..") }); | |
| 55 | 55 | if (!made.ok) return err("could not check the branch out"); |
| 56 | 56 | } |
| 57 | const got = await runLocal(["fetch", "--quiet", bare, `+refs/heads/${branch}:refs/remotes/dev/head`], { cwd: dir }); | |
| 57 | const got = await runGit(["fetch", "--quiet", bare, `+refs/heads/${branch}:refs/remotes/dev/head`], { cwd: dir }); | |
| 58 | 58 | if (!got.ok) return err("could not read the branch"); |
| 59 | const set = await runLocal(["reset", "--quiet", "--hard", tip], { cwd: dir }); | |
| 59 | const set = await runGit(["reset", "--quiet", "--hard", tip], { cwd: dir }); | |
| 60 | 60 | return set.ok ? ok(tip) : err("could not check the branch out"); |
| 61 | 61 | } |
| 62 | 62 |
test/dev-launch-git-env.test.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** | |
| 2 | * A workspace's dev checkout is synced with the forge's own git (`syncCheckout`, apps/dev_launch.ts): | |
| 3 | * the scrubbed environment of git/env.ts, never the operator's (#14780). A forge process that read | |
| 4 | * the operator's ~/.gitconfig would carry their settings, credential helpers and identity into a | |
| 5 | * person's checkout. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { syncCheckout } from "../src/apps/dev_launch.ts"; | |
| 12 | ||
| 13 | let dir = ""; | |
| 14 | const priorHome = process.env["HOME"]; // env-restored: afterAll | |
| 15 | const priorGlobal = process.env["GIT_CONFIG_GLOBAL"]; // env-restored: afterAll | |
| 16 | ||
| 17 | const git = (cwd: string, ...args: string[]): void => { | |
| 18 | const done = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { | |
| 19 | cwd, | |
| 20 | env: { PATH: process.env["PATH"] ?? "", HOME: "/dev/null", GIT_CONFIG_GLOBAL: "/dev/null" }, | |
| 21 | stdout: "ignore", | |
| 22 | stderr: "pipe", | |
| 23 | }); | |
| 24 | if (done.exitCode !== 0) throw new Error(`git ${args.join(" ")}: ${done.stderr.toString()}`); | |
| 25 | }; | |
| 26 | ||
| 27 | beforeAll(() => { | |
| 28 | dir = mkdtempSync(join(tmpdir(), "dev-launch-git-env-")); | |
| 29 | const work = join(dir, "work"); | |
| 30 | mkdirSync(work); | |
| 31 | git(work, "init", "-q", "-b", "main"); | |
| 32 | writeFileSync(join(work, "README.md"), "# app\n"); | |
| 33 | git(work, "add", "-A"); | |
| 34 | git(work, "commit", "-qm", "first"); | |
| 35 | git(dir, "clone", "-q", "--bare", work, join(dir, "app.git")); | |
| 36 | // An operator's own settings, where an inheriting git reads them: a clone names its remote by them. | |
| 37 | const home = join(dir, "home"); | |
| 38 | mkdirSync(home); | |
| 39 | writeFileSync(join(home, ".gitconfig"), "[clone]\n\tdefaultRemoteName = operators-own\n"); | |
| 40 | process.env["HOME"] = home; // env-restored: afterAll | |
| 41 | delete process.env["GIT_CONFIG_GLOBAL"]; // env-restored: afterAll | |
| 42 | }); | |
| 43 | afterAll(() => { | |
| 44 | if (priorHome === undefined) delete process.env["HOME"]; | |
| 45 | else process.env["HOME"] = priorHome; | |
| 46 | if (priorGlobal === undefined) delete process.env["GIT_CONFIG_GLOBAL"]; | |
| 47 | else process.env["GIT_CONFIG_GLOBAL"] = priorGlobal; | |
| 48 | rmSync(dir, { recursive: true, force: true }); | |
| 49 | }); | |
| 50 | ||
| 51 | test("a dev checkout is cloned and synced without the operator's git settings", async () => { | |
| 52 | const checkout = join(dir, "cells", "main"); | |
| 53 | const synced = await syncCheckout(join(dir, "app.git"), checkout, "main"); | |
| 54 | expect(synced.ok).toBe(true); | |
| 55 | const config = readFileSync(join(checkout, ".git", "config"), "utf8"); | |
| 56 | expect(config).not.toContain("operators-own"); | |
| 57 | expect(config).toContain('[remote "origin"]'); | |
| 58 | }); |
new above
offline