Skip to content

Skip unchanged git marketplaces and fetch only the catalog on refresh - #8128

Merged
ymichael merged 2 commits into
get-bb:mainfrom
afn:marketplace-git-refresh
Nov 25, 2026
Merged

ymichael merged 2 commits into
get-bb:mainfrom
afn:marketplace-git-refresh

Conversation

@afn

@afn afn commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

Related to #7911 and #8116, this PR speeds up adding/updating git-hosted marketplaces, which can be painfully slow.

What was wrong

materializeGit in apps/server/src/services/plugin-catalog/marketplace-source.ts ran git clone --no-checkout <url> with no depth or filter, resolved the ref with rev-parse, checked out the whole tree, and deleted .git — on every bb marketplace add, every manual refresh, and every periodic refresh, without ever comparing the ref against the stored sourceGitCommit. For a marketplace monorepo with a long history that is ~87 s of download per refresh to read a 346 KB marketplace.json and 152 KB of icons. #7911 fixed the same clone for plugin installs; the marketplace path had its own. Fixes #8127.

What changed

  • marketplace-source.ts: materializeGit first resolves the ref with resolveGitRef (one ls-remote, the same resolver plugin installs use). If it resolves to the stored commit, the stored catalog is returned as unchanged: true with no checkout, like the https path does on a 304. If the ref moved (or there is no stored commit), the commit is fetched with git init + fetch --depth 1 --no-tags --filter=blob:none origin <sha> into a cone-mode sparse checkout: for a root marketplace, sparse-checkout set --cone (repository-root files only), then after reading marketplace.json sparse-checkout add of the directories its local icons live in; for a subdirectory marketplace, the subdirectory itself. The manifest and icons are then read exactly as before. If ls-remote cannot resolve the ref (for example origin/<branch>, which the existing rev-parse fallback accepts), the server refuses the fetch, the manifest, the subdirectory, or a local icon path crosses a symlink (whose target may lie outside the sparse tree), sparse-checkout add fails, or an icon directory or the subdirectory contains sparse-pattern characters, the code falls back to the previous full clone + checkout (sparse-checkout disable where a sparse tree already exists), so the caller sees the same tree a full clone would. Servers that do not advertise partial clone ignore --filter with a warning and the sparse working tree still applies.
  • marketplace-icons.ts: onlyMissing now also reuses cached local icons whose source path is unchanged, and skips local icons that are not cached, so an unchanged git refresh never reads from a checkout that was not made. Local icons only occur for git: and path: sources; path: is never unchanged, and at the same commit the files are identical. Remote icons behave as before.
  • plugin-catalog-service.ts: the refresh passes row.sourceGitCommit into cached. The add path passes cached: null and takes the sparse-fetch path. A stored catalog that fails to parse is re-read from the repository with a warning rather than failing the refresh.
  • No wire, CLI, or guide changes; which ref and subdirectory a marketplace reads is unchanged.

How you verified

  • New test refreshes an unchanged ref from the stored catalog without fetching the repository (third-party-marketplaces.test.ts): after addMarketplace, deletes the fixture repository's loose objects so ls-remote still answers but any clone or fetch fails, then asserts refreshMarketplaces returns ok: true with the same commit, the stored icon's content hash is unchanged, no warnings were emitted, and the staging directory is empty. Fails on main (fatal: … nonexistent object).
  • New tests fetches only the catalog and its icons when the ref moved (root) and fetches only the subdirectory when the ref moved (subdirectory): serve the fixture over file:// through an insteadOf rewrite with uploadpack.allowFilter=true, commit a new catalog (root case: with a second icon in a nested directory) plus plugins/alpha/dist/index.js, delete that blob's object, assert that git clone of the repository fails with possible repository corruption, and assert the refresh succeeds with the new commit, both entries and both icons. Fail on main (the full clone needs the missing blob).
  • New reads the catalog when %s cases (POSIX): marketplace.json, the subdirectory, an icon file, and the icons directory each a symlink to another path in the repository. The first three failed with the sparse checkout before the symlink check (ENOENT … marketplace.json, not a directory in the repository, icon dropped with a warning); all four match main.
  • Existing reads the selected catalog commit for ref %s cases still pass, including origin/catalog-next, which ls-remote cannot resolve and which now exercises the full-clone fallback, and catalog-release, an annotated tag that resolveGitRef peels.
  • pnpm exec turbo run test --filter=@bb/server -- test/services/plugin-catalog/: 171 passed (9 files). test/services/plugins/plugin-install.test.ts and plugin-update.test.ts: 104 passed. turbo run typecheck --filter=@bb/server: clean. oxlint on the touched files reports only the node:fs/promises import restriction already present on main.
  • Real-world, through createPluginCatalogService against the marketplace monorepo in Git marketplace refresh clones the whole repository even when the ref has not moved #8127 (89 entries, 39 icons stored, identical warnings before and after): addMarketplace 87.05 s → 3.54 s; refreshMarketplaces with the ref unchanged 87.72 s → 0.75 s.

Fixes #8127

AGENT GENERATED

materializeGit cloned the whole repository on every add and every
refresh of a git: marketplace, checked out the full tree, and deleted
.git. The refresh now resolves the ref with ls-remote first; when it
still points at the stored commit the stored catalog and icons are
reused without touching the repository. When the ref moved, the commit
is fetched with --depth 1 --filter=blob:none into a cone-mode sparse
checkout of the repository root (plus the icon directories the manifest
names) or of the selected subdirectory. Anything the fast path cannot
do falls back to the previous full clone.
The sparse checkout only holds the repository root files (or the
selected subdirectory) and the icon directories. A marketplace.json,
subdirectory, or icon file that is a symlink to another path in the
repository then pointed outside that tree, so add and refresh failed or
dropped the icon where a full clone succeeded. Check every path the
catalog read uses and disable the sparse checkout when one crosses a
symlink.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 3ae1d58 into get-bb:main Nov 25, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git marketplace refresh clones the whole repository even when the ref has not moved

2 participants