Skip to content

Commit

Permalink
Auto merge of #11579 - kawaemon:show-progress-on-git-cli-fetch, r=wei…
Browse files Browse the repository at this point in the history
…hanglo

Show progress of crates.io index update even `net.git-fetch-with-cli` option enabled

### What does this PR try to resolve?

This PR fixes #11574 .

### How should we test and review this PR?

Please run `cargo` with `net.git-fetch-with-cli` option enabled.
It should show `git fetch`'s progress output like below.
```
❯ CARGO_NET_GIT_FETCH_WITH_CLI=true ./target/debug/cargo b
    Updating crates.io index
remote: Enumerating objects: 139821, done.
remote: Counting objects: 100% (2226/2226), done.
remote: Compressing objects: 100% (769/769), done.
receiving objects:   0% (1/139821)
```
  • Loading branch information
bors committed Jan 16, 2023
2 parents f0b6f81 + 5bd8ef6 commit 2a5ff4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utilities for handling git repositories, mainly around
//! authentication/cloning.
use crate::core::GitReference;
use crate::core::{GitReference, Verbosity};
use crate::util::errors::CargoResult;
use crate::util::{human_readable_bytes, network, Config, IntoUrl, MetricsCounter, Progress};
use anyhow::{anyhow, Context as _};
Expand Down Expand Up @@ -933,6 +933,15 @@ fn fetch_with_cli(
if tags {
cmd.arg("--tags");
}
match config.shell().verbosity() {
Verbosity::Normal => {}
Verbosity::Verbose => {
cmd.arg("--verbose");
}
Verbosity::Quiet => {
cmd.arg("--quiet");
}
}
cmd.arg("--force") // handle force pushes
.arg("--update-head-ok") // see discussion in #2078
.arg(url)
Expand All @@ -952,7 +961,7 @@ fn fetch_with_cli(
config
.shell()
.verbose(|s| s.status("Running", &cmd.to_string()))?;
cmd.exec_with_output()?;
cmd.exec()?;
Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,8 @@ fn use_the_cli() {
let stderr = "\
[UPDATING] git repository `[..]`
[RUNNING] `git fetch [..]`
From [..]
* [new ref] -> origin/HEAD
[COMPILING] dep1 [..]
[RUNNING] `rustc [..]`
[COMPILING] foo [..]
Expand Down

0 comments on commit 2a5ff4c

Please sign in to comment.