The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 14:45 UTC
fix(server): first commit dialog shows net file changes (#36716)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 13:33 UTC
243d66a295814a4bed1351b7eab7760e040cc8d5
3 files changed
+55
-39
apps/server/src/vcs/GitVcsDriverCore.test.ts
+6
-10
@@ -4901,25 +4901,21 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4901
}),
4902
);
4903
4904
- it.effect("reports staged file counts on unborn HEAD without failing", () =>
4904
+ it.effect("reports net file counts from the empty tree on unborn HEAD", () =>
4905
Effect.gen(function* () {
4906
const cwd = yield* makeTmpDir();
4907
const driver = yield* GitVcsDriver.GitVcsDriver;
4908
yield* driver.initRepo({ cwd });
4909
- yield* git(cwd, ["config", "user.email", "test@test.com"]);
4910
- yield* git(cwd, ["config", "user.name", "Test"]);
4909
yield* writeTextFile(cwd, "initial.ts", "// first file\n");
4910
yield* git(cwd, ["add", "initial.ts"]);
4911
+ yield* writeTextFile(cwd, "initial.ts", "// edited after staging\n");
4912
4914
- const status = yield* driver.statusDetails(cwd);
4913
+ const status = yield* driver.statusDetailsLocal(cwd);
4914
4915
assert.equal(status.isRepo, true);
4917
- assert.equal(status.workingTree.files.length, 1);
4918
- const file = status.workingTree.files[0];
4919
- if (file) {
4920
- assert.equal(file.path, "initial.ts");
4921
- assert.equal(file.insertions, 1);
4922
- }
4916
+ assert.deepStrictEqual(status.workingTree.files, [
4917
+ { path: "initial.ts", insertions: 1, deletions: 0 },
4918
+ ]);
4919
}),
4920
);
4921
});
apps/server/src/vcs/GitVcsDriverCore.ts
+13
-29
@@ -2276,41 +2276,25 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2276
isMissingGitCwdError(error) ? Effect.succeed(null) : Effect.fail(error),
2277
}),
2278
);
2279
+ // Porcelain diff rewrites indexes despite GIT_OPTIONAL_LOCKS=0; plumbing with -M preserves rename detection.
2280
+ const readNumstat = (ref: string) =>
2281
+ executeGitWithStableDiagnostics(
2282
+ "GitVcsDriver.statusDetails.numstat",
2283
+ cwd,
2284
+ ["diff-index", "-M", "--numstat", "-z", ref, "--"],
2285
+ { allowNonZeroExit: true, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2286
+ );
2287
// diff-index does not read status output, so both spawn together; a non-repository discards it.
2288
const [statusResult, numstatResult, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
2289
[
2290
readStatus,
2283
- // Porcelain diff rewrites indexes despite GIT_OPTIONAL_LOCKS=0; plumbing with -M preserves rename detection.
2284
- executeGitWithStableDiagnostics(
2285
- "GitVcsDriver.statusDetails.numstat",
2286
- cwd,
2287
- ["diff-index", "-M", "--numstat", "-z", "HEAD", "--"],
2288
- { allowNonZeroExit: true, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2289
- ).pipe(
2291
+ readNumstat("HEAD").pipe(
2292
+ Effect.filterOrElse(
2293
+ (result) => result.exitCode === 0 || !isUnbornHeadStderr(result.stderr),
2294
+ () => Effect.flatMap(readEmptyTreeHash(cwd), readNumstat),
2295
+ ),
2296
Effect.flatMap((result) => {
2297
if (result.exitCode === 0) return Effect.succeed(parseReviewNumstat(result.stdout));
2292
- if (isUnbornHeadStderr(result.stderr)) {
2293
- return Effect.map(
2294
- Effect.all([
2295
- runGitStdoutWithOptions(
2296
- "GitVcsDriver.statusDetails.numstat.unborn",
2297
- cwd,
2298
- ["diff-files", "--numstat", "-z"],
2299
- { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2300
- ),
2301
- runGitStdoutWithOptions(
2302
- "GitVcsDriver.statusDetails.numstat.unborn.staged",
2303
- cwd,
2304
- ["diff", "--cached", "--numstat", "-z"],
2305
- { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2306
- ),
2307
- ]),
2308
- ([unstagedStdout, stagedStdout]) => [
2309
- ...parseReviewNumstat(stagedStdout),
2310
- ...parseReviewNumstat(unstagedStdout),
2311
- ],
2312
- );
2313
- }
2298
return Effect.fail(
2299
new GitCommandError({
2300
...gitCommandContext({
scripts/scenarios/unborn-commit-dialog-shows-net-counts.e2e.ts
new
+36
@@ -0,0 +1,36 @@
1
+import { expect } from "e2e";
2
+import * as Effect from "effect/Effect";
3
+import * as FileSystem from "effect/FileSystem";
4
+
5
+import { run } from "./shell.ts";
6
+import { runPromise, test, WEB } from "./t3.ts";
7
+
8
+test(
9
+ "The commit dialog before the first commit counts a file staged then edited once",
10
+ WEB,
11
+ async ({ t3, app, screen }) => {
12
+ const project = await t3.project("demo");
13
+ const git = (...args: ReadonlyArray<string>) => runPromise(run("git", args, { cwd: project }));
14
+ const write = (text: string) =>
15
+ runPromise(
16
+ Effect.flatMap(FileSystem.FileSystem, (fs) =>
17
+ fs.writeFileString(`${project}/new.txt`, `${text}\n`),
18
+ ),
19
+ );
20
+ // No commits yet: staged "staged", then edited to "actual" without restaging.
21
+ await git("update-ref", "-d", "HEAD");
22
+ await git("rm", "-r", "--cached", "--quiet", ".");
23
+ await write("staged");
24
+ await git("add", "new.txt");
25
+ await write("actual");
26
+ const thread = await t3.thread({ project, title: "First commit", messages: ["first"] });
27
+
28
+ await t3.open(thread);
29
+ await screen.getByRole("button", "Git action options").tap();
30
+ await screen.getByRole("menuitem", "Commit").tap();
31
+ const row = screen.getByRole("button", "Open new.txt in editor");
32
+ await expect(row).toBeVisible();
33
+ await app.screenshot("commit-dialog");
34
+ await expect(row).toHaveText(/\+1 \/ -0/);
35
+ },
36
+);