Skip to content
TypeScript

fix(server): checkpoints no longer expire a split index the repo still uses (#17074)

Sheehan Munimd37bce55f2d0
diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts
index 3a7a16f95d4..3c2b62259bf 100644
--- a/apps/server/src/vcs/GitVcsDriver.test.ts
+++ b/apps/server/src/vcs/GitVcsDriver.test.ts
@@ -163,6 +163,27 @@ it.effect("checkpoint capture skips untracked nested repositories without a comm
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
);
+it.effect("checkpoint capture keeps the shared index a split index still uses", () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
+ const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-checkpoint-split-" });
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
+ yield* git(["config", "core.splitIndex", "true"]);
+ yield* git(["config", "splitIndex.sharedIndexExpire", "now"]);
+ yield* git(["update-index", "--split-index"]);
+ yield* fileSystem.writeFileString(path.join(cwd, "untracked.txt"), "new\n");
+
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
+
+ assert.strictEqual((yield* git(["show", `${checkpointRef}:untracked.txt`])).stdout, "new\n");
+ // The real index points at a sharedindex.* file. Reading it fails if the capture expired it.
+ assert.strictEqual((yield* git(["ls-files", "--cached"])).stdout, "file.txt\n");
+ assert.strictEqual((yield* git(["diff", "--cached", "--name-only"])).stdout, "file.txt\n");
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
+);
+
it.effect("checkpoint recovery discovers nested HEAD independently of inherited GIT_DIR", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts
index 098b1ebcf64..c1684be0e1c 100644
--- a/apps/server/src/vcs/GitVcsDriver.ts
+++ b/apps/server/src/vcs/GitVcsDriver.ts
@@ -793,11 +793,17 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
const checkpoints: VcsDriver.VcsCheckpointOps = {
captureCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureCheckpoint")(function* (input) {
const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION;
+ // core.splitIndex governs every index Git writes, so an unguarded write to the
+ // scratch index can expire the sharedindex.* the real .git/index still uses.
const indexConfig = [
"-c",
"core.fsmonitor=false",
"-c",
"sparse.expectFilesOutsideOfPatterns=false",
+ "-c",
+ "core.splitIndex=false",
+ "-c",
+ "splitIndex.sharedIndexExpire=never",
];
const gitCommonDir = yield* resolveGitCommonDir(input.cwd);
const indexId = yield* crypto.randomUUIDv4().pipe(Effect.orDie);
@@ -933,7 +939,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
cwd: input.cwd,
args: sparseCheckout
? [...indexConfig, "-c", "index.sparse=true", "read-tree", "--reset", "HEAD"]
- : ["read-tree", "HEAD"],
+ : [...indexConfig, "read-tree", "HEAD"],
env: commitEnv,
});
}