TypeScript
fix(server): git hooks keep the user's locale (#27778)
Julius Marmingeacd2db9c5e16
diff --git a/apps/server/src/sourceControl/SourceControlRepositoryService.ts b/apps/server/src/sourceControl/SourceControlRepositoryService.tsindex 44d31a43b69..1e9c48893da 100644--- a/apps/server/src/sourceControl/SourceControlRepositoryService.ts+++ b/apps/server/src/sourceControl/SourceControlRepositoryService.ts@@ -79,7 +79,8 @@ const CLONE_ENV = {// Force piped progress immediately; refuse credential prompts that would hang without a tty.GIT_PROGRESS_DELAY: "0",GIT_TERMINAL_PROMPT: "0",- LC_ALL: "C",+ // English progress without overriding LC_CTYPE, which a global post-checkout hook inherits.+ LANGUAGE: "C",} satisfies NodeJS.ProcessEnv;function mapRepositoryError(operation: string, provider: SourceControlProviderKind) {diff --git a/apps/server/src/triage/TriageService.ts b/apps/server/src/triage/TriageService.tsindex f7a93f24a66..14d12c0af9e 100644--- a/apps/server/src/triage/TriageService.ts+++ b/apps/server/src/triage/TriageService.ts@@ -23,7 +23,8 @@ const T3CODE_REPOSITORY_URL = "https://github.com/pingdotgg/t3code";const GIT_ENV = {GIT_TERMINAL_PROMPT: "0",GIT_ASKPASS: "",- LC_ALL: "C",+ // English messages without overriding LC_CTYPE, which a global post-checkout hook inherits.+ LANGUAGE: "C",} satisfies NodeJS.ProcessEnv;/** Starts in-app triage sessions: the same files `t3 triage` writes, plus a source clone. */diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex ebfc4866c57..53d031a7413 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -1439,7 +1439,7 @@ it.effect.each([return yield* Effect.die("expected Git command");if (command.args[0] !== "fetch") return makeNonRepositoryHandle();assert.deepEqual(command.args, ["fetch", "--quiet", "--", "origin"]);- assert.equal(command.options.env?.LC_ALL, "C");+ assert.equal(command.options.env?.LANGUAGE, "C");assert.equal(command.options.env?.GIT_TERMINAL_PROMPT, "0");yield* Ref.update(attempts, (count) => count + 1);return ChildProcessSpawner.makeHandle({@@ -1863,7 +1863,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {command.args[0] === "branch" ||command.args[0] === "checkout")) {- locales.push(command.options.env?.LC_ALL);+ locales.push(command.options.env?.LANGUAGE);}return delegate.spawn(command);});@@ -4282,6 +4282,38 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {}}),);++ // regression: #27749 hooks inherited the driver's forced LC_ALL=C+ it.effect("runs post-checkout hooks under the server's own locale", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ const { initialBranch } = yield* initRepoWithCommit(cwd);+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const driver = yield* GitVcsDriver.GitVcsDriver;+ const serverLocale = process.env.LC_ALL ?? "unset";+ const seenLocale = path.join(yield* makeTmpDir("git-hook-locale-"), "lc-all");+ yield* writeTextFile(+ cwd,+ "hooks/post-checkout",+ `#!/bin/sh\necho "\${LC_ALL-unset}" > '${seenLocale}'\n[ "\${LC_ALL-unset}" = '${serverLocale}' ]\n`,+ );+ yield* fs.chmod(path.join(cwd, "hooks/post-checkout"), 0o755);+ yield* git(cwd, ["config", "core.hooksPath", path.join(cwd, "hooks")]);+ const worktreePath = path.join(yield* makeTmpDir("git-worktrees-"), "locale");++ const result = yield* driver+ .createWorktree({ cwd, path: worktreePath, refName: initialBranch, newRefName: "locale" })+ .pipe(Effect.result);++ assert.equal(+ (yield* fs.readFileString(seenLocale)).trim(),+ serverLocale,+ "post-checkout hook should see the server's LC_ALL",+ );+ assert.isTrue(Result.isSuccess(result), "worktree creation failed in the hook");+ }),+ );it.effect.each(["commit", "short-commit", "tag", "revision"] as const)("creates a worktree from a %s without recording it as a PR base",(kind) =>diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex dbccb877553..4ace91f8017 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -1186,7 +1186,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*...options,env: {...options.env,- LC_ALL: "C",+ // English diagnostics without overriding LC_CTYPE, which hooks inherit.+ LANGUAGE: "C",},});@@ -4303,7 +4304,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*timeoutMs: null,...(onSubmoduleLine? {- env: { LC_ALL: "C" },+ env: { LANGUAGE: "C" },progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },}: {}),