feat: add subpath support for monorepo sparse checkout#47
Open
ChrisLally wants to merge 1 commit intovercel-labs:mainfrom
Open
feat: add subpath support for monorepo sparse checkout#47ChrisLally wants to merge 1 commit intovercel-labs:mainfrom
ChrisLally wants to merge 1 commit intovercel-labs:mainfrom
Conversation
|
@ChrisLally is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Comment on lines
+312
to
+313
| if resolved.subpath.is_some() && repo_path.exists() { | ||
| let _ = fs::remove_dir_all(&repo_path); |
There was a problem hiding this comment.
Suggested change
| if resolved.subpath.is_some() && repo_path.exists() { | |
| let _ = fs::remove_dir_all(&repo_path); | |
| if let Some(ref sp) = resolved.subpath { | |
| if repo_path.exists() { | |
| // If the requested subpath already exists on disk, reuse it instead | |
| // of deleting the entire repo directory (which would destroy files | |
| // checked out for other subpaths of the same repo/ref). | |
| if repo_path.join(sp).exists() { | |
| return FetchResult { | |
| package: format!("{}/{}", resolved.display_name, sp), | |
| version: resolved.git_ref.clone(), | |
| path: format!( | |
| "{}/{}", | |
| get_repo_relative_path(&resolved.display_name, &resolved.git_ref), | |
| sp | |
| ), | |
| success: true, | |
| error: None, | |
| registry: None, | |
| }; | |
| } | |
| // Subpath not present in the existing clone — must re-clone. | |
| // This will remove files from any previously sparse-checked-out | |
| // subpath; callers should handle stale sources.json entries. | |
| let _ = fs::remove_dir_all(&repo_path); | |
| } |
Fetching a different subpath of the same repo at the same ref deletes and re-clones the shared directory, destroying previously fetched subpath files while their sources.json entries remain as dangling references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #27
Ports the sparse-checkout and monorepo subpath behavior from vercel-labs/opensrc#28 to the Rust CLI.
Summary
Adds support for fetching only a subdirectory from a GitHub (or other git host) monorepo instead of the full repo. Uses
git sparse-checkoutwith--filter=blob:noneso only the requested path is downloaded.^ Screenshot:
opensrc path vercel/ai/packages/ai— cache directory~/.opensrc/repos/github.com/vercel/ai/mainwith only thepackages/aitree checked out.Supported syntax
Implementation
core/registries/repo.rs):RepoSpec/ResolvedRepocarry an optionalsubpath; repo specs with three or more path segments (and URL/tree forms) populate it.core/git.rs): When a subpath is present, clone uses--filter=blob:none --sparseandgit sparse-checkout set <subpath>instead of a full checkout.core/cache.rs): Repos live under~/.opensrc/repos/<host>/<owner>/<repo>/<ref>/(or$OPENSRC_HOME/repos/...ifOPENSRC_HOMEis set); the working tree only contains the sparse path.commands/path.rs,commands/remove.rs):opensrc pathresolves and prints the absolute directory;remove/sources.jsonhandling understands repo specs with subpaths.Why sparse checkout
Testing
core/registries/repo.rs(and related) for subpath parsing acrossowner/repo/...,github:, and URL/tree forms.cargo test --manifest-path packages/opensrc/cli/Cargo.tomlfrom the repo root.opensrc path vercel/ai/packages/ai.Breaking changes
None. Existing
owner/repousage is unchanged; subpath support is additive.