diff --git a/apps/web/src/components/chat/ChangedFilesTree.tsx b/apps/web/src/components/chat/ChangedFilesTree.tsx index 6b49b81401f33..5638949650b16 100644 --- a/apps/web/src/components/chat/ChangedFilesTree.tsx +++ b/apps/web/src/components/chat/ChangedFilesTree.tsx @@ -48,7 +48,7 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: { } = props; const syncTimelineLayout = useSyncLayout(); const hiddenFileCount = totals.count - files.length; - const hasDirectories = files.some((file) => /[/\\]/.test(file.path)); + const hasDirectories = files.some((file) => file.path.includes("/")); return (
{ }, ]); }); + + it("keeps literal backslashes in file names apart from directory paths", () => { + const tree = buildTurnDiffTree([ + { path: "back\\slash.txt", kind: "modified", additions: 1, deletions: 0 }, + { path: "back/slash.txt", kind: "modified", additions: 2, deletions: 0 }, + ]); + + expect(tree).toEqual([ + { + kind: "directory", + name: "back", + path: "back", + stat: { additions: 2, deletions: 0 }, + children: [ + { + kind: "file", + name: "slash.txt", + path: "back/slash.txt", + stat: { additions: 2, deletions: 0 }, + }, + ], + }, + { + kind: "file", + name: "back\\slash.txt", + path: "back\\slash.txt", + stat: { additions: 1, deletions: 0 }, + }, + ]); + }); }); diff --git a/apps/web/src/lib/turnDiffTree.ts b/apps/web/src/lib/turnDiffTree.ts index e841e18ce24d2..05346f900cce3 100644 --- a/apps/web/src/lib/turnDiffTree.ts +++ b/apps/web/src/lib/turnDiffTree.ts @@ -32,11 +32,10 @@ interface MutableDirectoryNode { let sortCollator: Intl.Collator | undefined; +// Checkpoint paths come from Git, which separates directories with "/" on every +// platform. A backslash is part of a POSIX file name, not a separator. function normalizePathSegments(pathValue: string): string[] { - return pathValue - .replaceAll("\\", "/") - .split("/") - .filter((segment) => segment.length > 0); + return pathValue.split("/").filter((segment) => segment.length > 0); } function compareByName(a: { name: string }, b: { name: string }): number {