Skip to content

Commit 3406bd7

Browse files
fix(server): background status fetch no longer breaks a concurrent git pull (pingdotgg#26568)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 49b0cc3 commit 3406bd7

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4416,6 +4416,37 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
44164416
}),
44174417
);
44184418

4419+
it.effect("leaves FETCH_HEAD to the user's own pulls in background upstream fetches", () =>
4420+
Effect.gen(function* () {
4421+
const cwd = yield* makeTmpDir();
4422+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
4423+
const updater = yield* makeTmpDir("git-vcs-driver-updater-");
4424+
const { initialBranch } = yield* initRepoWithCommit(cwd);
4425+
yield* git(remote, ["init", "--bare"]);
4426+
yield* git(cwd, ["remote", "add", "origin", remote]);
4427+
yield* git(cwd, ["push", "-u", "origin", initialBranch]);
4428+
4429+
yield* git(updater, ["clone", remote, "."]);
4430+
yield* git(updater, ["config", "user.email", "[email protected]"]);
4431+
yield* git(updater, ["config", "user.name", "Test"]);
4432+
yield* writeTextFile(updater, "remote.txt", "remote\n");
4433+
yield* git(updater, ["add", "remote.txt"]);
4434+
yield* git(updater, ["commit", "-m", "remote commit"]);
4435+
yield* git(updater, ["push", "origin", initialBranch]);
4436+
const fetchHeadPath = (yield* Path.Path).join(cwd, ".git", "FETCH_HEAD");
4437+
assert.equal(NodeFS.existsSync(fetchHeadPath), false);
4438+
4439+
const status = yield* (yield* GitVcsDriver.GitVcsDriver).statusDetailsRemote(cwd);
4440+
4441+
assert.equal(status.behindCount, 1);
4442+
assert.equal(
4443+
NodeFS.existsSync(fetchHeadPath),
4444+
false,
4445+
"background status fetch wrote .git/FETCH_HEAD, which an overlapping `git pull` merges from",
4446+
);
4447+
}),
4448+
);
4449+
44194450
it.effect("uses origin HEAD for default-branch detection with a non-origin upstream", () =>
44204451
Effect.gen(function* () {
44214452
const cwd = yield* makeTmpDir();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
13871387
"--quiet",
13881388
"--no-tags",
13891389
"--no-auto-gc",
1390+
// FETCH_HEAD is written without a lock; overlapping a user's `git pull` makes that pull fail.
1391+
"--no-write-fetch-head",
13901392
"--",
13911393
remoteName,
13921394
];

0 commit comments

Comments
 (0)