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 22, 03:15 UTC
fix(server): reverting files removes what a new .gitignore from the turn was hiding (#29795)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Alex Southwell committed
Nov 6, 2026 at 04:22 UTC
68d5f7ab6c0a3103f5d0de582e81189c2397609e
2 files changed
+84
-10
apps/server/src/vcs/GitVcsDriver.test.ts
+40
@@ -193,6 +193,7 @@ it.effect("checkpoint capture skips untracked nested repositories without a comm
193
`160000 commit ${nestedHead}\tcommitted\n`,
194
);
195
assert.deepEqual(yield* fileSystem.readFile(path.join(cwd, ".git", "index")), originalIndex);
196
+ assert.isTrue(yield* driver.checkpoints.restoreCheckpoint({ cwd, checkpointRef }));
197
assert.strictEqual(
198
yield* fileSystem.readFileString(path.join(cwd, nested, "private.txt")),
199
"nested\n",
@@ -1126,6 +1127,8 @@ it.effect("restores empty checkpoints without changing paths outside the workspa
1127
yield* fileSystem.writeFileString(path.join(cwd, "ignored.txt"), "keep\n");
1128
yield* fileSystem.makeDirectory(path.join(cwd, "untracked"));
1129
yield* fileSystem.writeFileString(path.join(cwd, "untracked", "file.txt"), "remove\n");
1130
+ yield* fileSystem.writeFileString(path.join(cwd, "untracked", ".gitignore"), "hidden.txt\n");
1131
+ yield* fileSystem.writeFileString(path.join(cwd, "untracked", "hidden.txt"), "remove\n");
1132
assert.isTrue(
1133
yield* driver.checkpoints.restoreCheckpoint({ cwd, checkpointRef, fallbackToHead: false }),
1134
);
@@ -1143,6 +1146,43 @@ it.effect("restores empty checkpoints without changing paths outside the workspa
1146
});
1147
assert.strictEqual(staged.stdout.trim(), "outside.txt");
1148
}
1149
+ yield* fileSystem.writeFileString(path.join(cwd, "checkpoint.txt"), "checkpoint\n");
1150
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
1151
+ yield* fileSystem.writeFileString(path.join(cwd, "checkpoint.txt"), "later\n");
1152
+ let deepest = cwd;
1153
+ for (let depth = 0; depth < 4; depth++) {
1154
+ yield* fileSystem.writeFileString(path.join(deepest, ".gitignore"), "d/.gitignore\n");
1155
+ deepest = path.join(deepest, "d");
1156
+ yield* fileSystem.makeDirectory(deepest);
1157
+ }
1158
+ yield* fileSystem.writeFileString(path.join(deepest, ".gitignore"), "hidden.txt\n");
1159
+ yield* fileSystem.writeFileString(path.join(deepest, "hidden.txt"), "remove\n");
1160
+ const incomplete = yield* driver.checkpoints
1161
+ .restoreCheckpoint({ cwd, checkpointRef, fallbackToHead: false })
1162
+ .pipe(Effect.flip);
1163
+ assert.strictEqual(incomplete._tag, "VcsProcessExitError");
1164
+ assert.strictEqual(
1165
+ yield* fileSystem.readFileString(path.join(cwd, "checkpoint.txt")),
1166
+ "checkpoint\n",
1167
+ );
1168
+ assert.strictEqual(
1169
+ (yield* driver.execute({
1170
+ operation: "test",
1171
+ cwd,
1172
+ args: ["diff", "--cached", "--name-only", "--", "."],
1173
+ })).stdout,
1174
+ "",
1175
+ );
1176
+ if (nested) {
1177
+ assert.strictEqual(
1178
+ (yield* driver.execute({
1179
+ operation: "test",
1180
+ cwd: root,
1181
+ args: ["diff", "--cached", "--name-only"],
1182
+ })).stdout.trim(),
1183
+ "outside.txt",
1184
+ );
1185
+ }
1186
}
1187
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1188
);
apps/server/src/vcs/GitVcsDriver.ts
+44
-10
@@ -1343,13 +1343,52 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1343
}),
1344
),
1345
);
1346
+ const resetIndex = Effect.gen(function* () {
1347
+ // On Windows clean can remove './' and exit 0.
1348
+ yield* recreateWorkspace;
1349
+ yield* execute({
1350
+ operation,
1351
+ cwd: input.cwd,
1352
+ args: [...longPaths, "reset", "--quiet", "--", "."],
1353
+ });
1354
+ });
1355
yield* recreateWorkspace;
1347
- const cleaned = yield* execute({
1356
+ const clean = execute({
1357
operation,
1358
cwd: input.cwd,
1359
args: [...longPaths, "clean", "-fd", "--", "."],
1360
+ env: { LC_ALL: "C" },
1361
allowNonZeroExit: true,
1362
});
1363
+ let cleaned = yield* clean;
1364
+ // Removing a new .gitignore exposes the files it hid; clean again until nothing is left.
1365
+ for (
1366
+ let pass = 1;
1367
+ pass < 4 && cleaned.exitCode === 0 && /^Removing /m.test(cleaned.stdout);
1368
+ pass++
1369
+ ) {
1370
+ yield* recreateWorkspace;
1371
+ cleaned = yield* clean;
1372
+ }
1373
+ if (cleaned.exitCode === 0 && /^Removing /m.test(cleaned.stdout)) {
1374
+ yield* recreateWorkspace;
1375
+ const remaining = yield* execute({
1376
+ operation,
1377
+ cwd: input.cwd,
1378
+ args: [...longPaths, "clean", "-dn", "--", "."],
1379
+ env: { LC_ALL: "C" },
1380
+ });
1381
+ if (/^Would remove /m.test(remaining.stdout)) {
1382
+ yield* resetIndex;
1383
+ return yield* new VcsProcessExitError({
1384
+ operation,
1385
+ command: "git clean",
1386
+ cwd: input.cwd,
1387
+ exitCode: 0,
1388
+ detail: "Could not clean the checkpoint workspace: untracked files remain.",
1389
+ });
1390
+ }
1391
+ }
1392
if (cleaned.exitCode !== 0) {
1393
// Git can remove every child, then fail trying to remove './' itself.
1394
const emptiedWorkspace =
@@ -1359,7 +1398,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1398
Effect.map((entries) => entries.length === 0),
1399
Effect.orElseSucceed(() => false),
1400
));
1362
- if (!emptiedWorkspace)
1401
+ if (!emptiedWorkspace) {
1402
+ yield* resetIndex;
1403
return yield* new VcsProcessExitError({
1404
operation,
1405
command: "git clean",
@@ -1367,15 +1407,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1407
exitCode: cleaned.exitCode,
1408
detail: cleaned.stderr.trim() || "Could not clean the checkpoint workspace.",
1409
});
1410
+ }
1411
}
1371
- // On Windows the same clean can remove './' and exit 0.
1372
- yield* recreateWorkspace;
1373
-
1374
- yield* execute({
1375
- operation,
1376
- cwd: input.cwd,
1377
- args: [...longPaths, "reset", "--quiet", "--", "."],
1378
- });
1412
+ yield* resetIndex;
1413
1414
return true;
1415
}),