Skip to content

Commit 3711421

Browse files
ahalekellyclaude
andcommitted
fix(server): status polling no longer locks the git index
The server's background `git status` and `git diff HEAD --numstat` save their refreshed index under index.lock, so a user's own checkout or commit fails with "index.lock: File exists" whenever it lands during a poll. Run server git commands with GIT_OPTIONAL_LOCKS=0, and read status numstat with diff-index/diff-files, since porcelain `git diff` rewrites the index even with optional locks off. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 20012eb commit 3711421

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
860860
cwd: commandInput.cwd,
861861
env: {
862862
...process.env,
863+
// Status polling runs beside the user's own git commands; without this,
864+
// `git status` takes index.lock to save its refreshed index.
865+
GIT_OPTIONAL_LOCKS: "0",
863866
...input.env,
864867
...trace2Monitor.env,
865868
},
@@ -1771,10 +1774,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17711774
const statusCacheKey = repositoryPaths?.gitCommonDir;
17721775
const [numstatStdout, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
17731776
[
1777+
// Plumbing, because porcelain `git diff` rewrites the index even with
1778+
// GIT_OPTIONAL_LOCKS=0. -M keeps porcelain's rename detection.
17741779
executeGitWithStableDiagnostics(
17751780
"GitVcsDriver.statusDetails.numstat",
17761781
cwd,
1777-
["diff", "HEAD", "--numstat", "--"],
1782+
["diff-index", "-M", "--numstat", "HEAD", "--"],
17781783
{ allowNonZeroExit: true },
17791784
).pipe(
17801785
Effect.flatMap((result) => {
@@ -1783,7 +1788,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17831788
return Effect.map(
17841789
Effect.all([
17851790
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn", cwd, [
1786-
"diff",
1791+
"diff-files",
17871792
"--numstat",
17881793
]),
17891794
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn.staged", cwd, [
@@ -1816,9 +1821,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
18161821
...gitCommandContext({
18171822
operation: "GitVcsDriver.statusDetails.numstat",
18181823
cwd,
1819-
args: ["diff", "HEAD", "--numstat", "--"],
1824+
args: ["diff-index", "-M", "--numstat", "HEAD", "--"],
18201825
}),
1821-
detail: "git diff HEAD --numstat failed.",
1826+
detail: "git diff-index HEAD --numstat failed.",
18221827
exitCode: result.exitCode,
18231828
stdoutLength: result.stdout.length,
18241829
stderrLength: result.stderr.length,

0 commit comments

Comments
 (0)