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 22, 23:15 UTC
fix(server): resolve git common dirs through symlinked subdirectories (#18152)
Co-authored-by: macodev00 <macodev00@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
maco committed
Oct 20, 2026 at 06:20 UTC
6e1bf41a4aaf0cb71e655dd976d1ac4ed942e404
4 files changed
+85
-2
apps/server/src/vcs/GitVcsDriver.test.ts
+49
@@ -17,6 +17,7 @@ import { assert, it } from "@effect/vitest";
17
18
import { CheckpointRef, GitCommandError, VcsProcessExitError } from "@t3tools/contracts";
19
import * as HostProcess from "@t3tools/shared/HostProcess";
20
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
21
import * as ServerConfig from "../config.ts";
22
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
23
import * as ProcessRunner from "../processRunner.ts";
@@ -196,6 +197,54 @@ it.effect("checkpoint capture skips untracked nested repositories without a comm
197
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
198
);
199
200
+it.effect.skipIf(!symlinksSupported)(
201
+ "checkpoint capture writes its index into the real git dir when cwd is a symlinked subdirectory",
202
+ () =>
203
+ Effect.gen(function* () {
204
+ const fileSystem = yield* FileSystem.FileSystem;
205
+ const path = yield* Path.Path;
206
+ const liveRunner = yield* ProcessRunner.ProcessRunner;
207
+ const indexFiles: string[] = [];
208
+ const captureProcess = yield* VcsProcess.make.pipe(
209
+ Effect.provideService(ProcessRunner.ProcessRunner, {
210
+ run: (input) => {
211
+ const indexFile = input.env?.GIT_INDEX_FILE;
212
+ if (indexFile !== undefined) indexFiles.push(indexFile);
213
+ return liveRunner.run(input);
214
+ },
215
+ }),
216
+ );
217
+ const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
218
+ Effect.provideService(VcsProcess.VcsProcess, captureProcess),
219
+ );
220
+ const sandbox = yield* fileSystem.makeTempDirectoryScoped({
221
+ prefix: "t3-checkpoint-symlink-",
222
+ });
223
+ const repo = path.join(sandbox, "repo");
224
+ const subdir = path.join(repo, "sub", "dir");
225
+ const link = path.join(sandbox, "nest", "link");
226
+ yield* fileSystem.makeDirectory(subdir, { recursive: true });
227
+ yield* fileSystem.makeDirectory(path.dirname(link), { recursive: true });
228
+ yield* fileSystem.symlink(subdir, link);
229
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, repo);
230
+ // Git returns ../../.git from the target; resolving it against the link reaches the decoy.
231
+ yield* git(["-C", sandbox, "init"]);
232
+ yield* fileSystem.writeFileString(path.join(subdir, "nested.txt"), "from-link\n");
233
+ const realCommonDir = yield* fileSystem.realPath(path.join(repo, ".git"));
234
+
235
+ yield* driver.checkpoints.captureCheckpoint({ cwd: link, checkpointRef });
236
+
237
+ assert.isTrue(indexFiles.length > 0);
238
+ for (const indexFile of indexFiles) {
239
+ assert.strictEqual(yield* fileSystem.realPath(path.dirname(indexFile)), realCommonDir);
240
+ }
241
+ assert.strictEqual(
242
+ (yield* git(["show", `${checkpointRef}:sub/dir/nested.txt`])).stdout,
243
+ "from-link\n",
244
+ );
245
+ }).pipe(Effect.scoped, Effect.provide(layerGitCaptureContract)),
246
+);
247
+
248
it.effect("checkpoint capture keeps the shared index a split index still uses", () =>
249
Effect.gen(function* () {
250
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/vcs/GitVcsDriver.ts
+4
-1
@@ -788,6 +788,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
788
}),
789
);
790
791
+ // Git reports relative paths from the physical cwd, which can differ from a symlink.
792
const resolveGitCommonDir = Effect.fn("GitVcsDriver.resolveGitCommonDir")(function* (
793
cwd: string,
794
) {
@@ -797,7 +798,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
798
args: ["rev-parse", "--git-common-dir"],
799
});
800
const gitCommonDir = result.stdout.trim();
800
- return path.isAbsolute(gitCommonDir) ? gitCommonDir : path.resolve(cwd, gitCommonDir);
801
+ if (path.isAbsolute(gitCommonDir)) return gitCommonDir;
802
+ const physicalCwd = yield* fileSystem.realPath(cwd).pipe(Effect.orElseSucceed(() => cwd));
803
+ return path.resolve(physicalCwd, gitCommonDir);
804
});
805
806
// Git renames loose objects and refs into place without fsync by default, so
apps/server/src/vcs/GitVcsDriverCore.test.ts
+29
@@ -30,6 +30,7 @@ import {
30
type ReviewDiffPreviewResult,
31
type WorktreeSubmodules,
32
} from "@t3tools/contracts";
33
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
34
import * as ServerConfig from "../config.ts";
35
import { gitCommandDuration } from "../observability/Metrics.ts";
36
import {
@@ -3153,6 +3154,34 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3154
}),
3155
);
3156
3157
+ it.effect.skipIf(!symlinksSupported)(
3158
+ "lists the real repository through a symlink when a decoy repo occupies the lexical common dir",
3159
+ () =>
3160
+ Effect.gen(function* () {
3161
+ const fileSystem = yield* FileSystem.FileSystem;
3162
+ const pathService = yield* Path.Path;
3163
+ const sandbox = yield* makeTmpDir("git-symlink-subdir-");
3164
+ yield* initRepoWithCommit(sandbox);
3165
+ yield* git(sandbox, ["branch", "-M", "decoy-only"]);
3166
+ const repo = pathService.join(sandbox, "repo");
3167
+ const link = pathService.join(sandbox, "nest", "link");
3168
+ yield* fileSystem.makeDirectory(pathService.join(repo, "sub", "dir"), {
3169
+ recursive: true,
3170
+ });
3171
+ yield* fileSystem.makeDirectory(pathService.dirname(link), { recursive: true });
3172
+ yield* fileSystem.symlink(pathService.join(repo, "sub", "dir"), link);
3173
+
3174
+ yield* initRepoWithCommit(repo);
3175
+ yield* git(repo, ["checkout", "-b", "real-only"]);
3176
+
3177
+ // The decoy must exist before the first lookup, which caches repository paths.
3178
+ const refs = yield* (yield* GitVcsDriver.GitVcsDriver).listRefs({ cwd: link });
3179
+ assert.isTrue(refs.isRepo);
3180
+ assert.isFalse(refs.refs.some((ref) => ref.name === "decoy-only"));
3181
+ assert.isTrue(refs.refs.some((ref) => ref.name === "real-only"));
3182
+ }),
3183
+ );
3184
+
3185
it.effect("reads Changes totals with untracked files when requested", () =>
3186
Effect.gen(function* () {
3187
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+3
-1
@@ -1324,6 +1324,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1324
const resolveRepositoryPathsUncached = Effect.fn("resolveRepositoryPathsUncached")(function* (
1325
cwd: string,
1326
) {
1327
+ // Git reports relative paths from the physical cwd, which can differ from a symlink.
1328
const commonDirResult = yield* executeGitWithStableDiagnostics(
1329
"GitVcsDriver.resolveRepositoryPaths.commonDir",
1330
cwd,
@@ -1352,9 +1353,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1353
}
1354
1355
const commonDirOutput = commonDirResult.stdout.trim();
1356
+ const physicalCwd = yield* fileSystem.realPath(cwd).pipe(Effect.orElseSucceed(() => cwd));
1357
const resolvedGitCommonDir = path.isAbsolute(commonDirOutput)
1358
? path.normalize(commonDirOutput)
1357
- : path.resolve(cwd, commonDirOutput);
1359
+ : path.resolve(physicalCwd, commonDirOutput);
1360
const gitCommonDir = yield* fileSystem
1361
.realPath(resolvedGitCommonDir)
1362
.pipe(Effect.orElseSucceed(() => resolvedGitCommonDir));