Closed
Description
Problem
Running cargo test --all
will fail if you have a local .git/config
. Link to the log file is here https://gist.github.com/hbina/8b09995b55e95267b3286a99a30a54f2
Specifically, the following unit tests will fail.
new::finds_author_email
new::finds_author_git
new::finds_author_user
new::finds_author_user_escaped
new::finds_author_username
new::finds_git_author
new::strip_angle_bracket_author_email
Steps
- Clone the repository
- Set a local
user.name
and/oruser.email
- Run test
- ????
- No profit!
Possible Solution(s)
@ehuss suggested a solution that uses the environment variable __CARGO_TEST_ROOT
. The following is my attempt to use that. This code could be infinitely better, I guess. Note that this does not actually solve the problem, but some variations of them work (except for one test). I think the problem is with my logic.
diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs
index 512eed7e..9ae7ba1d 100644
--- a/src/cargo/ops/cargo_new.rs
+++ b/src/cargo/ops/cargo_new.rs
@@ -698,9 +698,23 @@ fn get_environment_variable(variables: &[&str]) -> Option<String> {
fn discover_author() -> CargoResult<(String, Option<String>)> {
let cwd = env::current_dir()?;
let git_config = if let Ok(repo) = GitRepository::discover(&cwd) {
- repo.config()
- .ok()
- .or_else(|| GitConfig::open_default().ok())
+ let repo_path = repo.path();
+ let cargo_test_root = env::var("__CARGO_TEST_ROOT");
+ match cargo_test_root {
+ Ok(ok) => {
+ if repo_path.starts_with(ok)
{
+ GitConfig::open_default().ok()
+ } else {
+ repo.config()
+ .ok()
+ .or_else(|| GitConfig::open_default().ok())
+ }
+ }
+ Err(_) => repo
+ .config()
+ .ok()
+ .or_else(|| GitConfig::open_default().ok()),
+ }
} else {
GitConfig::open_default().ok()
};
Notes
Output of cargo version
: cargo 1.38.0 (23ef9a4ef 2019-08-20)