Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/server/src/vcs/GitVcsDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
65 changes: 44 additions & 21 deletions apps/server/src/vcs/GitVcsDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1408,28 +1418,41 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
? CheckpointUntrackedBlobs.NOTHING
: yield* untrackedBlobs.reuse({ ...untracked, indexConfig });

const stageFiles = (exclusions: ReadonlyArray<string>) =>
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<string>, exclusions: ReadonlyArray<string>) =>
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<string>) =>
durableWriteBatches
? stageFilesWith(durableWrite, exclusions).pipe(
Effect.catchTags({
VcsProcessExitError: () => stageFilesWith(perObjectDurableWrite, exclusions),
Comment thread
maria-rcks marked this conversation as resolved.
Resolved
}),
)
: stageFilesWith(durableWrite, exclusions),
);
const stagingAt = yield* Clock.currentTimeMillis;

yield* stageFiles([]).pipe(
Effect.catchTags({
VcsProcessExitError: (error) =>
Expand Down
Loading