-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add a special case for git config discovery inside tests #7944
Conversation
r? @ehuss (rust_highfive has picked a reviewer for you, use r? to override) |
d24c64c
to
a68c3c0
Compare
Thanks! This looks like it changes the behavior when config files fail to load. Previously errors were ignored, and I think it would be good to preserve that behavior. |
a68c3c0
to
64e5b01
Compare
I have restored the previous behavior as requested. I went even further with It bothers me a bit that the code to do that turned out to be not very elegant:
There are probably some combinators that could be applied here to seamlessly integrate with the code that goes after it, but I couldn't come up with any. Suggestions welcome! |
src/cargo/ops/cargo_new.rs
Outdated
let current_working_directory = env::current_dir(); | ||
|
||
if current_working_directory.is_err() { | ||
return GitConfig::open_default().ok(); | ||
} | ||
|
||
let current_working_directory = current_working_directory.unwrap(); | ||
|
||
GitRepository::discover(current_working_directory) | ||
.and_then(|repo| repo.config()) | ||
.or_else(|_| GitConfig::open_default()) | ||
.ok() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified with a match.
let current_working_directory = env::current_dir(); | |
if current_working_directory.is_err() { | |
return GitConfig::open_default().ok(); | |
} | |
let current_working_directory = current_working_directory.unwrap(); | |
GitRepository::discover(current_working_directory) | |
.and_then(|repo| repo.config()) | |
.or_else(|_| GitConfig::open_default()) | |
.ok() | |
match env::current_dir() { | |
Ok(cwd) => GitRepository::discover(cwd) | |
.and_then(|repo| repo.config()) | |
.or_else(|_| GitConfig::open_default()) | |
.ok(), | |
Err(_) => GitConfig::open_default().ok(), | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. I was trying to cram it into one chain to avoid duplicating GitConifg::open_default()
call (is that even possible?), but your suggestion looks quite clear
src/cargo/ops/cargo_new.rs
Outdated
fn find_tests_git_config(cargo_test_root: String) -> Option<GitConfig> { | ||
// Path where 'git config --local' puts variables when run from inside a test | ||
let test_git_config = PathBuf::from(cargo_test_root).join(".git").join("config"); | ||
let test_git_config = test_git_config.as_path(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This as_path
isn't necessary. You can pass &test_git_config
to open()
and the auto-deref will convert it as necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Applied
e4ea640
to
153213f
Compare
@ehuss There are now two additional commits as a result of the review, should I squash everything into one for cleaner history? |
Yea, if you could squash, that would be great. We're often not too careful about that here, but I do prefer a cleaner history. |
Fixes rust-lang#7469: Some tests will fail if one have a local git config user.name/user.email
153213f
to
0f51c48
Compare
Done. Didn't want to do that during the review to make it easier to view the changes. |
Thanks! 😄 @bors r+ |
📌 Commit 0f51c48 has been approved by |
☀️ Test successful - checks-azure |
Update cargo, clippy Closes #69601 ## cargo 16 commits in e57bd02999c9f40d52116e0beca7d1dccb0643de..bda50510d1daf6e9c53ad6ccf603da6e0fa8103f 2020-02-21 20:20:10 +0000 to 2020-03-02 18:05:34 +0000 - Fix rare failure in collision_export test. (rust-lang/cargo#7956) - Ignore broken Cargo.toml in git sources (rust-lang/cargo#7947) - Add more fingerprint mtime debug logging. (rust-lang/cargo#7952) - Fix plugin tests for latest nightly. (rust-lang/cargo#7955) - Simplified usage code of SipHasher (rust-lang/cargo#7945) - Add a special case for git config discovery inside tests (rust-lang/cargo#7944) - Fixes issue rust-lang/cargo#7543 (rust-lang/cargo#7946) - Filter out cfgs which should not be used during build (rust-lang/cargo#7943) - Provide extra context on a query failure. (rust-lang/cargo#7934) - Try to clarify `cargo metadata`'s relationship with the workspace. (rust-lang/cargo#7927) - Update libgit2 dependency (rust-lang/cargo#7939) - Fix link in comment (rust-lang/cargo#7936) - Enable `cargo doc --open` tests on macos. (rust-lang/cargo#7932) - build-std: remove sysroot probe (rust-lang/cargo#7931) - Try to clarify how feature flags work on the "current" package. (rust-lang/cargo#7928) - Add extra details in the new feature resolver doc comment. (rust-lang/cargo#7918) ## clippy 6 commits in fc5d0cc..8b7f7e6 2020-02-24 05:58:17 +0000 to 2020-03-02 20:00:31 +0000 - Rustup to #69469 (rust-lang/rust-clippy#5254) - Some rustups (rust-lang/rust-clippy#5247) - Update git2 to 0.12 (rust-lang/rust-clippy#5232) - Rustup to #61812 (rust-lang/rust-clippy#5231) - Add lint to improve floating-point expressions (rust-lang/rust-clippy#4897) - Do not run deploy action on other repos (rust-lang/rust-clippy#5222)
Fixes #7469: Some tests will fail if one have a local git config user.name/user.email