Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/web/src/components/diffs/diffFileTree.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ describe("diffFileTreeEntries", () => {
});
});

describe("diffFileTreeEntries", () => {
it("drops a file whose path became a directory in the same diff", () => {
const entries = diffFileTreeEntries([
file("deleted", "skills/react-composition"),
file("new", "skills/react-composition/SKILL.md"),
file("new", "skills/other.md"),
]);
expect(entries).toEqual([
{ path: "skills/react-composition/SKILL.md", status: "added" },
{ path: "skills/other.md", status: "added" },
]);
expect(() => preloadFileTree({ paths: entries.map((entry) => entry.path) })).not.toThrow();
});
});

describe("collectDirectoryPaths", () => {
it("lists every ancestor once, parents first, with Pierre's trailing slash", () => {
expect(collectDirectoryPaths(["apps/web/src/a.ts", "apps/web/b.ts", "README.md"])).toEqual([
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/diffs/diffFileTree.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function toGitStatus(file: FileDiffMetadata): GitStatus {
* Maps parsed diff files to tree entries, keeping the diff's own order. A path
* appears once: a type change (regular file to symlink) is a deletion plus an
* addition of the same path, and the tree shows the surviving file as modified.
*
* A file whose path is also a directory in the same diff (a file or symlink replaced by a
* folder) is left out: the tree cannot hold both, and the folder's files carry the change.
*/
export function diffFileTreeEntries(
files: ReadonlyArray<FileDiffMetadata>,
Expand All @@ -38,7 +41,10 @@ export function diffFileTreeEntries(
const previous = statusByPath.get(path);
statusByPath.set(path, previous === undefined || previous === status ? status : "modified");
}
return [...statusByPath].map(([path, status]) => ({ path, status }));
const directories = new Set(collectDirectoryPaths([...statusByPath.keys()]));
return [...statusByPath]
.filter(([path]) => !directories.has(`${path}/`))
.map(([path, status]) => ({ path, status }));
}

/**
Expand Down
Loading