Skip to content

feat: add subpath support for monorepo sparse checkout#28

Open
ChrisLally wants to merge 2 commits intovercel-labs:mainfrom
ChrisLally:feat/subpath-sparse-checkout
Open

feat: add subpath support for monorepo sparse checkout#28
ChrisLally wants to merge 2 commits intovercel-labs:mainfrom
ChrisLally:feat/subpath-sparse-checkout

Conversation

@ChrisLally
Copy link

Description

Fixes #27

Summary

Adds support for fetching only a subdirectory from a GitHub (or other git host) monorepo instead of the full repo. Uses git sparse-checkout with --filter=blob:none so only the requested path is downloaded.

Screenshot 2026-02-27 at 11 14 46 PM

^ For example, I only wanted part of the vercel repo so the command "opensrc vercel/vercel/packages/cli" worked great now!

Supported syntax

opensrc owner/repo/packages/some-package
opensrc github:owner/repo/path/to/dir
opensrc vercel/ai/packages/ai@main
opensrc https://github.com/owner/repo/tree/main/packages/some-package

Implementation

  • Parsing (lib/repo.ts): Extended parseRepoSpec to handle 3+ path segments and extract a subpath (e.g. vercel/ai/packages/aiowner: vercel, repo: ai, subpath: packages/ai).
  • Types (types.ts): Added optional subpath to RepoSpec and ResolvedRepo.
  • Fetch (lib/git.ts): When subpath is set, uses git clone --filter=blob:none --sparse and git sparse-checkout set <subpath> instead of a full clone.
  • Output path: Files are stored at opensrc/repos/github.com/owner/repo/packages/ai to mirror the repo layout.

Why sparse checkout

  • Avoids cloning large monorepos when only one package is needed.
  • Uses Git’s built-in sparse checkout instead of many GitHub API calls.
  • Works with any git host (GitHub, GitLab, Bitbucket).

Testing

  • Added tests for subpath parsing in parseRepoSpec (owner/repo/subpath, URLs with tree/ref/subpath, github: prefix).
  • Added tests for isRepoSpec and detectInputType with subpath formats.
  • Manually tested with opensrc vercel/ai/packages/ai.

Breaking changes

None. Existing owner/repo usage is unchanged; subpath support is additive.

- Parse owner/repo/subpath syntax in parseRepoSpec
- Add sparse checkout when subpath specified (--filter=blob:none --sparse)
- Support github:, URLs, and tree/ref/subpath formats
- Add tests for subpath parsing and detectInputType
@vercel
Copy link

vercel bot commented Feb 28, 2026

@ChrisLally is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The "already up to date" early return in fetchRepoInput omits the subpath from the returned package and path fields, and looks up repo info using the base name instead of the subpath-qualified name.

Fix on Vercel

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.

[Feature Request] Support subdirectory fetching for GitHub repos

1 participant