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

feat: Support non-crates.io registries #69

Closed fasterthanlime closed 2 years ago

fasterthanlime commented 2 years ago

This matches cargo's behavior for registries that are not hosted on GitHub (like Cloudsmith), and uses the configured git credential helper to allow cloning private registries.

Needed for https://github.com/pksunkara/cargo-workspaces/pull/53


I'm as surprised as you probably are that cargo normalizes:

this:
https://github.com/rust-lang/crates.io-index.git
to this:
https://github.com/rust-lang/crates.io-index

But keeps something like https://dl.cloudsmith.io/basic/myorg/myrepo/cargo/index.git as-is. But if we don't reproduce cargo's behavior there, we won't use the same checkout directories, using up more disk space and being generally out-of-sync with cargo.

The other change is rather straightforward, I'm not sure why it's not libgit2's default, but apparently you need to spell out "please use the configured git credential helper to clone stuff". At least for Cloudsmith crate registries, that's a prerequisite - every user gets their own API token that's configured in something like ~/.git-credentials:

https://fasterthanlime:my_github_token@github.com
https://fasterthanlime:my_cloudsmith_token@dl.cloudsmith.io

...or really any of the Git credential helpers that exist. The bit of config in that PR should work no matter the credential helper, whether it's "store", some GUI thing on Windows, VSCode's odd "git credential forwarding helper" for dev containers, etc.

kornelski commented 2 years ago

That's great. Thank you.