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

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

perf(server): reuse untracked paths in Git status (#28374)

Guanying Chen committed Nov 1, 2026 at 13:51 UTC b0d2a86dd8bf58c6255054a2722fff8963710814
2 files changed +65 -16
apps/server/src/vcs/GitVcsDriverCore.test.ts
+47 -13
@@ -3120,13 +3120,14 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3120 yield* writeTextFile(cwd, "README.md", "# test\ncommitted\n");
3121 yield* git(cwd, ["commit", "-am", "commit edit"]);
3122 yield* writeTextFile(cwd, "nested/untracked.txt", "one\ntwo\n");
3123 + yield* writeTextFile(cwd, "new [1].txt", "literal\n");
3124
3125 const status = yield* driver.statusDetailsLocal(pathService.join(cwd, "nested"), {
3126 includeBranchChanges: true,
3127 });
3128 assert.deepStrictEqual(status.branchChanges, {
3129 baseRef: "main",
3129 - insertions: 3,
3130 + insertions: 4,
3131 deletions: 0,
3132 });
3133 assert.isUndefined((yield* driver.statusDetailsLocal(cwd)).branchChanges);
@@ -3183,25 +3184,58 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3184 Effect.gen(function* () {
3185 const cwd = yield* makeTmpDir();
3186 yield* initRepoWithCommit(cwd);
3186 - const driver = yield* GitVcsDriver.GitVcsDriver;
3187 + const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
3188 + const untrackedScanRoots: string[][] = [];
3189 + const spawner = ChildProcessSpawner.make((command) => {
3190 + if (
3191 + ChildProcess.isStandardCommand(command) &&
3192 + command.args.includes("ls-files") &&
3193 + command.args.includes("--others")
3194 + ) {
3195 + untrackedScanRoots.push(command.args.slice(command.args.indexOf("--") + 1));
3196 + }
3197 + return delegate.spawn(command);
3198 + });
3199 + const driver = yield* makeGitVcsDriverCore().pipe(
3200 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
3201 + );
3202 yield* git(cwd, ["branch", "-M", "main"]);
3203 yield* git(cwd, ["checkout", "-b", "feature/many-untracked"]);
3204 + yield* writeTextFile(cwd, ".git/info/exclude", "ignored.txt\n");
3205 + yield* writeTextFile(cwd, "bulk[1]/ignored.txt", "ignored\n");
3206 yield* Effect.forEach(
3190 - Array.from({ length: 1_001 }, (_, index) => `bulk/${index}.txt`),
3207 + Array.from({ length: 1_001 }, (_, index) => `bulk[1]/${index}.txt`),
3208 (file) => writeTextFile(cwd, file, "one\ntwo\n"),
3209 { concurrency: 32, discard: true },
3210 );
3211
3195 - const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
3196 - assert.deepStrictEqual(status.branchChanges, {
3197 - baseRef: "main",
3198 - insertions: 2_002,
3199 - deletions: 0,
3200 - });
3201 - assert.deepStrictEqual(
3202 - status.workingTree.files.map((file) => file.path),
3203 - ["bulk/"],
3204 - );
3212 + for (const scenario of ["normal", "all", "no", "long names"]) {
3213 + if (scenario === "long names") {
3214 + yield* Effect.forEach(
3215 + Array.from({ length: 50 }, (_, index) => `${"a".repeat(180)}-${index}.txt`),
3216 + (file) => writeTextFile(cwd, file, "long name\n"),
3217 + { concurrency: 32, discard: true },
3218 + );
3219 + }
3220 + const mode = scenario === "long names" ? "normal" : scenario;
3221 + yield* git(cwd, ["config", "status.showUntrackedFiles", mode]);
3222 + untrackedScanRoots.length = 0;
3223 + const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
3224 + assert.deepStrictEqual(status.branchChanges, {
3225 + baseRef: "main",
3226 + insertions: scenario === "long names" ? 2_052 : 2_002,
3227 + deletions: 0,
3228 + });
3229 + assert.deepStrictEqual(untrackedScanRoots, [
3230 + scenario === "normal" ? [":(top,literal)bulk[1]/"] : [],
3231 + ]);
3232 + if (scenario === "normal") {
3233 + assert.deepStrictEqual(
3234 + status.workingTree.files.map((file) => file.path),
3235 + ["bulk[1]/"],
3236 + );
3237 + }
3238 + }
3239 }),
3240 );
3241
apps/server/src/vcs/GitVcsDriverCore.ts
+18 -3
@@ -2232,6 +2232,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2232 let aheadOfDefaultCount = 0;
2233 let hasWorkingTreeChanges = false;
2234 const changedFilesWithoutNumstat = new Set<string>();
2235 + const untrackedRoots: string[] = [];
2236
2237 const statusRecords = statusStdout.split("\0");
2238 for (let index = 0; index < statusRecords.length; index++) {
@@ -2256,7 +2257,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2257 if (line.length > 0 && !line.startsWith("#")) {
2258 hasWorkingTreeChanges = true;
2259 const pathValue = parsePorcelainPath(line);
2259 - if (pathValue) changedFilesWithoutNumstat.add(pathValue);
2260 + if (pathValue) {
2261 + changedFilesWithoutNumstat.add(pathValue);
2262 + if (line.startsWith("? ")) untrackedRoots.push(pathValue);
2263 + }
2264 // A rename record is followed by its original path as a separate record. Listing it
2265 // keeps the deletion selectable when committing only some files.
2266 if (line.startsWith("2 ")) {
@@ -2282,6 +2286,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2286 options?.includeBranchChanges
2287 ? readBranchChangeTotals(repositoryPaths?.worktreeRoot ?? cwd, refName, {
2288 knownOriginDefaultBranch: defaultBranch,
2289 + untrackedRoots,
2290 }).pipe(Effect.orElseSucceed(() => undefined))
2291 : Effect.undefined,
2292 ],
@@ -3133,7 +3138,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3138 const readBranchChangeTotals = Effect.fn("readBranchChangeTotals")(function* (
3139 cwd: string,
3140 branch: string | null,
3136 - options?: { readonly knownOriginDefaultBranch: string | null },
3141 + options?: {
3142 + readonly knownOriginDefaultBranch: string | null;
3143 + readonly untrackedRoots: ReadonlyArray<string>;
3144 + },
3145 ) {
3146 const { baseRef, mergeBase } = yield* resolveReviewMergeBase(
3147 cwd,
@@ -3141,7 +3149,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3149 undefined,
3150 options?.knownOriginDefaultBranch ?? null,
3151 );
3144 - const untracked = yield* prepareUntrackedReviewIndex(cwd, []);
3152 + const roots = options?.untrackedRoots ?? [];
3153 + // Bound pathspec matching work and stay below Windows' command-line limit.
3154 + const pathspecs =
3155 + roots.length <= 128 && roots.reduce((length, root) => length + root.length + 16, 0) < 8_000
3156 + ? roots.map((root) => `:(top,literal)${root}`)
3157 + : [];
3158 + // Empty status can mean untracked files are hidden; retain the full scan.
3159 + const untracked = yield* prepareUntrackedReviewIndex(cwd, pathspecs);
3160 if (untracked === null) {
3161 return yield* new GitCommandError({
3162 operation: "GitVcsDriver.readBranchChangeTotals",