Skip to content
TypeScript

fix(server): selected-file commits stop when the index reset fails (#28275)

Victor Vogelcf5e6d3f0cbb
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index be0b8d6b7a3..9f9d23a8e40 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -5089,6 +5089,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 bc2f6833363..a084664bc44 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -2450,9 +2450,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",