@devries-cameron20 / t3code-1 / commits / ab2420ffc0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): a selected-file commit keeps other files' merge conflicts (#33115)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 15, 2026 at 00:26 UTC ab2420ffc0fe702841dadadbd822987cdcee9b3c
2 files changed +90 -4
apps/server/src/vcs/GitVcsDriverCore.test.ts
+47
@@ -8388,6 +8388,53 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
8388 }),
8389 );
8390
8391 + it.effect("keeps other files conflicted through a selected-file commit", () =>
8392 + Effect.gen(function* () {
8393 + const cwd = yield* makeTmpDir();
8394 + yield* initRepoWithCommit(cwd);
8395 + const driver = yield* GitVcsDriver.GitVcsDriver;
8396 + // git stash pop leaves README.md conflicted with no merge in progress.
8397 + yield* writeTextFile(cwd, "README.md", "stashed version\n");
8398 + yield* git(cwd, ["stash"]);
8399 + yield* writeTextFile(cwd, "README.md", "committed version\n");
8400 + yield* git(cwd, ["commit", "-am", "Change README"]);
8401 + const pop = yield* driver.execute({
8402 + operation: "test.stashPop",
8403 + cwd,
8404 + args: ["stash", "pop"],
8405 + allowNonZeroExit: true,
8406 + });
8407 + assert.equal(pop.exitCode, 1);
8408 + yield* writeTextFile(cwd, "other.txt", "other\n");
8409 + const head = yield* git(cwd, ["rev-parse", "HEAD"]);
8410 + const unmerged = yield* git(cwd, ["ls-files", "--unmerged"]);
8411 + const fs = yield* FileSystem.FileSystem;
8412 + const path = yield* Path.Path;
8413 + const nested = path.join(cwd, "nested");
8414 + yield* fs.makeDirectory(nested);
8415 + // A formatting hook stages its edit into the temporary index that --only commits from.
8416 + yield* writeTextFile(
8417 + cwd,
8418 + ".git/hooks/pre-commit",
8419 + "#!/bin/sh\necho formatted >> other.txt\ngit add other.txt\n",
8420 + );
8421 + yield* fs.chmod(path.join(cwd, ".git/hooks/pre-commit"), 0o755);
8422 +
8423 + yield* driver.commit(cwd, "Add other", "", { stage: { filePaths: ["other.txt"] } });
8424 +
8425 + assert.equal(yield* git(cwd, ["rev-parse", "HEAD~1"]), head);
8426 + assert.equal(yield* git(cwd, ["show", "--pretty=", "--name-only", "HEAD"]), "other.txt");
8427 + assert.equal(yield* git(cwd, ["show", "HEAD:other.txt"]), "other\nformatted");
8428 + assert.equal(yield* git(cwd, ["show", ":other.txt"]), "other\nformatted");
8429 + assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
8430 + const all = yield* driver.prepareCommitContext(nested).pipe(Effect.flip);
8431 + assert.equal(
8432 + all.detail,
8433 + "Cannot commit with unresolved merge conflicts in README.md. Resolve them, then commit.",
8434 + );
8435 + }),
8436 + );
8437 +
8438 const commitWithHooks = (hooks: Record<string, string>) =>
8439 Effect.gen(function* () {
8440 const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+43 -4
@@ -2680,6 +2680,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2680 const config = env
2681 ? ["-c", "core.splitIndex=false", "-c", "splitIndex.sharedIndexExpire=never"]
2682 : [];
2683 + let preserveUnselectedConflicts = false;
2684 if (filePaths && filePaths.length > 0) {
2685 if (env) {
2686 const head = yield* executeGit(
@@ -2756,7 +2757,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2757 detail: `Cannot commit selected files during a ${operation}. Commit all files to finish the ${operation}.`,
2758 });
2759 }
2759 - yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]);
2760 + const selectedFiles = new Set(filePaths);
2761 + const unmergedPaths = yield* runGitStdoutWithOptions(
2762 + "GitVcsDriver.commit.unmergedPaths",
2763 + cwd,
2764 + ["-c", "diff.relative=false", "diff", "--cached", "--name-only", "--diff-filter=U", "-z"],
2765 + { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2766 + );
2767 + // Reset drops every conflict stage, so keep the index while unselected files are conflicted.
2768 + preserveUnselectedConflicts = unmergedPaths
2769 + .split("\0")
2770 + .some((file) => file.length > 0 && !selectedFiles.has(file));
2771 + if (!preserveUnselectedConflicts) {
2772 + yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]);
2773 + }
2774 }
2775 // Status paths are repository-relative, while cwd can be a subdirectory.
2776 const pathspecs = filePaths.map((file) => `:(top,literal)${file}`);
@@ -2872,6 +2886,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2886 env ? { env } : {},
2887 );
2888 }
2889 + return preserveUnselectedConflicts && filePaths
2890 + ? filePaths.map((file) => `:(top,literal)${file}`)
2891 + : undefined;
2892 });
2893
2894 const prepareCommitContext: GitVcsDriver.GitVcsDriver["Service"]["prepareCommitContext"] =
@@ -3016,14 +3033,26 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3033 body,
3034 options?: GitVcsDriver.GitCommitOptions,
3035 ) {
3019 - if (options?.stage !== undefined) {
3020 - yield* stageCommitChanges(cwd, options.stage.filePaths);
3021 - }
3036 + const partialCommitPaths =
3037 + options?.stage !== undefined
3038 + ? yield* stageCommitChanges(cwd, options.stage.filePaths)
3039 + : undefined;
3040 const args = ["commit", "-m", subject];
3041 const trimmedBody = body.trim();
3042 if (trimmedBody.length > 0) {
3043 args.push("-m", trimmedBody);
3044 }
3045 + const onlyFromStdin = partialCommitPaths ? yield* supportsPathspecFromFile(cwd) : false;
3046 + const onlyPathspecArgs = onlyFromStdin
3047 + ? ["--pathspec-from-file=-", "--pathspec-file-nul"]
3048 + : ["--", ...(partialCommitPaths ?? [])];
3049 + const onlyPathspecStdin =
3050 + partialCommitPaths && onlyFromStdin
3051 + ? { stdin: partialCommitPaths.map((pathspec) => `${pathspec}\0`).join("") }
3052 + : {};
3053 + if (partialCommitPaths) {
3054 + args.push("--only", ...onlyPathspecArgs);
3055 + }
3056 const progress =
3057 options?.progress?.onOutputLine === undefined
3058 ? options?.progress
@@ -3036,9 +3065,19 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3065 };
3066 yield* executeGit("GitVcsDriver.commit.commit", cwd, args, {
3067 maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,
3068 + ...onlyPathspecStdin,
3069 ...(options?.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
3070 ...(progress ? { progress } : {}),
3071 }).pipe(Effect.asVoid);
3072 + if (partialCommitPaths) {
3073 + // --only runs hooks on a temporary index, so a hook's `git add` never reaches the real one.
3074 + yield* runGit(
3075 + "GitVcsDriver.commit.syncSelectedIndex",
3076 + cwd,
3077 + ["reset", "--quiet", "HEAD", ...onlyPathspecArgs],
3078 + onlyPathspecStdin,
3079 + );
3080 + }
3081 const commitSha = yield* runGitStdout("GitVcsDriver.commit.revParseHead", cwd, [
3082 "rev-parse",
3083 "HEAD",