Skip to content

Commit f5d0be6

Browse files
fix(server): Changes totals no longer take index.lock (pingdotgg#35770)
1 parent 63426c4 commit f5d0be6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,6 +4017,29 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40174017
}),
40184018
);
40194019

4020+
it.effect("reads Changes totals without rewriting the real index for stat-dirty files", () =>
4021+
Effect.gen(function* () {
4022+
const cwd = yield* makeTmpDir();
4023+
yield* initRepoWithCommit(cwd);
4024+
const driver = yield* GitVcsDriver.GitVcsDriver;
4025+
const fileSystem = yield* FileSystem.FileSystem;
4026+
const path = yield* Path.Path;
4027+
yield* writeTextFile(cwd, "tracked.txt", "same content\n");
4028+
yield* git(cwd, ["add", "tracked.txt"]);
4029+
yield* git(cwd, ["commit", "-m", "add tracked file"]);
4030+
yield* fileSystem.utimes(path.join(cwd, "tracked.txt"), 1_000_000_000, 1_000_000_000);
4031+
const indexPath = path.join(cwd, ".git", "index");
4032+
const originalIndex = yield* fileSystem.readFile(indexPath);
4033+
4034+
const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
4035+
4036+
assert.strictEqual(status.branchChanges?.insertions, 0);
4037+
assert.strictEqual(status.branchChanges?.deletions, 0);
4038+
// Writing the index takes index.lock, which makes concurrent user Git writes fail.
4039+
assert.deepStrictEqual(yield* fileSystem.readFile(indexPath), originalIndex);
4040+
}),
4041+
);
4042+
40204043
it.effect("reads Changes totals with untracked files when requested", () =>
40214044
Effect.gen(function* () {
40224045
const cwd = yield* makeTmpDir();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3513,7 +3513,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
35133513
executeGit(
35143514
"GitVcsDriver.readBranchChangeTotals",
35153515
cwd,
3516-
[...REVIEW_DIFF_ARGS, "--numstat", "-z", ref, "--"],
3516+
// Plumbing: porcelain diff refreshes and rewrites the real index, taking index.lock.
3517+
["diff-index", "-M", "--numstat", "-z", ref, "--"],
35173518
{
35183519
allowNonZeroExit: true,
35193520
maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,

0 commit comments

Comments
 (0)