Skip to content

Commit ffa9cf9

Browse files
committed
Auto merge of #13997 - epage:config, r=weihanglo
[beta-1.79] fix(config): Ensure `--config net.git-fetch-with-cli=true` is respected Beta backports - #13992 In order to make CI pass, the following PRs are also cherry-picked: - #13964
2 parents 9ca20fa + 947466b commit ffa9cf9

File tree

4 files changed

+79
-75
lines changed

4 files changed

+79
-75
lines changed

src/cargo/util/context/mod.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,31 @@ impl GlobalContext {
10201020
unstable_flags: &[String],
10211021
cli_config: &[String],
10221022
) -> CargoResult<()> {
1023+
for warning in self
1024+
.unstable_flags
1025+
.parse(unstable_flags, self.nightly_features_allowed)?
1026+
{
1027+
self.shell().warn(warning)?;
1028+
}
1029+
if !unstable_flags.is_empty() {
1030+
// store a copy of the cli flags separately for `load_unstable_flags_from_config`
1031+
// (we might also need it again for `reload_rooted_at`)
1032+
self.unstable_flags_cli = Some(unstable_flags.to_vec());
1033+
}
1034+
if !cli_config.is_empty() {
1035+
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
1036+
self.merge_cli_args()?;
1037+
}
1038+
if self.unstable_flags.config_include {
1039+
// If the config was already loaded (like when fetching the
1040+
// `[alias]` table), it was loaded with includes disabled because
1041+
// the `unstable_flags` hadn't been set up, yet. Any values
1042+
// fetched before this step will not process includes, but that
1043+
// should be fine (`[alias]` is one of the only things loaded
1044+
// before configure). This can be removed when stabilized.
1045+
self.reload_rooted_at(self.cwd.clone())?;
1046+
}
1047+
10231048
// Ignore errors in the configuration files. We don't want basic
10241049
// commands like `cargo version` to error out due to config file
10251050
// problems.
@@ -1066,31 +1091,6 @@ impl GlobalContext {
10661091
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
10671092
self.target_dir = cli_target_dir;
10681093

1069-
for warning in self
1070-
.unstable_flags
1071-
.parse(unstable_flags, self.nightly_features_allowed)?
1072-
{
1073-
self.shell().warn(warning)?;
1074-
}
1075-
if !unstable_flags.is_empty() {
1076-
// store a copy of the cli flags separately for `load_unstable_flags_from_config`
1077-
// (we might also need it again for `reload_rooted_at`)
1078-
self.unstable_flags_cli = Some(unstable_flags.to_vec());
1079-
}
1080-
if !cli_config.is_empty() {
1081-
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
1082-
self.merge_cli_args()?;
1083-
}
1084-
if self.unstable_flags.config_include {
1085-
// If the config was already loaded (like when fetching the
1086-
// `[alias]` table), it was loaded with includes disabled because
1087-
// the `unstable_flags` hadn't been set up, yet. Any values
1088-
// fetched before this step will not process includes, but that
1089-
// should be fine (`[alias]` is one of the only things loaded
1090-
// before configure). This can be removed when stabilized.
1091-
self.reload_rooted_at(self.cwd.clone())?;
1092-
}
1093-
10941094
self.load_unstable_flags_from_config()?;
10951095

10961096
Ok(())

tests/testsuite/cargo/z_help/stdout.term.svg

+34-37
Loading

tests/testsuite/config_cli.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ use std::{collections::HashMap, fs};
1111
#[cargo_test]
1212
fn basic() {
1313
// Simple example.
14-
let gctx = GlobalContextBuilder::new().config_arg("foo='bar'").build();
14+
let gctx = GlobalContextBuilder::new()
15+
.config_arg("foo='bar'")
16+
.config_arg("net.git-fetch-with-cli=true")
17+
.build();
1518
assert_eq!(gctx.get::<String>("foo").unwrap(), "bar");
19+
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));
1620
}
1721

