cargo-edit icon indicating copy to clipboard operation
cargo-edit copied to clipboard

`cargo add` no longer works with Git using SSH in 0.8.0

Open frxstrem opened this issue 3 years ago • 8 comments

I've configured Git to use SSH by default for all GitHub URLs, including HTTPS, which the command:

$ git config --global [email protected]:.insteadof https://github.com/

which will replace the prefix https://github.com/ with [email protected]: in all git URLs.

This works perfectly fine when pulling the crates.io index with Git:

$ git clone https://github.com/rust-lang/crates.io-index --depth=1
Cloning into 'crates.io-index'...
remote: Enumerating objects: 85891, done.
remote: Counting objects: 100% (85891/85891), done.
remote: Compressing objects: 100% (38459/38459), done.
Receiving objects: 100% (85891/85891), 39.48 MiB | 11.68 MiB/s, done.
remote: Total 85891 (delta 44780), reused 74962 (delta 37395), pack-reused 0
Resolving deltas: 100% (44780/44780), done.
Updating files: 100% (67956/67956), done.

But it does not work when running cargo add:

$ cargo add --version
cargo-add 0.8.0
$ cargo add serde
    Updating 'https://github.com/rust-lang/crates.io-index' index
Command failed due to unhandled error: authentication required but no callback set; class=Ssh (23); code=Auth (-16)

Steps to reproduce:

  1. Install cargo-edit version 0.8.0.
  2. Run cargo add serde in a clean Rust project. This works without any errors.
  3. Add an SSH key valid for GitHub to ~/.ssh/id_rsa.
  4. Run git config --global [email protected]:.insteadof https://github.com/.
  5. Repeat step 2, which now fails with the error above.

I'm unable to reproduce the issue with version 0.7.0, so this seems to have been broken with the release of 0.8.0.

frxstrem avatar Sep 23 '21 20:09 frxstrem

I assume regular cargo commands can successfully interact with the registry?

epage avatar Sep 23 '21 22:09 epage

Also, could you try with --features vendored-libgit2?

epage avatar Sep 23 '21 22:09 epage

@epage Yes, regular cargo commands can interact with the registry just fine. They also seem to respect the git configuration (for example, they'll fail if it's misconfigured).

I tried running cargo install cargo-edit --features vendored-libgit2, after which cargo add still did not work and gave the same error as before.

frxstrem avatar Sep 24 '21 00:09 frxstrem

cargo add failed in my machine with message Command failed due to unhandled error: invalid version 0 on git_proxy_options; class=Invalid (3) but work fine when I install it with cargo install cargo-edit --features vendored-libgit2

dungph avatar Sep 24 '21 06:09 dungph

This is a regression introduced in #484. Opened https://github.com/frewsxcv/rust-crates-index/issues/65 upstream.

cargo add failed in my machine with message Command failed due to unhandled error: invalid version 0 on git_proxy_options; class=Invalid (3) but work fine when I install it with cargo install cargo-edit --features vendored-libgit2

That's a separate issue, see #510.

ordian avatar Sep 24 '21 08:09 ordian

In part, I'm tempted t revert #484. On the other hand, I'm unsure how much to worry about cargo add (though this also impacts cargo upgrade) because cargo add is going to need to be rewritten anyways when we upstream it into cargo.

epage avatar Sep 24 '21 13:09 epage

Looks like we need to be tracking https://github.com/frewsxcv/rust-crates-index/issues/37

epage avatar Sep 24 '21 14:09 epage

The best workaround I found for this:

cargo update && cargo upgrade --offline

Seems to be working well because cargo update downloads the updated index.

nyurik avatar Dec 17 '21 18:12 nyurik