Skip to content

Commit e5b0718

Browse files
fix(server): blank .gitignore lines no longer make checkpoints drop new files (#32374)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 151d5f8 commit e5b0718

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ it.effect("checkpoint capture skips an ignored project while keeping its allowed
406406
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
407407
);
408408

409+
it.effect.each([
410+
{ workspace: "the repository root", subdirectory: "" },
411+
{ workspace: "a subdirectory", subdirectory: "sub" },
412+
])(
413+
"checkpoint capture keeps new files in $workspace when the root .gitignore has a blank CRLF line",
414+
({ subdirectory }) =>
415+
Effect.gen(function* () {
416+
const fs = yield* FileSystem.FileSystem;
417+
const path = yield* Path.Path;
418+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
419+
const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-crlf-ignore-" });
420+
const { git, checkpointRef } = yield* makeCheckpointFixture(driver, parent);
421+
yield* fs.writeFileString(path.join(parent, ".gitignore"), "a.txt\r\n\r\nb.txt\r\n");
422+
const cwd = path.join(parent, subdirectory);
423+
yield* fs.makeDirectory(cwd, { recursive: true });
424+
yield* fs.writeFileString(path.join(cwd, "notes.md"), "notes\n");
425+
const notesPath = subdirectory === "" ? "notes.md" : `${subdirectory}/notes.md`;
426+
427+
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
428+
429+
assert.include(
430+
(yield* git(["ls-tree", "-r", "--name-only", checkpointRef])).stdout.split("\n"),
431+
notesPath,
432+
);
433+
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
434+
);
435+
409436
it.effect.each([
410437
{ tracking: "committed-only", committed: ["committed.txt"], staged: [] },
411438
{ tracking: "staged-only", committed: [], staged: ["staged.txt"] },
@@ -1007,7 +1034,6 @@ it.effect.each(["committed", "unborn"] as const)(
10071034
"rev-parse",
10081035
"config",
10091036
...(head === "committed" ? ["read-tree", "ls-files"] : []),
1010-
"check-ignore",
10111037
"add",
10121038
"write-tree",
10131039
"commit-tree",
@@ -1060,13 +1086,13 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
10601086
const commands = yield* captureRecordingGitCommands(cwd, checkpointRef);
10611087

10621088
assert.deepStrictEqual(commands, [
1089+
"rev-parse",
10631090
"rev-parse",
10641091
"rev-parse",
10651092
"config",
10661093
"rev-parse",
10671094
"read-tree",
10681095
"ls-files",
1069-
"check-ignore",
10701096
"add",
10711097
"write-tree",
10721098
"commit-tree",

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
872872
"--git-common-dir",
873873
"--git-path",
874874
"index",
875+
"--show-prefix",
875876
"--verify",
876877
"--quiet",
877878
"HEAD",
@@ -881,19 +882,27 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
881882
const headExists = result.exitCode === 0;
882883
const headChecked = headExists || result.exitCode === 1;
883884
const lines = result.stdout.split("\n");
884-
const [gitCommonDir = "", indexPath = ""] = lines;
885-
if (headChecked && lines.length === (headExists ? 4 : 3) && lines.at(-1) === "") {
885+
const [gitCommonDir = "", indexPath = "", prefix = ""] = lines;
886+
if (headChecked && lines.length === (headExists ? 5 : 4) && lines.at(-1) === "") {
886887
return {
887888
gitCommonDir: gitCommonDir.trim(),
888889
indexPath: indexPath.trim(),
890+
prefix,
889891
headExists,
890892
};
891893
}
892894
// Git before 2.31 echoes --path-format, and a path containing a newline spans lines.
893895
// Separate commands read the paths as before and report a failure the same way.
896+
const fallbackCommonDir = yield* resolveGitCommonDir(cwd);
897+
const prefixResult = yield* execute({
898+
operation: VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
899+
cwd,
900+
args: ["rev-parse", "--show-prefix"],
901+
});
894902
return {
895-
gitCommonDir: yield* resolveGitCommonDir(cwd),
903+
gitCommonDir: fallbackCommonDir,
896904
indexPath: undefined,
905+
prefix: prefixResult.stdout.replace(/\n$/, ""),
897906
headExists: headChecked ? headExists : yield* hasHeadCommit(cwd),
898907
};
899908
});
@@ -930,7 +939,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
930939
"-c",
931940
"splitIndex.sharedIndexExpire=never",
932941
];
933-
const { gitCommonDir, indexPath, headExists } = yield* resolveCaptureRepository(input.cwd);
942+
const { gitCommonDir, indexPath, prefix, headExists } = yield* resolveCaptureRepository(
943+
input.cwd,
944+
);
934945
const indexId = yield* random.uuidV4();
935946
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
936947
const hostEnv = yield* HostProcess.Environment;
@@ -1123,7 +1134,12 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
11231134
}
11241135
}
11251136

1126-
const workspaceIgnored = (yield* filterIgnoredPaths(input.cwd, ["."])).length === 0;
1137+
// The working-tree root is never ignored. Probe a subdirectory without the trailing slash
1138+
// Git adds to ".", which a blank or whitespace-only ignore line matches as an empty pattern.
1139+
const workspaceIgnored =
1140+
prefix !== "" &&
1141+
(yield* filterIgnoredPaths(input.cwd, [`../${prefix.slice(0, -1).split("/").at(-1)}`]))
1142+
.length === 0;
11271143
if (workspaceIgnored) {
11281144
// HEAD omits staged-only paths. Seed just this workspace's additions, keeping
11291145
// unrelated staged changes and the scratch index's sparse flags untouched.

0 commit comments

Comments
 (0)