Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cargo-util-terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ anstyle.workspace = true
anstyle-hyperlink = { workspace = true, features = ["file"] }
anstyle-progress.workspace = true
anyhow.workspace = true
cargo-util.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
supports-hyperlinks.workspace = true
Expand Down
15 changes: 15 additions & 0 deletions crates/cargo-util-terminal/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ impl Shell {
url.map(|u| self.err_hyperlink(u)).unwrap_or_default()
}

/// Query terminal capability, independent of user configuration
pub fn progress_supported(&self) -> bool {
// report no progress when -q (for quiet) or TERM=dumb are set
// or if running on Continuous Integration service like Travis where the
// output logs get mangled.
if self.verbosity == Verbosity::Quiet
|| std::env::var("TERM").as_deref() == Ok("dumb")
|| cargo_util::is_ci()
{
false
} else {
true
}
}

fn unstable_flags_rustc_unicode(&self) -> bool {
match &self.output {
ShellOut::Write(_) => false,
Expand Down
25 changes: 18 additions & 7 deletions src/sources/git/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Utilities for handling git repositories, mainly around
//! authentication/cloning.

use crate::context::ProgressWhen;
use crate::sources::git::fetch::RemoteKind;
use crate::sources::git::oxide;
use crate::sources::git::oxide::cargo_config_to_gitoxide_overrides;
Expand Down Expand Up @@ -1156,15 +1157,25 @@ fn fetch_with_cli(
let depth = 0i32.saturating_add_unsigned(depth.get());
cmd.arg(format!("--depth={depth}"));
}
match gctx.shell().verbosity() {
Verbosity::Normal => {}
Verbosity::Verbose => {
cmd.arg("--verbose");
}
Verbosity::Quiet => {
cmd.arg("--quiet");

let progress_config = gctx.progress_config();
let progress = match progress_config.when {
ProgressWhen::Always => true,
ProgressWhen::Never => false,
ProgressWhen::Auto => {
// Recreate the same conditions used with `Progress`
let width = progress_config
.width
.or_else(|| gctx.shell().err_width().progress_max_width());
gctx.shell().progress_supported() && width.is_some()
}
};
if gctx.shell().verbosity() == Verbosity::Verbose {
cmd.arg("--verbose");
} else if !progress {
cmd.arg("--quiet");
}

cmd.arg("--force") // handle force pushes
.arg("--update-head-ok") // see discussion in #2078
.arg(url)
Expand Down
24 changes: 8 additions & 16 deletions src/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::time::{Duration, Instant};
use crate::context::ProgressWhen;
use crate::util::{CargoResult, GlobalContext};
use anstyle_progress::TermProgress;
use cargo_util::is_ci;
use cargo_util_terminal::Shell;
use cargo_util_terminal::Verbosity;
use unicode_width::UnicodeWidthChar;

/// CLI progress bar.
Expand Down Expand Up @@ -56,23 +54,17 @@ impl<'gctx> Progress<'gctx> {
style: ProgressStyle,
gctx: &'gctx GlobalContext,
) -> Progress<'gctx> {
// report no progress when -q (for quiet) or TERM=dumb are set
// or if running on Continuous Integration service like Travis where the
// output logs get mangled.
let dumb = match gctx.get_env("TERM") {
Ok(term) => term == "dumb",
Err(_) => false,
};
let progress_config = gctx.progress_config();
match progress_config.when {
ProgressWhen::Always => return Progress::new_priv(name, style, gctx),
ProgressWhen::Never => return Progress { gctx, state: None },
ProgressWhen::Auto => {}
}
if gctx.shell().verbosity() == Verbosity::Quiet || dumb || is_ci() {
let progress = match progress_config.when {
ProgressWhen::Always => true,
ProgressWhen::Never => false,
ProgressWhen::Auto => gctx.shell().progress_supported(),
};
if progress {
Progress::new_priv(name, style, gctx)
} else {
return Progress { gctx, state: None };
}
Progress::new_priv(name, style, gctx)
}

fn new_priv(name: &str, style: ProgressStyle, gctx: &'gctx GlobalContext) -> Progress<'gctx> {
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4237,11 +4237,11 @@ fn github_fastpath_error_message() {
.with_stderr_data(str![[r#"
[UPDATING] git repository `https://github.com/rust-lang/bitflags.git`
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
[WARNING] spurious network error (3 tries remaining): process didn't exit successfully: `git fetch --no-tags --force --update-head-ok [..]
[WARNING] spurious network error (3 tries remaining): process didn't exit successfully: `git fetch --no-tags --quiet --force --update-head-ok [..]
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
[WARNING] spurious network error (2 tries remaining): process didn't exit successfully: `git fetch --no-tags --force --update-head-ok [..]
[WARNING] spurious network error (2 tries remaining): process didn't exit successfully: `git fetch --no-tags --quiet --force --update-head-ok [..]
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
[WARNING] spurious network error (1 try remaining): process didn't exit successfully: `git fetch --no-tags --force --update-head-ok [..]
[WARNING] spurious network error (1 try remaining): process didn't exit successfully: `git fetch --no-tags --quiet --force --update-head-ok [..]
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`

Expand All @@ -4258,7 +4258,7 @@ Caused by:
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found

Caused by:
process didn't exit successfully: `git fetch --no-tags --force --update-head-ok [..]
process didn't exit successfully: `git fetch --no-tags --quiet --force --update-head-ok [..]

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