The best way to control Claude Code, Codex and more from any computer or phone
fix(server): reverting files before the first commit no longer leaves them staged (#28647)
Abhishek B R committed
Nov 4, 2026 at 04:34 UTC
ac976026a9005527a058948347b83edbc8431670
2 files changed
+46
-8
apps/server/src/vcs/GitVcsDriver.test.ts
+41
@@ -1134,6 +1134,47 @@ it.effect("restores empty checkpoints without changing paths outside the workspa
1134
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1135
);
1136
1137
+it.effect("restores a checkpoint before the first commit without staging its files", () =>
1138
+ Effect.gen(function* () {
1139
+ const fileSystem = yield* FileSystem.FileSystem;
1140
+ const path = yield* Path.Path;
1141
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
1142
+ for (const nested of [false, true]) {
1143
+ const root = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-unborn-restore-" });
1144
+ yield* runGit(root, ["init"]);
1145
+ yield* runGit(root, ["config", "user.email", "test@test.com"]);
1146
+ yield* runGit(root, ["config", "user.name", "Test"]);
1147
+ if (nested) {
1148
+ yield* fileSystem.writeFileString(path.join(root, "outside.txt"), "staged\n");
1149
+ yield* runGit(root, ["add", "outside.txt"]);
1150
+ }
1151
+ const cwd = nested ? path.join(root, "nested") : root;
1152
+ yield* fileSystem.makeDirectory(cwd, { recursive: true });
1153
+ yield* fileSystem.writeFileString(path.join(cwd, "file.txt"), "original\n");
1154
+ const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/unborn");
1155
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
1156
+ yield* fileSystem.writeFileString(path.join(cwd, "file.txt"), "changed\n");
1157
+ yield* fileSystem.writeFileString(path.join(cwd, "added.txt"), "new\n");
1158
+
1159
+ assert.isTrue(
1160
+ yield* driver.checkpoints.restoreCheckpoint({ cwd, checkpointRef, fallbackToHead: false }),
1161
+ );
1162
+
1163
+ assert.strictEqual(
1164
+ yield* fileSystem.readFileString(path.join(cwd, "file.txt")),
1165
+ "original\n",
1166
+ );
1167
+ assert.isFalse(yield* fileSystem.exists(path.join(cwd, "added.txt")));
1168
+ const staged = yield* driver.execute({
1169
+ operation: "test",
1170
+ cwd: root,
1171
+ args: ["diff", "--cached", "--name-only"],
1172
+ });
1173
+ assert.strictEqual(staged.stdout.trim(), nested ? "outside.txt" : "");
1174
+ }
1175
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1176
+);
1177
+
1178
// The real VCS process, spawning `command` wherever the driver runs git.
1179
const vcsProcessSpawning = (command: string) =>
1180
Layer.effect(
apps/server/src/vcs/GitVcsDriver.ts
+5
-8
@@ -1367,14 +1367,11 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1367
// On Windows the same clean can remove './' and exit 0.
1368
yield* recreateWorkspace;
1369
1370
- const headExists = yield* hasHeadCommit(input.cwd);
1371
- if (headExists) {
1372
- yield* execute({
1373
- operation,
1374
- cwd: input.cwd,
1375
- args: [...longPaths, "reset", "--quiet", "--", "."],
1376
- });
1377
- }
1370
+ yield* execute({
1371
+ operation,
1372
+ cwd: input.cwd,
1373
+ args: [...longPaths, "reset", "--quiet", "--", "."],
1374
+ });
1375
1376
return true;
1377
}),