1822
#[cargo_test]
@@ -39,13 +43,16 @@ fn cli_priority() {
3943
.env("CARGO_BUILD_JOBS", "2")
4044
.env("CARGO_BUILD_RUSTC", "env")
4145
.env("CARGO_TERM_VERBOSE", "false")
46+
.env("CARGO_NET_GIT_FETCH_WITH_CLI", "false")
4247
.config_arg("build.jobs=1")
4348
.config_arg("build.rustc='cli'")
4449
.config_arg("term.verbose=true")
50+
.config_arg("net.git-fetch-with-cli=true")
4551
.build();
4652
assert_eq!(gctx.get::<i32>("build.jobs").unwrap(), 1);
4753
assert_eq!(gctx.get::<String>("build.rustc").unwrap(), "cli");
4854
assert_eq!(gctx.get::<bool>("term.verbose").unwrap(), true);
55+
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));
4956

5057
// Setting both term.verbose and term.quiet is invalid and is tested
5158
// in the run test suite.

tests/testsuite/fix.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn do_not_fix_broken_builds() {
1616
r#"
1717
pub fn foo() {
1818
let mut x = 3;
19-
drop(x);
19+
let _ = x;
2020
}
2121
2222
pub fn foo2() {
@@ -427,7 +427,7 @@ fn fix_deny_warnings() {
427427
.file(
428428
"src/lib.rs",
429429
"#![deny(warnings)]
430-
pub fn foo() { let mut x = 3; drop(x); }
430+
pub fn foo() { let mut x = 3; let _ = x; }
431431
",
432432
)
433433
.build();
@@ -503,25 +503,25 @@ fn fix_two_files() {
503503
#[cargo_test]
504504
fn fixes_missing_ampersand() {
505505
let p = project()
506-
.file("src/main.rs", "fn main() { let mut x = 3; drop(x); }")
506+
.file("src/main.rs", "fn main() { let mut x = 3; let _ = x; }")
507507
.file(
508508
"src/lib.rs",
509509
r#"
510-
pub fn foo() { let mut x = 3; drop(x); }
510+
pub fn foo() { let mut x = 3; let _ = x; }
511511
512512
#[test]
513-
pub fn foo2() { let mut x = 3; drop(x); }
513+
pub fn foo2() { let mut x = 3; let _ = x; }
514514
"#,
515515
)
516516
.file(
517517
"tests/a.rs",
518518
r#"
519519
#[test]
520-
pub fn foo() { let mut x = 3; drop(x); }
520+
pub fn foo() { let mut x = 3; let _ = x; }
521521
"#,
522522
)
523-
.file("examples/foo.rs", "fn main() { let mut x = 3; drop(x); }")
524-
.file("build.rs", "fn main() { let mut x = 3; drop(x); }")
523+
.file("examples/foo.rs", "fn main() { let mut x = 3; let _ = x; }")
524+
.file("build.rs", "fn main() { let mut x = 3; let _ = x; }")
525525
.build();
526526

527527
p.cargo("fix --all-targets --allow-no-vcs")
@@ -701,8 +701,8 @@ fn does_not_warn_about_dirty_ignored_files() {
701701
#[cargo_test]
702702
fn fix_all_targets_by_default() {
703703
let p = project()
704-
.file("src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
705-
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; drop(x); }")
704+
.file("src/lib.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
705+
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
706706
.build();
707707
p.cargo("fix --allow-no-vcs")
708708
.env("__CARGO_FIX_YOLO", "1")
@@ -1280,7 +1280,7 @@ fn fix_to_broken_code() {
12801280
"#,
12811281
)
12821282
.file("bar/build.rs", "fn main() {}")
1283-
.file("bar/src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
1283+
.file("bar/src/lib.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
12841284
.build();
12851285

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

12971297
assert_eq!(
12981298
p.read_file("bar/src/lib.rs"),
1299-
"pub fn foo() { let x = 3; drop(x); }"
1299+
"pub fn foo() { let x = 3; let _ = x; }"
13001300
);
13011301
}
13021302

0 commit comments

Comments
 (0)