d33tah
d33tah

Reputation: 11561

How to make gitconfig's InsteadOf work with Cargo?

I have the following in my ~/.gitconfig:

[url "[email protected]:"]
       pushInsteadOf = https://github.com/
       insteadOf = https://github.com/

Unfortunately today I discovered that this prevents me from making cargo build download dependencies for me:

    Updating crates.io index
error: failed to get `libc` as a dependency of package `hilbert-c2rust v0.1.4 (/home/d33tah/workspace/profound/hilbert-c2rust)`

Caused by:
  failed to load source for dependency `libc`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded

Caused by:
  no authentication available

Is there a workaround for this problem? Commenting out the lines temporarily helps, but I'd like to keep them because they solve a problem related to Github for me.

Upvotes: 8

Views: 6905

Answers (5)

NicolasElPapu
NicolasElPapu

Reputation: 1678

cd ~/.cargo
touch config

edit config with whatever you want i.e nvim config and paste this

[net]
git-fetch-with-cli = true

Upvotes: 1

vvxhid
vvxhid

Reputation: 111

Try this (from here):

[url "ssh://[email protected]/"]
    insteadOf = https://github.com

[url "https://github.com/rust-lang/crates.io-index"]
    insteadOf = https://github.com/rust-lang/crates.io-index

Upvotes: 6

Osoro
Osoro

Reputation: 422

For some reason creating an ssh-agent and adding your identities to the agent did it for me.

eval `ssh-agent -s`
ssh-add
cargo build

I believe this fix is particular to cargo because you can still pull and push to private repositories and yet the authentication will fail on cargo update.

Upvotes: 2

Ishan Kumar
Ishan Kumar

Reputation: 21

This also occurs when the user's git is configured with ssh and cargo is unable to find the key configured.

To solve this navigate to '.ssh' file and run ssh-add id_rsa and then try again.

This is the only solution that worked for me after hours of head hunting.

Upvotes: 0

Martin Cifko Štefček
Martin Cifko Štefček

Reputation: 493

Set env var CARGO_NET_GIT_FETCH_WITH_CLI to true.

Upvotes: 26

Related Questions