diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts index 8363e16c32476..66d3d78e9454c 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.test.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts @@ -4824,6 +4824,31 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { }), ); + it.effect("stops a selected-file commit when another process holds the index lock", () => + Effect.gen(function* () { + const cwd = yield* makeTmpDir(); + yield* initRepoWithCommit(cwd); + const head = yield* git(cwd, ["rev-parse", "HEAD"]); + yield* writeTextFile(cwd, "a.txt", "a\n"); + yield* writeTextFile(cwd, "staged.txt", "staged\n"); + yield* git(cwd, ["add", "staged.txt"]); + const lockPath = (yield* Path.Path).join(cwd, ".git", "index.lock"); + yield* (yield* FileSystem.FileSystem).writeFileString(lockPath, ""); + const { driver } = yield* makeDriverReleasingLock( + (args) => args.includes("reset"), + lockPath, + ); + + const error = yield* driver + .commit(cwd, "Add a", "", { stage: { filePaths: ["a.txt"] } }) + .pipe(Effect.flip); + + assert.equal(error.operation, "GitVcsDriver.commit.reset"); + assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), head); + assert.equal(yield* git(cwd, ["diff", "--cached", "--name-only"]), "staged.txt"); + }), + ); + it.effect.each([ { location: "root", ref: "refs/heads/MERGE_HEAD" }, { location: "nested", ref: "refs/heads/MERGE_HEAD" }, diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts index 71945b0b6f71c..d616ceed7d735 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.ts @@ -2421,9 +2421,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* "Cannot commit selected files during a merge. Commit all files to finish the merge.", }); } - yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset"]).pipe( - Effect.catchTags({ GitCommandError: () => Effect.void }), - ); + yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]); } yield* runGit( "GitVcsDriver.commit.addSelected",