Skip to content

Commit dc2b16a

Browse files
fix(server): hidden-edit check keeps names that are not valid UTF-8
Git prints such names raw with core.quotePath=false and they decode with U+FFFD, so the decoded path never exists and the edit looked absent. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e26bb74 commit dc2b16a

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,39 @@ describe("storage cleanup reports and local file policies", () => {
24542454
}),
24552455
),
24562456
);
2457+
// macOS and Windows file systems reject names that are not valid UTF-8.
2458+
it.live.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
2459+
"keeps hidden edits to files whose names are not valid UTF-8",
2460+
() =>
2461+
runCleanupTest(
2462+
Effect.gen(function* () {
2463+
const { service, fs, worktree, command } = yield* cleanupFixture();
2464+
const git = yield* GitVcsDriver.GitVcsDriver;
2465+
// Git unquotes C-quoted paths on stdin, which reaches a name a JS string cannot.
2466+
const quoted = '"bad-\\377.txt"';
2467+
const stdin = (args: string[], input: string) =>
2468+
git.execute({ operation: "cleanup-test", cwd: worktree, args, stdin: input });
2469+
const blob = (content: string) =>
2470+
stdin(["hash-object", "-w", "--stdin"], content).pipe(
2471+
Effect.map((result) => result.stdout.trim()),
2472+
);
2473+
const original = yield* blob("original\n");
2474+
yield* stdin(["update-index", "--index-info"], `100644 ${original}\t${quoted}\n`);
2475+
yield* stdin(["checkout-index", "--stdin"], `${quoted}\n`);
2476+
yield* command(worktree, ["commit", "-m", "bad name"]);
2477+
// The committed content moves on while the file on disk keeps the other version.
2478+
const edited = yield* blob("edited\n");
2479+
yield* stdin(["update-index", "--index-info"], `100644 ${edited}\t${quoted}\n`);
2480+
yield* command(worktree, ["commit", "-m", "edit"]);
2481+
yield* stdin(["update-index", "--assume-unchanged", "--stdin"], `${quoted}\n`);
2482+
expect((yield* command(worktree, ["status", "--porcelain"])).stdout).toBe("");
2483+
expect((yield* service.runNow).entries[0]).toMatchObject({ outcome: "kept" });
2484+
expect((yield* fs.readDirectory(worktree)).some((name) => name.startsWith("bad-"))).toBe(
2485+
true,
2486+
);
2487+
}),
2488+
),
2489+
);
24572490
it.live("removes worktrees whose flagged files are unchanged or outside a sparse checkout", () =>
24582491
runCleanupTest(
24592492
Effect.gen(function* () {

‎apps/server/src/storageCleanup.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,9 @@ const make = Effect.gen(function* () {
644644
});
645645
if (overflow) return "hidden tracked files exceed the inspection limit";
646646
const reason = (file: string) => `has uncommitted changes hidden from git status (${file})`;
647-
// Git quotes names with control characters, quotes or backslashes, so the listed text is not a path on disk.
648-
const unreadable = flagged.find(({ file }) => file.startsWith('"'));
647+
// Quoted names (control characters, quotes, backslashes) and names that are not valid UTF-8
648+
// decode to text that is not the path on disk.
649+
const unreadable = flagged.find(({ file }) => file.startsWith('"') || file.includes("\uFFFD"));
649650
if (unreadable !== undefined) return reason(unreadable.file);
650651
const onDisk = yield* Effect.forEach(
651652
flagged,

0 commit comments

Comments
 (0)