Skip to content

Commit 68d5f7a

Browse files
saphidclaudemaria-rcks
authored
fix(server): reverting files removes what a new .gitignore from the turn was hiding (pingdotgg#29795)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 37f9134 commit 68d5f7a

2 files changed

Lines changed: 84 additions & 10 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ it.effect("checkpoint capture skips untracked nested repositories without a comm
193193
`160000 commit ${nestedHead}\tcommitted\n`,
194194
);
195195
assert.deepEqual(yield* fileSystem.readFile(path.join(cwd, ".git", "index")), originalIndex);
196+
assert.isTrue(yield* driver.checkpoints.restoreCheckpoint({ cwd, checkpointRef }));
196197
assert.strictEqual(
197198
yield* fileSystem.readFileString(path.join(cwd, nested, "private.txt")),
198199
"nested\n",
@@ -1126,6 +1127,8 @@ it.effect("restores empty checkpoints without changing paths outside the workspa
11261127
yield* fileSystem.writeFileString(path.join(cwd, "ignored.txt"), "keep\n");
11271128
yield* fileSystem.makeDirectory(path.join(cwd, "untracked"));
11281129
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");
11291132
assert.isTrue(
11301133
yield* driver.checkpoints.restoreCheckpoint({ cwd, checkpointRef, fallbackToHead: false }),
11311134
);
@@ -1143,6 +1146,43 @@ it.effect("restores empty checkpoints without changing paths outside the workspa
11431146
});
11441147
assert.strictEqual(staged.stdout.trim(), "outside.txt");
11451148
}
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+
}
11461186
}
11471187
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
11481188
);

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,13 +1343,52 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
13431343
}),
13441344
),
13451345
);
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+
});
13461355
yield* recreateWorkspace;
1347-
const cleaned = yield* execute({
1356+
const clean = execute({
13481357
operation,
13491358
cwd: input.cwd,
13501359
args: [...longPaths, "clean", "-fd", "--", "."],
1360+
env: { LC_ALL: "C" },
13511361
allowNonZeroExit: true,
13521362
});
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+
}
13531392
if (cleaned.exitCode !== 0) {
13541393
// Git can remove every child, then fail trying to remove './' itself.
13551394
const emptiedWorkspace =
@@ -1359,23 +1398,18 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
13591398
Effect.map((entries) => entries.length === 0),
13601399
Effect.orElseSucceed(() => false),
13611400
));
1362-
if (!emptiedWorkspace)
1401+
if (!emptiedWorkspace) {
1402+
yield* resetIndex;
13631403
return yield* new VcsProcessExitError({
13641404
operation,
13651405
command: "git clean",
13661406
cwd: input.cwd,
13671407
exitCode: cleaned.exitCode,
13681408
detail: cleaned.stderr.trim() || "Could not clean the checkpoint workspace.",
13691409
});
1410+
}
13701411
}
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;
13791413

13801414
return true;
13811415
}),

0 commit comments

Comments
 (0)