diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 21386adbacf9..eaeeffa458ef 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -847,9 +847,25 @@ it.effect.each([ change: ({ git, checkpointRef }: UntrackedBlobChange) => git(["update-ref", "-d", checkpointRef]).pipe(Effect.andThen(git(["prune", "--expire=now"]))), }, + ...(HostProcess.Platform.defaultValue() === "win32" + ? [] + : [ + { + name: "it became ignored under a name that looks like a git pathspec", + file: ":large.txt", + reuses: false, + change: ({ write }: UntrackedBlobChange) => write(".gitignore", ":large.txt\n"), + }, + { + name: "its name looks like git pathspec magic", + file: ":(magic)", + reuses: true, + change: () => Effect.void, + }, + ]), ])( "checkpoint capture skips hashing an untracked file only while a fresh hash would match: $name", - ({ reuses, change, during }) => + ({ file = "nested/large.txt", reuses, change, during }) => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -877,7 +893,7 @@ it.effect.each([ const write = (relativePath: string, contents: string) => fs.writeFileString(path.join(cwd, relativePath), contents); yield* fs.makeDirectory(path.join(cwd, "nested")); - yield* write("nested/large.txt", "line\r\n".repeat(3 * 1024 * 1024)); + yield* write(file, "line\r\n".repeat(3 * 1024 * 1024)); // Only files left alone for a few seconds before a capture are remembered. yield* TestClock.adjust("36500 days"); yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); diff --git a/apps/server/src/vcs/checkpointUntrackedBlobs.ts b/apps/server/src/vcs/checkpointUntrackedBlobs.ts index 675dba012161..889d189e13cd 100644 --- a/apps/server/src/vcs/checkpointUntrackedBlobs.ts +++ b/apps/server/src/vcs/checkpointUntrackedBlobs.ts @@ -253,7 +253,8 @@ export const make = ( const paths = [...blobs.map((blob) => blob.path), ...snapshot.pending]; if (paths.length === 0) return NOTHING; const unchecked = Effect.succeed({ exitCode: 1, stdout: "" }); - const stdin = `${blobs.map((blob) => `${blob.path}\0`).join("")}`; + // ./ avoids leading : pathspec magic; check-ignore rejects --literal-pathspecs. + const stdin = blobs.map((blob) => `./${blob.path}\0`).join(""); const [config, attributes, ignored, objects] = yield* Effect.all( [ readConfig(input.cwd), @@ -290,7 +291,9 @@ export const make = ( attributes: new Map(paths.map((entryPath, index) => [entryPath, attributes[index]])), }; if (config !== snapshot.config || ignored.exitCode > 1) return { reused: [], before }; - const ignoredPaths = new Set(ignored.stdout.split("\0")); + const ignoredPaths = new Set( + ignored.stdout.split("\0").map((entryPath) => entryPath.replace(/^\.\//, "")), + ); const present = new Set(objects.stdout.split("\n")); blobs = blobs.filter( (blob, index) =>