Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/book/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ Number of times to retry possibly spurious network errors.

#### `net.git-fetch-with-cli`
* Type: boolean
* Default: false
* Default: true if `git` is present, `false` otherwise
* Environment: `CARGO_NET_GIT_FETCH_WITH_CLI`

If this is `true`, then Cargo will use the `git` executable to fetch registry
Expand Down
6 changes: 5 additions & 1 deletion src/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,11 @@ pub fn fetch(
}

debug!("doing a fetch for {remote_url}");
let result = if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
let result = if gctx
.net_config()?
.git_fetch_with_cli
.unwrap_or_else(|| git_version().is_some())
Comment on lines +1105 to +1108

@weihanglo weihanglo Sep 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also update doc for net.git-fetch-with-cli.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specific to this PR, though there is a catch: cargo config get doesn't really reflect the if something then true else false logic. I don't think this is a blocker though worth some thinking.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #9301

{
fetch_with_cli(repo, remote_url, &refspecs, tags, shallow, gctx)
} else if gctx.cli_unstable().gitoxide.map_or(false, |git| git.fetch) {
fetch_with_gitoxide(repo, remote_url, refspecs, tags, shallow, gctx)
Expand Down
8 changes: 7 additions & 1 deletion tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ fn bad_git_dependency() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] git repository `file:///`
[RUNNING] `git [..] fetch [..]`
fatal: [..] does not appear to be a git repository
...
[ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 ([ROOT]/foo)`

Caused by:
Expand All @@ -452,7 +455,10 @@ Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/_empty-[HASH]

Caused by:
'file:///' is not a valid local file URI; class=Config (7)
`git fetch` failed for file:///

[HELP] re-try with `net.git-fetch-with-cli = false` to see if it resolves the problem
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

"#]])
.run();
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4657,6 +4657,9 @@ fn rustc_wrapper_relative() {
.env("RUSTC_WRAPPER", &relative_path)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 1 package to highest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5223,6 +5223,9 @@ fn warnings_hidden_for_upstream() {
p.cargo("check -v")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 1 package to highest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
Expand Down Expand Up @@ -5290,6 +5293,9 @@ fn warnings_printed_on_vv() {
p.cargo("check -vv")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 1 package to highest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/build_script_extra_link_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ fn link_arg_transitive_not_allowed() {
p.cargo("build -v")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 1 package to highest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ fn very_verbose() {
p.cargo("check -vv")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 1 package to highest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions tests/testsuite/cargo_info/verbose/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/testsuite/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ fn collision_doc_profile_split() {
.with_stderr_data(
str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 2 packages to highest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] common v1.0.0 (registry `dummy-registry`)
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/corrupt_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ fn deleting_database_files() {
),
)
.file("src/lib.rs", "")
.file(
".cargo/config.toml",
"
[net]
git-fetch-with-cli = false
",
)
.build();

project.cargo("check").run();
Expand Down Expand Up @@ -92,6 +99,13 @@ fn deleting_checkout_files() {
),
)
.file("src/lib.rs", "")
.file(
".cargo/config.toml",
"
[net]
git-fetch-with-cli = false
",
)
.build();

project.cargo("check").run();
Expand Down
9 changes: 9 additions & 0 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ fn multiple_providers() {
.replace_crates_io(server.index_url())
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[CREDENTIAL] [..]url_not_supported[..] login crates-io
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[ROOTURL]/api/me"}
[CREDENTIAL] [..]success_provider[..] login crates-io
Expand Down Expand Up @@ -465,6 +468,9 @@ fn registry_provider_overrides_global() {
.replace_crates_io(server.index_url())
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[CREDENTIAL] cargo:token login crates-io
[LOGIN] token for `crates-io` saved

Expand Down Expand Up @@ -496,6 +502,9 @@ fn both_asymmetric_and_token() {
.replace_crates_io(server.index_url())
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[RUNNING] `git [..] fetch [..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[WARNING] registry `crates-io` has a `secret_key` configured in [..]config.toml that will be ignored because a `token` is also configured, and the `cargo:token` provider is configured with higher precedence
[CREDENTIAL] cargo:token login crates-io
[LOGIN] token for `crates-io` saved
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4028,6 +4028,9 @@ fn mergeable_info_dep_collision() {
.with_stderr_data(
str![[r#"
[UPDATING] `dummy-registry` index
[RUNNING] `git[..] fetch[..]`
From [ROOTURL]/registry
* [new ref] HEAD -> origin/HEAD
[LOCKING] 2 packages to highest compatible versions
[ADDING] dep v0.1.0 (available: v0.2.0)
[DOWNLOADING] crates ...
Expand Down
17 changes: 16 additions & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4908,6 +4908,12 @@ fn dep_with_scp_like_submodule_url() {
.with_stderr_data(str![[r#"
[UPDATING] git repository `[ROOTURL]/dep1`
[UPDATING] git submodule `git@github.com:foo/bar.git`
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
...
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 ([ROOT]/foo)`

Caused by:
Expand All @@ -4921,7 +4927,16 @@ Caused by:

Caused by:
failed to fetch submodule `submod` from git@github.com:foo/bar.git
...

Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]

Caused by:
`git fetch` failed for git@github.com:foo/bar.git

[HELP] re-try with `net.git-fetch-with-cli = false` to see if it resolves the problem
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

"#]])
.run();
}
Expand Down
Loading
Loading