diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 06b34446fd4bb..83d74b47c6c2a 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -270,12 +270,15 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( ), ), ); - const packs = (yield* fs.readDirectory(path.join(objectDirectory, "pack"))).filter( - (name) => name.startsWith("tmp_pack_") && name !== "tmp_pack_other_operation", + // Batch fsync (macOS, Windows) writes the pack in Git's own bulk-fsync folder inside it. + const packs = (yield* fs.readDirectory(objectDirectory, { recursive: true })).filter( + (name) => + path.basename(name).startsWith("tmp_pack_") && + path.basename(name) !== "tmp_pack_other_operation", ); assert.strictEqual(packs.length, 1); assert.isAbove( - Number((yield* fs.stat(path.join(objectDirectory, "pack", packs[0]!))).size), + Number((yield* fs.stat(path.join(objectDirectory, packs[0]!))).size), 1024 * 1024, ); // An overlapping capture publishes the same large blob while the first @@ -319,7 +322,7 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( sharedPackBytes, ); assert.strictEqual((yield* git(["rev-parse", concurrentRef])).stdout, concurrentOid); - assert.isFalse(yield* fs.exists(path.join(objectDirectory, "pack", packs[0]!))); + assert.isFalse(yield* fs.exists(path.join(objectDirectory, packs[0]!))); assert.isFalse(yield* fs.exists(objectDirectory)); assert.strictEqual(yield* fs.readFileString(sharedPack), "owned by another Git operation"); if (stop !== "success") diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index 0bf6f31b227c9..6040163bed248 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1019,6 +1019,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ? ["-c", "core.fsyncMethod=batch"] : []), ] as const; + // Git 2.54-2.56 batch mode loses a large file's bulk-checkin pack when a smaller file was + // written loose earlier in the same add ("unable to rename temporary file"), so a failed + // batch add is staged once more with per-object fsync, which Git finalizes correctly. + const perObjectDurableWrite = [ + "-c", + "core.fsync=objects,reference", + "-c", + "core.fsyncMethod=fsync", + ] as const; + const durableWriteBatches = durableWrite.length > perObjectDurableWrite.length; // Checkpoints must handle existing paths beyond Windows MAX_PATH, even when // core.longpaths is disabled in the user's Git configuration. @@ -1408,28 +1418,41 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ? CheckpointUntrackedBlobs.NOTHING : yield* untrackedBlobs.reuse({ ...untracked, indexConfig }); - const stageFiles = (exclusions: ReadonlyArray) => - execute({ - operation, - cwd: input.cwd, - args: [ - ...indexConfig, - ...durableWrite, - ...longPaths, - // safecrlf=true refuses LF files under CRLF conversion; capture them as Git's default does. - "-c", - "core.safecrlf=false", - "add", - ...(sparseCheckout ? ["--sparse"] : []), - // add -A rejects ignored directories even when they contain tracked files. - workspaceIgnored ? "-u" : "-A", - "--", - ".", - ...exclusions, - ], - env: commitEnv, - }); + const stageFilesWith = Effect.fn("GitVcsDriver.stageFilesWith")( + (durability: ReadonlyArray, exclusions: ReadonlyArray) => + execute({ + operation, + cwd: input.cwd, + args: [ + ...indexConfig, + ...durability, + ...longPaths, + // safecrlf=true refuses LF files under CRLF conversion; capture them as Git's default does. + "-c", + "core.safecrlf=false", + "add", + ...(sparseCheckout ? ["--sparse"] : []), + // add -A rejects ignored directories even when they contain tracked files. + workspaceIgnored ? "-u" : "-A", + "--", + ".", + ...exclusions, + ], + env: commitEnv, + }), + ); + const stageFiles = Effect.fn("GitVcsDriver.stageFiles")( + (exclusions: ReadonlyArray) => + durableWriteBatches + ? stageFilesWith(durableWrite, exclusions).pipe( + Effect.catchTags({ + VcsProcessExitError: () => stageFilesWith(perObjectDurableWrite, exclusions), + }), + ) + : stageFilesWith(durableWrite, exclusions), + ); const stagingAt = yield* Clock.currentTimeMillis; + yield* stageFiles([]).pipe( Effect.catchTags({ VcsProcessExitError: (error) =>