Skip to content

Commit db2e6c8

Browse files
K3iraraclaude
andcommitted
fix(server): checkpoints work in Windows workspaces with paths over 260 characters
Git for Windows cannot open paths longer than MAX_PATH unless core.longpaths is on, and it is off by default. In such a workspace, checkpoint capture's `git add -A` exited 128 with "Filename too long", so every turn failed to checkpoint. Checkpoint commands that read or write the working tree now pass `-c core.longpaths=true` on Windows. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d4a3345 commit db2e6c8

2 files changed

Lines changed: 69 additions & 4 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
1515
import { assert, it } from "@effect/vitest";
1616

1717
import { CheckpointRef, GitCommandError, VcsProcessExitError } from "@t3tools/contracts";
18+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
1819
import * as ServerConfig from "../config.ts";
1920
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
2021
import * as ProcessRunner from "../processRunner.ts";
@@ -1116,3 +1117,41 @@ it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publi
11161117
),
11171118
);
11181119
});
1120+
1121+
it.effect.each(["win32", "linux"] as const)(
1122+
"checkpoint working-tree commands enable Git long paths only on Windows (%s)",
1123+
(platform) =>
1124+
Effect.gen(function* () {
1125+
const fs = yield* FileSystem.FileSystem;
1126+
const path = yield* Path.Path;
1127+
const liveProcess = yield* VcsProcess.VcsProcess;
1128+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
1129+
const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-long-paths-" });
1130+
const { checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
1131+
const observedArgs: ReadonlyArray<string>[] = [];
1132+
const platformDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
1133+
Effect.provideService(HostProcessPlatform, platform),
1134+
Effect.provideService(VcsProcess.VcsProcess, {
1135+
run: (input) => {
1136+
observedArgs.push(input.args);
1137+
return liveProcess.run(input);
1138+
},
1139+
}),
1140+
);
1141+
1142+
yield* platformDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
1143+
yield* fs.writeFileString(path.join(cwd, "file.txt"), "changed\n");
1144+
assert.isTrue(yield* platformDriver.checkpoints.restoreCheckpoint({ cwd, checkpointRef }));
1145+
1146+
assert.strictEqual(yield* fs.readFileString(path.join(cwd, "file.txt")), "unstaged\n");
1147+
const worktreeCommands = observedArgs.filter((args) =>
1148+
["add", "restore", "clean", "reset"].some((command) => args.includes(command)),
1149+
);
1150+
assert.strictEqual(worktreeCommands.length, 4);
1151+
for (const args of worktreeCommands) {
1152+
const setting = args.indexOf("core.longpaths=true");
1153+
if (platform === "win32") assert.strictEqual(args[setting - 1], "-c", args.join(" "));
1154+
else assert.strictEqual(setting, -1, args.join(" "));
1155+
}
1156+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
1157+
);

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
type VcsStatusResult,
3333
type WorktreeSubmodules,
3434
} from "@t3tools/contracts";
35+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
3536
import {
3637
makeGitVcsDriverCore,
3738
PATCH_RENDER_PREFIX_ARGS,
@@ -775,6 +776,13 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
775776
"core.fsyncMethod=fsync",
776777
] as const;
777778

779+
// Git for Windows cannot open paths longer than MAX_PATH (260 characters) unless
780+
// core.longpaths is on, and it is off by default. Without it, checkpoint `git add -A` exits
781+
// 128 with "Filename too long" in any workspace holding such a path, and restore cannot write
782+
// or clean those files. Checkpoints only snapshot and restore paths that already exist, so
783+
// commands that touch the working tree turn it on even if the user's config says false.
784+
const longPaths = (yield* HostProcessPlatform) === "win32" ? ["-c", "core.longpaths=true"] : [];
785+
778786
const checkpoints: VcsDriver.VcsCheckpointOps = {
779787
captureCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureCheckpoint")(function* (input) {
780788
const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION;
@@ -939,6 +947,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
939947
args: [
940948
...indexConfig,
941949
...durableWrite,
950+
...longPaths,
942951
"add",
943952
...(sparseCheckout ? ["--sparse"] : []),
944953
"-A",
@@ -957,7 +966,15 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
957966
const untracked = yield* execute({
958967
operation,
959968
cwd: input.cwd,
960-
args: ["ls-files", "--others", "--exclude-standard", "-z", "--", "."],
969+
args: [
970+
...longPaths,
971+
"ls-files",
972+
"--others",
973+
"--exclude-standard",
974+
"-z",
975+
"--",
976+
".",
977+
],
961978
env: commitEnv,
962979
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
963980
});
@@ -1072,7 +1089,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
10721089
yield* execute({
10731090
operation,
10741091
cwd: input.cwd,
1075-
args: ["restore", "--source", commitOid, "--worktree", "--staged", "--", "."],
1092+
args: [
1093+
...longPaths,
1094+
"restore",
1095+
"--source",
1096+
commitOid,
1097+
"--worktree",
1098+
"--staged",
1099+
"--",
1100+
".",
1101+
],
10761102
});
10771103
}
10781104
// Restoring away the last tracked file can remove a nested workspace directory.
@@ -1091,7 +1117,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
10911117
const cleaned = yield* execute({
10921118
operation,
10931119
cwd: input.cwd,
1094-
args: ["clean", "-fd", "--", "."],
1120+
args: [...longPaths, "clean", "-fd", "--", "."],
10951121
allowNonZeroExit: true,
10961122
});
10971123
if (cleaned.exitCode !== 0) {
@@ -1118,7 +1144,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
11181144
yield* execute({
11191145
operation,
11201146
cwd: input.cwd,
1121-
args: ["reset", "--quiet", "--", "."],
1147+
args: [...longPaths, "reset", "--quiet", "--", "."],
11221148
});
11231149
}
11241150

0 commit comments

Comments
 (0)