Cargo: Cargo gets private gitlab repository code failed by git-credentials store

Created on 18 Nov 2019  ·  3Comments  ·  Source: rust-lang/cargo

Problem

Cargo gets private gitlab repository code failed,git-credentials not work,write username/password in cargo.toml is ok.

_git-credentials not work_

$ cat ~/.gitconfig
[credential]
        helper = store

$ cat ~/.git-credentials
http://tensorchen:[email protected]

$ cat Cargo.toml
[package]
name = "xxxxx"
version = "0.1.0"
edition = "2018"

[dependencies]
l5 = {git = "http://git.code.oa.com/birdio/l5-rs", branch = "master"}

$ cargo build 
    Updating git repository `http://git.code.oa.com/birdio/l5-rs`
warning: spurious network error (2 tries remaining): failed to receive HTTP 200 response: got 401; class=Net (12)
warning: spurious network error (1 tries remaining): failed to receive HTTP 200 response: got 401; class=Net (12)
error: failed to load source for a dependency on `l5`

Caused by:
  Unable to update http://git.code.oa.com/birdio/l5-rs

Caused by:
  failed to fetch into /root/.cargo/git/db/l5-rs-56b3f1291d851527

Caused by:
  failed to receive HTTP 200 response: got 401; class=Net (12)

_write username/password in cargo.toml is ok_

$ cat Cargo.toml
[dependencies]
l5 = {git = "http://tensorchen:[email protected]/birdio/l5-rs", branch = "master"}

$ cargo build 
Updating git repository `http://tensorchen:[email protected]/birdio/l5-rs`
   Compiling l5 v0.1.0 (http://tensorchen:[email protected]/birdio/l5-rs#39fffd34)
   Compiling rust-by-example v0.1.0 (/root/git.code.oa.com/tensorchen/rust-by-example)
    Finished dev [unoptimized + debuginfo] target(s) in 0.52s

Notes

$ cargo version
cargo 1.39.0 (1c6ec66d5 2019-09-30)
$ git version
git version 2.23.0


A-git C-bug

Most helpful comment

Solve this problem

$ cat ~/.cargo/config
[net]
git-fetch-with-cli = true

All 3 comments

I've also often run into this problem, especially when trying to setup authentication inside a CI job for a private rust dependency. It would be super helpful to have a mode of cargo that inherits the users default git credentials rather than having to use the ~/.git-credentials trick.

Solve this problem

$ cat ~/.cargo/config
[net]
git-fetch-with-cli = true

Solve this problem

$ cat ~/.cargo/config
[net]
git-fetch-with-cli = true

Thanks a lot for this answer!!!
Additionally, Cargo’s configuration is $CARGO_HOME/config. This may matter if you set custom $CARGO_HOME.

$CARGO_HOME/config which defaults to:
Windows: %USERPROFILE%.cargo\config
Unix: $HOME/.cargo/config

Was this page helpful?
0 / 5 - 0 ratings