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

Add a special case for git config discovery inside tests #7944

Merged
merged 1 commit into from
Feb 28, 2020

Conversation

aleksator
Copy link
Contributor

@aleksator aleksator commented Feb 27, 2020

Fixes #7469: Some tests will fail if one have a local git config user.name/user.email

@rust-highfive
Copy link

r? @ehuss

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 27, 2020
@ehuss
Copy link
Contributor

ehuss commented Feb 27, 2020

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.

@aleksator
Copy link
Contributor Author

I have restored the previous behavior as requested. I went even further with env::current_dir()?, handing the error in place: now default git config is returned if that happens.

It bothers me a bit that the code to do that turned out to be not very elegant:

    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();

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!

Comment on lines 818 to 829
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()
Copy link
Contributor

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.

Suggested change
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(),
}

Copy link
Contributor Author

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

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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

src/cargo/ops/cargo_new.rs Outdated Show resolved Hide resolved
@aleksator
Copy link
Contributor Author

@ehuss There are now two additional commits as a result of the review, should I squash everything into one for cleaner history?

@ehuss
Copy link
Contributor

ehuss commented Feb 28, 2020

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
@aleksator
Copy link
Contributor Author

Done. Didn't want to do that during the review to make it easier to view the changes.

@ehuss
Copy link
Contributor

ehuss commented Feb 28, 2020

Thanks! 😄

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 28, 2020

📌 Commit 0f51c48 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 28, 2020
@bors
Copy link
Collaborator

bors commented Feb 28, 2020

⌛ Testing commit 0f51c48 with merge 6256eca...

@bors
Copy link
Collaborator

bors commented Feb 28, 2020

☀️ Test successful - checks-azure
Approved by: ehuss
Pushing 6256eca to master...

@bors bors merged commit 6256eca into rust-lang:master Feb 28, 2020
@aleksator aleksator deleted the 7469_git_config_discovery branch February 28, 2020 19:31
bors added a commit to rust-lang/rust that referenced this pull request Mar 2, 2020
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)
@ehuss ehuss added this to the 1.43.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some tests will fail if one have a local git config user.name/user.email
4 participants