frewsxcv / rust-crates-index

Rust library for retrieving and interacting with the crates.io index
https://docs.rs/crates-index/
Apache License 2.0
72 stars 37 forks source link

git: Bail out if the url is `sparse` #167

Open MarijnS95 opened 5 months ago

MarijnS95 commented 5 months ago

I ended up in the accidental case where my URL is sparse, and believe this could also happen if someone uses replace-with in their .cargo/ config.toml. When GitIndex is created, this ends up with a rather useless error:

Refusing to initialize the non-empty directory as '/home/me/.cargo/registry/index/my-custom-registry'

Because it is probably not finding a git repository at that place, without realizing that it's a sparse index cache.

To solve the replace-with case above, or make this crate more generally usable, shouldn't there be (if there isn't already) a high-level wrapper that automatically delegates to SparseIndex if the URL starts with sparse+, and hide the GitIndex/SparseIndex "internals"?