Skip to content

Commit f12a4dd

Browse files
fix(server): blank .gitignore lines no longer make checkpoints drop new files
Capture asked `git check-ignore .` whether the workspace is ignored. Git turns `.` into the workspace prefix with a trailing slash, and a blank CRLF or spaces-only line in any ignore source becomes an empty pattern that matches it. At the repository root capture then skipped untracked files; in a subdirectory without tracked files it refused to capture at all. The capture rev-parse now also reads the workspace prefix. The working-tree root is never ignored, so it skips the probe; a subdirectory is probed by its slash-less path, which real directory rules still match and the empty pattern does not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 84b970e commit f12a4dd

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ it.effect.each(["committed", "unborn"] as const)(
10341034
"rev-parse",
10351035
"config",
10361036
...(head === "committed" ? ["read-tree", "ls-files"] : []),
1037-
"check-ignore",
10381037
"add",
10391038
"write-tree",
10401039
"commit-tree",
@@ -1087,13 +1086,13 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
10871086
const commands = yield* captureRecordingGitCommands(cwd, checkpointRef);
10881087

10891088
assert.deepStrictEqual(commands, [
1089+
"rev-parse",
10901090
"rev-parse",
10911091
"rev-parse",
10921092
"config",
10931093
"rev-parse",
10941094
"read-tree",
10951095
"ls-files",
1096-
"check-ignore",
10971096
"add",
10981097
"write-tree",
10991098
"commit-tree",

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
857857
"--git-common-dir",
858858
"--git-path",
859859
"index",
860+
"--show-prefix",
860861
"--verify",
861862
"--quiet",
862863
"HEAD",
@@ -866,19 +867,27 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
866867
const headExists = result.exitCode === 0;
867868
const headChecked = headExists || result.exitCode === 1;
868869
const lines = result.stdout.split("\n");
869-
const [gitCommonDir = "", indexPath = ""] = lines;
870-
if (headChecked && lines.length === (headExists ? 4 : 3) && lines.at(-1) === "") {
870+
const [gitCommonDir = "", indexPath = "", prefix = ""] = lines;
871+
if (headChecked && lines.length === (headExists ? 5 : 4) && lines.at(-1) === "") {
871872
return {
872873
gitCommonDir: gitCommonDir.trim(),
873874
indexPath: indexPath.trim(),
875+
prefix,
874876
headExists,
875877
};
876878
}
877879
// Git before 2.31 echoes --path-format, and a path containing a newline spans lines.
878880
// Separate commands read the paths as before and report a failure the same way.
881+
const fallbackCommonDir = yield* resolveGitCommonDir(cwd);
882+
const prefixResult = yield* execute({
883+
operation: VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
884+
cwd,
885+
args: ["rev-parse", "--show-prefix"],
886+
});
879887
return {
880-
gitCommonDir: yield* resolveGitCommonDir(cwd),
888+
gitCommonDir: fallbackCommonDir,
881889
indexPath: undefined,
890+
prefix: prefixResult.stdout.replace(/\n$/, ""),
882891
headExists: headChecked ? headExists : yield* hasHeadCommit(cwd),
883892
};
884893
});
@@ -915,7 +924,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
915924
"-c",
916925
"splitIndex.sharedIndexExpire=never",
917926
];
918-
const { gitCommonDir, indexPath, headExists } = yield* resolveCaptureRepository(input.cwd);
927+
const { gitCommonDir, indexPath, prefix, headExists } = yield* resolveCaptureRepository(
928+
input.cwd,
929+
);
919930
const indexId = yield* random.uuidV4();
920931
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
921932
const hostEnv = yield* HostProcess.Environment;
@@ -1108,7 +1119,12 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
11081119
}
11091120
}
11101121

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

0 commit comments

Comments
 (0)