The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
fix(server): projects read their own Git repository when the server inherited GIT_DIR (#35119)
Julius Marminge committed
Nov 12, 2026 at 02:47 UTC
80cccdcef3f22f00e25de5889bed2af9c80a3990
5 files changed
+62
-6
apps/server/src/project/RepositoryIdentityResolver.ts
+8
-3
@@ -12,7 +12,7 @@ import * as Path from "effect/Path";
12
13
import * as ProcessRunner from "../processRunner.ts";
14
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
15
-import { explicitBareRepositoryEnv } from "../vcs/VcsProcess.ts";
15
+import { explicitBareRepositoryEnv, unsetInheritedRepositoryEnv } from "../vcs/VcsProcess.ts";
16
import * as HostProcess from "@t3tools/shared/HostProcess";
17
18
const DEFAULT_REPOSITORY_IDENTITY_CACHE_CAPACITY = 512;
@@ -147,12 +147,17 @@ class RepositoryIdentityCacheKey extends Data.Class<{
147
readonly isBare: boolean;
148
}> {}
149
150
+const gitEnv = (platform: NodeJS.Platform): NodeJS.ProcessEnv => ({
151
+ ...unsetInheritedRepositoryEnv(process.env, platform),
152
+ ...explicitBareRepositoryEnv(process.env, platform),
153
+});
154
+
155
const resolveRepositoryIdentityCacheKey = Effect.fn("RepositoryIdentityResolver.resolveCacheKey")(
156
function* (cwd: string) {
157
const processRunner = yield* ProcessRunner.ProcessRunner;
158
const fileSystem = yield* FileSystem.FileSystem;
159
const path = yield* Path.Path;
155
- const env = explicitBareRepositoryEnv(process.env, yield* HostProcess.Platform);
160
+ const env = gitEnv(yield* HostProcess.Platform);
161
162
// `git -C` cannot enter a missing folder or a file, so every probe below would fail.
163
const isFolder = yield* fileSystem.stat(cwd).pipe(
@@ -241,7 +246,7 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
246
.run({
247
command: "git",
248
args: ["-C", cacheKey.rootPath, ...(cacheKey.isBare ? ["--git-dir=."] : []), "remote", "-v"],
244
- env: explicitBareRepositoryEnv(process.env, yield* HostProcess.Platform),
249
+ env: gitEnv(yield* HostProcess.Platform),
250
timeoutBehavior: "timedOutResult",
251
})
252
.pipe(Effect.option);
apps/server/src/vcs/GitVcsDriver.ts
-1
@@ -986,7 +986,6 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
986
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
987
const hostEnv = yield* HostProcess.Environment;
988
const commitEnv: NodeJS.ProcessEnv = {
989
- ...hostEnv,
989
GIT_INDEX_FILE: tempIndexPath,
990
GIT_AUTHOR_NAME: "T3 Code",
991
GIT_AUTHOR_EMAIL: "t3code@users.noreply.github.com",
apps/server/src/vcs/GitVcsDriverCore.test.ts
+20
@@ -6,6 +6,7 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
6
import * as NodeServices from "@effect/platform-node/NodeServices";
7
import * as HostProcess from "@t3tools/shared/HostProcess";
8
import { assert, it, describe } from "@effect/vitest";
9
+import { vi } from "vite-plus/test";
10
import * as Cause from "effect/Cause";
11
import * as Clock from "effect/Clock";
12
import * as Deferred from "effect/Deferred";
@@ -649,6 +650,25 @@ it.effect.each(["bare", "unborn"] as const)(
650
).pipe(Effect.provide(layerTest)),
651
);
652
653
+it.effect("reads the project's own repository when the server inherited GIT_DIR", () =>
654
+ Effect.scoped(
655
+ Effect.gen(function* () {
656
+ const path = yield* Path.Path;
657
+ const cwd = yield* makeTmpDir();
658
+ const other = yield* makeTmpDir();
659
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
660
+ yield* initRepoWithCommit(other);
661
+ yield* git(other, ["switch", "-c", "other-repository"]);
662
+ const driver = yield* GitVcsDriver.GitVcsDriver;
663
+ yield* Effect.addFinalizer(() => Effect.sync(() => vi.unstubAllEnvs()));
664
+ vi.stubEnv("GIT_DIR", path.join(other, ".git"));
665
+ assert.equal((yield* driver.statusDetailsLocal(cwd)).branch, initialBranch);
666
+ const refs = yield* driver.listRefs({ cwd });
667
+ assert.isFalse(refs.refs.some((ref) => ref.name === "other-repository"));
668
+ }),
669
+ ).pipe(Effect.provide(layerTest)),
670
+);
671
+
672
it.effect.each(["on a branch", "detached", "unborn"] as const)(
673
"reads only the repository root for review requests that ignore the branch when %s",
674
(state) =>
apps/server/src/vcs/GitVcsDriverCore.ts
+8
-2
@@ -42,7 +42,11 @@ import { resolveProjectFileBackedSetting } from "@t3tools/shared/projectSettings
42
import { gitCommandDuration, gitCommandsTotal, withMetrics } from "../observability/Metrics.ts";
43
import * as GitVcsDriver from "./GitVcsDriver.ts";
44
import { removeEmptyDirectory, type RemoveEmptyDirectoryError } from "./removeEmptyDirectory.ts";
45
-import { explicitBareRepositoryEnv, gitConfigEnv } from "./VcsProcess.ts";
45
+import {
46
+ explicitBareRepositoryEnv,
47
+ gitConfigEnv,
48
+ unsetInheritedRepositoryEnv,
49
+} from "./VcsProcess.ts";
50
import { makeWorktreeCheckoutCache } from "./worktreeCheckoutCache.ts";
51
import { removeLinkedWorktree } from "./worktreeRemoval.ts";
52
import { resolveWorktreesDirectory } from "../worktreesDirectory.ts";
@@ -993,8 +997,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
997
}),
998
),
999
);
1000
+ const hostEnv = yield* HostProcess.Environment;
1001
const baseEnv = {
997
- ...(yield* HostProcess.Environment),
1002
+ ...hostEnv,
1003
+ ...unsetInheritedRepositoryEnv(hostEnv, hostPlatform),
1004
// Concurrent status polls must not take index.lock to save refreshed indexes.
1005
GIT_OPTIONAL_LOCKS: "0",
1006
...input.env,
apps/server/src/vcs/VcsProcess.ts
+26
@@ -134,6 +134,29 @@ export const gitConfigEnv = (
134
export const explicitBareRepositoryEnv = (env: NodeJS.ProcessEnv, platform: NodeJS.Platform) =>
135
gitConfigEnv(env, "safe.bareRepository", "explicit", platform);
136
137
+const REPOSITORY_SELECTORS = new Set([
138
+ "GIT_DIR",
139
+ "GIT_WORK_TREE",
140
+ "GIT_COMMON_DIR",
141
+ "GIT_INDEX_FILE",
142
+ "GIT_OBJECT_DIRECTORY",
143
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
144
+]);
145
+
146
+/**
147
+ * Unsets repository selectors the server inherited, such as a Git hook's `GIT_DIR`, so Git finds
148
+ * the repository from cwd. Spread it before a command's own env, which may still set them.
149
+ */
150
+export const unsetInheritedRepositoryEnv = (
151
+ inherited: NodeJS.ProcessEnv,
152
+ platform: NodeJS.Platform,
153
+): NodeJS.ProcessEnv =>
154
+ Object.fromEntries(
155
+ Object.keys(inherited)
156
+ .filter((name) => REPOSITORY_SELECTORS.has(platform === "win32" ? name.toUpperCase() : name))
157
+ .map((name) => [name, undefined]),
158
+ );
159
+
160
const classifyNonZeroExit = (
161
stderr: string,
162
classifyFailure: VcsProcessInput["classifyFailure"],
@@ -210,6 +233,9 @@ export const make = Effect.gen(function* () {
233
...(input.stdin !== undefined ? { stdin: input.stdin } : {}),
234
...(input.onStdoutChunk !== undefined ? { onStdoutChunk: input.onStdoutChunk } : {}),
235
env: {
236
+ ...(input.command === "git"
237
+ ? unsetInheritedRepositoryEnv(process.env, hostPlatform)
238
+ : {}),
239
// Failures are read by English patterns; without LANG, macOS Git follows the system language.
240
// LANGUAGE leaves LC_CTYPE, which hooks inherit, alone.
241
...(input.command === "git" ? { LANGUAGE: "C" } : {}),