Skip to content

Commit 52b94dd

Browse files
fix(server): preserve staged tracked files in ignored checkpoints
1 parent f00136a commit 52b94dd

2 files changed

Lines changed: 73 additions & 14 deletions

File tree

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,13 @@ it.effect("checkpoint capture skips an ignored project while keeping its allowed
308308
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
309309
);
310310

311-
it.effect(
312-
"checkpoint capture keeps tracked edits but excludes new files in a project ignored later",
313-
() =>
311+
it.effect.each([
312+
{ tracking: "committed-only", committed: ["committed.txt"], staged: [] },
313+
{ tracking: "staged-only", committed: [], staged: ["staged.txt"] },
314+
{ tracking: "mixed", committed: ["committed.txt"], staged: ["staged.txt"] },
315+
])(
316+
"checkpoint capture keeps $tracking tracked edits but excludes new files in a project ignored later",
317+
({ committed, staged }) =>
314318
Effect.gen(function* () {
315319
const fs = yield* FileSystem.FileSystem;
316320
const path = yield* Path.Path;
@@ -319,25 +323,41 @@ it.effect(
319323
const { git, checkpointRef } = yield* makeCheckpointFixture(driver, parent);
320324
const cwd = path.join(parent, "sub");
321325
yield* fs.makeDirectory(cwd);
322-
yield* fs.writeFileString(path.join(cwd, "tracked.txt"), "before\n");
323-
yield* git(["add", "sub"]);
324-
yield* git(["commit", "-m", "track project"]);
326+
for (const file of committed) {
327+
yield* fs.writeFileString(path.join(cwd, file), "committed\n");
328+
yield* git(["add", `sub/${file}`]);
329+
}
330+
if (committed.length > 0) {
331+
yield* git(["commit", "-m", "track project"]);
332+
}
333+
for (const file of staged) {
334+
yield* fs.writeFileString(path.join(cwd, file), "staged\n");
335+
yield* git(["add", `sub/${file}`]);
336+
}
337+
const tracked = [...committed, ...staged];
325338
yield* fs.writeFileString(path.join(parent, ".gitignore"), "sub/\n");
326-
yield* fs.writeFileString(path.join(cwd, "tracked.txt"), "after\n");
339+
for (const file of tracked) {
340+
yield* fs.writeFileString(path.join(cwd, file), `${file} working\n`);
341+
}
327342
yield* fs.writeFileString(path.join(cwd, "secret.txt"), "private\n");
328343
const originalIndex = yield* fs.readFile(path.join(parent, ".git", "index"));
329344

330-
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
331-
332-
assert.strictEqual(
333-
(yield* git(["show", `${checkpointRef}:sub/tracked.txt`])).stdout,
334-
"after\n",
345+
const captured = yield* Effect.result(
346+
driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }),
335347
);
348+
349+
assert.deepEqual(yield* fs.readFile(path.join(parent, ".git", "index")), originalIndex);
350+
if (captured._tag === "Failure") return yield* captured.failure;
336351
assert.strictEqual(
337352
(yield* git(["ls-tree", "-r", "--name-only", checkpointRef, "--", "sub"])).stdout,
338-
"sub/tracked.txt\n",
353+
tracked.map((file) => `sub/${file}\n`).join(""),
339354
);
340-
assert.deepEqual(yield* fs.readFile(path.join(parent, ".git", "index")), originalIndex);
355+
for (const file of tracked) {
356+
assert.strictEqual(
357+
(yield* git(["show", `${checkpointRef}:sub/${file}`])).stdout,
358+
`${file} working\n`,
359+
);
360+
}
341361
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
342362
);
343363

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,45 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
950950

951951
const workspaceIgnored = (yield* filterIgnoredPaths(input.cwd, ["."])).length === 0;
952952
if (workspaceIgnored) {
953+
// HEAD omits staged-only paths. Seed just this workspace's additions, keeping
954+
// unrelated staged changes and the scratch index's sparse flags untouched.
955+
const additions = yield* execute({
956+
operation,
957+
cwd: input.cwd,
958+
args: [
959+
"-c",
960+
"core.quotePath=true",
961+
"diff",
962+
"--cached",
963+
"--raw",
964+
"--no-abbrev",
965+
"--no-renames",
966+
"--no-relative",
967+
"--ignore-submodules=none",
968+
"--no-color",
969+
"--no-ext-diff",
970+
"--no-textconv",
971+
"--ita-visible-in-index",
972+
"--diff-filter=A",
973+
"--",
974+
".",
975+
],
976+
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
977+
outputMode: "error",
978+
});
979+
if (additions.stdout.length > 0) {
980+
// Git's quoted paths round-trip through index-info, including non-UTF-8 names.
981+
yield* execute({
982+
operation,
983+
cwd: input.cwd,
984+
args: [...indexConfig, "-c", "index.sparse=false", "update-index", "--index-info"],
985+
stdin: additions.stdout.replace(
986+
/^:000000 ([0-7]{6}) 0+ ([0-9a-f]+) A\t/gm,
987+
"$1 $2\t",
988+
),
989+
env: commitEnv,
990+
});
991+
}
953992
const tracked = yield* execute({
954993
operation,
955994
cwd: input.cwd,

0 commit comments

Comments
 (0)