问题
Cargo获取私有gitlab存储库代码失败,git凭证不起作用,在cargo.toml中写入用户名/密码。
_git-credentials不起作用_
$ 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 cargo.toml中的用户名/密码没问题_
$ 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
笔记
$ cargo version
cargo 1.39.0 (1c6ec66d5 2019-09-30)
$ git version
git version 2.23.0
我也经常遇到这个问题,尤其是当试图在CI作业中为私有锈依赖项设置身份验证时。 拥有一种可以继承用户默认git凭据而不是使用~/.git-credentials
技巧的货运模式将非常有帮助。
解决这个问题
$ cat ~/.cargo/config
[net]
git-fetch-with-cli = true
解决这个问题
$ cat ~/.cargo/config [net] git-fetch-with-cli = true
非常感谢您的回答!!!
此外, Cargo的配置为$CARGO_HOME/config
。 如果设置自定义$ CARGO_HOME,这可能很重要。
$ CARGO_HOME / config,默认为:
Windows:%USERPROFILE%.cargo \ config
Unix:$ HOME / .cargo / config
最有用的评论
解决这个问题