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

[beta-1.79] fix(config): Ensure --config net.git-fetch-with-cli=true is respected #13997

Merged
merged 3 commits into from
Jun 3, 2024
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
50 changes: 25 additions & 25 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,31 @@ impl GlobalContext {
unstable_flags: &[String],
cli_config: &[String],
) -> CargoResult<()> {
for warning in self
.unstable_flags
.parse(unstable_flags, self.nightly_features_allowed)?
{
self.shell().warn(warning)?;
}
if !unstable_flags.is_empty() {
// store a copy of the cli flags separately for `load_unstable_flags_from_config`
// (we might also need it again for `reload_rooted_at`)
self.unstable_flags_cli = Some(unstable_flags.to_vec());
}
if !cli_config.is_empty() {
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
self.merge_cli_args()?;
}
if self.unstable_flags.config_include {
// If the config was already loaded (like when fetching the
// `[alias]` table), it was loaded with includes disabled because
// the `unstable_flags` hadn't been set up, yet. Any values
// fetched before this step will not process includes, but that
// should be fine (`[alias]` is one of the only things loaded
// before configure). This can be removed when stabilized.
self.reload_rooted_at(self.cwd.clone())?;
}

// Ignore errors in the configuration files. We don't want basic
// commands like `cargo version` to error out due to config file
// problems.
Expand Down Expand Up @@ -1066,31 +1091,6 @@ impl GlobalContext {
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
self.target_dir = cli_target_dir;

for warning in self
.unstable_flags
.parse(unstable_flags, self.nightly_features_allowed)?
{
self.shell().warn(warning)?;
}
if !unstable_flags.is_empty() {
// store a copy of the cli flags separately for `load_unstable_flags_from_config`
// (we might also need it again for `reload_rooted_at`)
self.unstable_flags_cli = Some(unstable_flags.to_vec());
}
if !cli_config.is_empty() {
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
self.merge_cli_args()?;
}
if self.unstable_flags.config_include {
// If the config was already loaded (like when fetching the
// `[alias]` table), it was loaded with includes disabled because
// the `unstable_flags` hadn't been set up, yet. Any values
// fetched before this step will not process includes, but that
// should be fine (`[alias]` is one of the only things loaded
// before configure). This can be removed when stabilized.
self.reload_rooted_at(self.cwd.clone())?;
}

self.load_unstable_flags_from_config()?;

Ok(())
Expand Down
71 changes: 34 additions & 37 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion tests/testsuite/config_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ use std::{collections::HashMap, fs};
#[cargo_test]
fn basic() {
// Simple example.
let gctx = GlobalContextBuilder::new().config_arg("foo='bar'").build();
let gctx = GlobalContextBuilder::new()
.config_arg("foo='bar'")
.config_arg("net.git-fetch-with-cli=true")
.build();
assert_eq!(gctx.get::<String>("foo").unwrap(), "bar");
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));
}

#[cargo_test]
Expand All @@ -39,13 +43,16 @@ fn cli_priority() {
.env("CARGO_BUILD_JOBS", "2")
.env("CARGO_BUILD_RUSTC", "env")
.env("CARGO_TERM_VERBOSE", "false")
.env("CARGO_NET_GIT_FETCH_WITH_CLI", "false")
.config_arg("build.jobs=1")
.config_arg("build.rustc='cli'")
.config_arg("term.verbose=true")
.config_arg("net.git-fetch-with-cli=true")
.build();
assert_eq!(gctx.get::<i32>("build.jobs").unwrap(), 1);
assert_eq!(gctx.get::<String>("build.rustc").unwrap(), "cli");
assert_eq!(gctx.get::<bool>("term.verbose").unwrap(), true);
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));

// Setting both term.verbose and term.quiet is invalid and is tested
// in the run test suite.
Expand Down
24 changes: 12 additions & 12 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn do_not_fix_broken_builds() {
r#"
pub fn foo() {
let mut x = 3;
drop(x);
let _ = x;
}

pub fn foo2() {
Expand Down Expand Up @@ -427,7 +427,7 @@ fn fix_deny_warnings() {
.file(
"src/lib.rs",
"#![deny(warnings)]
pub fn foo() { let mut x = 3; drop(x); }
pub fn foo() { let mut x = 3; let _ = x; }
",
)
.build();
Expand Down Expand Up @@ -503,25 +503,25 @@ fn fix_two_files() {
#[cargo_test]
fn fixes_missing_ampersand() {
let p = project()
.file("src/main.rs", "fn main() { let mut x = 3; drop(x); }")
.file("src/main.rs", "fn main() { let mut x = 3; let _ = x; }")
.file(
"src/lib.rs",
r#"
pub fn foo() { let mut x = 3; drop(x); }
pub fn foo() { let mut x = 3; let _ = x; }

#[test]
pub fn foo2() { let mut x = 3; drop(x); }
pub fn foo2() { let mut x = 3; let _ = x; }
"#,
)
.file(
"tests/a.rs",
r#"
#[test]
pub fn foo() { let mut x = 3; drop(x); }
pub fn foo() { let mut x = 3; let _ = x; }
"#,
)
.file("examples/foo.rs", "fn main() { let mut x = 3; drop(x); }")
.file("build.rs", "fn main() { let mut x = 3; drop(x); }")
.file("examples/foo.rs", "fn main() { let mut x = 3; let _ = x; }")
.file("build.rs", "fn main() { let mut x = 3; let _ = x; }")
.build();

p.cargo("fix --all-targets --allow-no-vcs")
Expand Down Expand Up @@ -701,8 +701,8 @@ fn does_not_warn_about_dirty_ignored_files() {
#[cargo_test]
fn fix_all_targets_by_default() {
let p = project()
.file("src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; drop(x); }")
.file("src/lib.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
.build();
p.cargo("fix --allow-no-vcs")
.env("__CARGO_FIX_YOLO", "1")
Expand Down Expand Up @@ -1280,7 +1280,7 @@ fn fix_to_broken_code() {
"#,
)
.file("bar/build.rs", "fn main() {}")
.file("bar/src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
.file("bar/src/lib.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
.build();

// Build our rustc shim
Expand All @@ -1296,7 +1296,7 @@ fn fix_to_broken_code() {

assert_eq!(
p.read_file("bar/src/lib.rs"),
"pub fn foo() { let x = 3; drop(x); }"
"pub fn foo() { let x = 3; let _ = x; }"
);
}

Expand Down