Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tensorchen opened this issue Nov 18, 2019 · 3 comments
Closed
Labels
A-git Area: anything dealing with git C-bug Category: bug

Comments

@tensorchen
Copy link

tensorchen commented Nov 18, 2019

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:xxx_mypassword@git.code.oa.com

$ 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:xxx_mypassword@git.code.oa.com/birdio/l5-rs", branch = "master"}

$ cargo build 
Updating git repository `http://tensorchen:xxxx@git.code.oa.com/birdio/l5-rs`
   Compiling l5 v0.1.0 (http://tensorchen:xxxxx@git.code.oa.com/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
@tensorchen tensorchen added the C-bug Category: bug label Nov 18, 2019
@kitfre
Copy link

kitfre commented Dec 1, 2019

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.

@ehuss ehuss added the A-git Area: anything dealing with git label Dec 3, 2019
@tensorchen
Copy link
Author

Solve this problem

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

@FideoJ
Copy link

FideoJ commented May 7, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants