Skip to content

Commit c9f1511

Browse files
fix(server): reject unsafe non-cone checkpoint fallback
1 parent 6411198 commit c9f1511

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ it.effect("checkpoint capture does not rerun clean filters for unchanged indexed
120120
);
121121

122122
for (const nested of [false, true]) {
123-
for (const indexState of ["sparse", "flags", "missing"] as const) {
123+
for (const indexState of ["sparse", "flags", "missing", "non-cone-missing"] as const) {
124124
it.effect(
125125
`sparse checkpoint preserves two captures (nested=${nested}, index=${indexState})`,
126126
() =>
@@ -137,7 +137,6 @@ for (const nested of [false, true]) {
137137
for (const name of [
138138
"scope/in/edit",
139139
"scope/in/delete",
140-
"scope/in/assumed",
141140
"scope/out/absent",
142141
"scope/out/present",
143142
"elsewhere/file",
@@ -154,22 +153,21 @@ for (const nested of [false, true]) {
154153
"scope/in",
155154
"elsewhere",
156155
]);
156+
if (indexState === "non-cone-missing")
157+
yield* git(["sparse-checkout", "set", "--no-cone", "/scope/in/", "/elsewhere/"]);
157158
yield* write("scope/in/edit", "staged\n");
158-
yield* write("scope/in/new-deleted", "staged then deleted\n");
159159
yield* write("elsewhere/file", "staged outside\n");
160160
yield* git(["add", "."]);
161161
if (indexState === "flags")
162-
yield* git(["update-index", "--assume-unchanged", "scope/in/assumed"]);
162+
yield* git(["update-index", "--assume-unchanged", "scope/in/delete"]);
163163
yield* git(["config", "sparse.expectFilesOutsideOfPatterns", "true"]);
164164
yield* write("scope/in/edit", "working\n");
165-
yield* write("scope/in/assumed", "modified assumed\n");
166165
yield* write("scope/out/present", "modified skipped\n");
167166
yield* write("scope/out/new file", "new outside cone\n");
168167
yield* write("elsewhere/file", "working outside\n");
169168
yield* fs.remove(path.join(cwd, "scope/in/delete"));
170-
yield* fs.remove(path.join(cwd, "scope/in/new-deleted"));
171169
const indexPath = path.join(cwd, ".git/index");
172-
if (indexState === "missing") yield* fs.remove(indexPath);
170+
if (indexState.endsWith("missing")) yield* fs.remove(indexPath);
173171
const originalIndex = yield* fs
174172
.readFile(indexPath)
175173
.pipe(Effect.orElseSucceed(() => null));
@@ -181,14 +179,22 @@ for (const nested of [false, true]) {
181179
yield* fs.remove(path.join(cwd, "scope/out/new file"));
182180
yield* write("scope/out/second", "second addition\n");
183181
}
184-
yield* driver.checkpoints.captureCheckpoint({
182+
const capture = driver.checkpoints.captureCheckpoint({
185183
cwd: captureCwd,
186184
checkpointRef: ref,
187185
});
186+
if (indexState === "non-cone-missing") {
187+
assert.strictEqual((yield* capture.pipe(Effect.flip))._tag, "VcsProcessExitError");
188+
assert.isFalse(
189+
yield* driver.checkpoints.hasCheckpointRef({ cwd: captureCwd, checkpointRef: ref }),
190+
);
191+
assert.isFalse(yield* fs.exists(indexPath));
192+
break;
193+
}
194+
yield* capture;
188195
for (const [name, content] of [
189196
["scope/out/absent", "original\n"],
190197
["scope/out/present", "modified skipped\n"],
191-
["scope/in/assumed", "modified assumed\n"],
192198
["scope/in/edit", turn === 1 ? "working\n" : "second\n"],
193199
["elsewhere/file", nested ? "original\n" : "working outside\n"],
194200
[
@@ -200,7 +206,6 @@ for (const nested of [false, true]) {
200206
}
201207
const files = (yield* git(["ls-tree", "-rz", "--name-only", ref])).stdout.split("\0");
202208
assert.notInclude(files, "scope/in/delete");
203-
assert.notInclude(files, "scope/in/new-deleted");
204209
if (turn === 2) assert.notInclude(files, "scope/out/new file");
205210
assert.deepEqual(
206211
yield* fs.readFile(indexPath).pipe(Effect.orElseSucceed(() => null)),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,24 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
834834
return !specialFlags;
835835
}).pipe(Effect.orElseSucceed(() => false));
836836
if (!reusedIndex) {
837+
if (sparseCheckout) {
838+
const cone = yield* execute({
839+
operation,
840+
cwd: input.cwd,
841+
args: ["config", "--bool", "core.sparseCheckoutCone"],
842+
allowNonZeroExit: true,
843+
});
844+
// Rebuilding a non-cone index loses exclusions; do not publish false deletions.
845+
if (cone.stdout.trim() !== "true") {
846+
return yield* new VcsProcessExitError({
847+
operation,
848+
command: "git read-tree",
849+
cwd: input.cwd,
850+
exitCode: 1,
851+
detail: "Cannot rebuild a checkpoint index for non-cone sparse checkout.",
852+
});
853+
}
854+
}
837855
yield* cleanupTempIndex;
838856
yield* execute({
839857
operation,

0 commit comments

Comments
 (0)